compile SUBROUTINE SAP_DTM_FORMAT( charstr CONV, charstr ANS, charstr BRANCH, charstr RETURN_DATA)
*
*   SAP_DTM_FORMAT is an example of a developer's custom prompt formatting
*   routine using the square brackets call.
*
*   It should be placed in square brackets, like this:
*
*                   [SAP_DTM_FORMAT]
*
* This subroutine should be used as the first and only "Input Validation" in
* a window prompt.  Placed in "Output Format", it properly formats internal dates
* to the YYYYMMDD format used by IR's SAP system
* 5/03/11 - John C. Henry - J.C. Henry & Co - Cloned from SAP_DT_FORMAT

!
begin condition
pre:
post:
end condition

*  Subroutine declarations

$insert msg_equates

declare function msg

*  Local Equates
*  The STATUS() variable is used to indicated the error condition of the
*  pattern. They are:
EQU VALID$         TO 0    ;* Successful
EQU INVALID_MSG$   TO 1    ;* Bad Data       -   Print error message window
EQU INVALID_CONV$  TO 2    ;* Bad Conversion -          "         "
EQU INVALID_NOMSG$ TO 3    ;* Bad but do not print the error message window

EQU THREEDGRAY$    TO 192

*  Begin Conversion

RETURN_DATA = ""

IF ANS NE "" THEN
   thisDateTime = ANS
   ANS = ""
   STATUS() = VALID$
   
	IF NUM(thisDateTime) THEN
		IF CONV = 'ICONV' THEN
			IF LEN(thisDateTime) = 14 THEN
				Year	= thisDateTime[1,4]
				Month	= thisDateTime[5,2]
				Day		= thisDateTime[7,2]
				Hour	= thisDateTime[9,2]
				Minute	= thisDateTime[11,2]
				Second	= thisDateTime[13,2]
				
				Tmp = ICONV(Month:'/':Day:'/':Year:' ':Hour:':':Minute:':':Second,'DTM')
				IF Tmp NE '' THEN
					RETURN_DATA = Tmp
					RETURN
				END
			END
			ErrorMsg = thisDate:' is not a valid SAP Date Time(YYYYMMDDHHMMSS).'
			GOSUB DisplayError
			STATUS() = INVALID_NOMSG$
			
		END ELSE
			* This is the oconv
			Tmp		= OCONV(thisDateTime,'DT4/JS^S')		;* Returns YYYY/MM/DD
			CONVERT '/: APM' TO '' IN Tmp					;* Strips out delimiter
			
			RETURN_DATA = Tmp
			RETURN
		END
		
	END ELSE
		STATUS() = INVALID_NOMSG$
		RETURN
	END	;* End of check for numeric data passed in
END

RETURN

  

DisplayError:              
    msgrec            = ""
    msgrec<MCAPTION$> = "Data Validation Error"
    msgrec<MTEXT$>    = ErrorMsg
    msgrec<MBKCOLOR$> = THREEDGRAY$:@VM:THREEDGRAY$:@VM:THREEDGRAY$
    msgrec<MJUST$>    = 'L'
    result = msg( "", msgrec)
return


