compile SUBROUTINE SAP_DT_FORMAT( charstr CONV, charstr ANS, charstr BRANCH, charstr RETURN_DATA)
*
*   SAP_DT_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_DT_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
   thisDate = ANS
   ANS = ""
   STATUS() = VALID$
   
	IF NUM(thisDate) THEN
		IF CONV = 'ICONV' THEN
			IF LEN(thisDate) = 8 THEN
				Tmp = ICONV(thisDate[5,2]:' ':thisDate[7,2]:' ':thisDate[1,4],'D')
				IF Tmp NE '' THEN
					RETURN_DATA = Tmp
					RETURN
				END
			END
			ErrorMsg = thisDate:' is not a valid Vision Date (YYYYMMDD).'
			GOSUB DisplayError
			STATUS() = INVALID_NOMSG$
			
		END ELSE
			* This is the oconv
			Tmp		= OCONV(thisDate,'D4/JS')		;* Returns YYYY/MM/DD
			CONVERT '/' 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


