Hi can someone tell me how to validate date in a CL program. If a DATE is provided as an input to the CL program , the CL program should validate the provided DATE.
there is a CL command named CVTDAT
. Use it to convert a date from one format to another. To validate the date, use the MONMSG
command to monitor for any conversion error.
PGM PARM(&CHDATE)
dcl &chdate *char 10
dcl &todate *char 10
dcl &errmsg *char 256
CVTDAT DATE(&CHDATE) TOVAR(&TODATE) FROMFMT(*YYMD) +
TOFMT(*ISO) TOSEP(*NONE)
monmsg cpf0000 exec(do)
RCVMSG MSGTYPE(*EXCP) MSG(&errMSG)
enddo
IF COND(&ERRMSG *NE ' ') THEN(SNDPGMMSG +
MSG('date convert error.' *BCAT &ERRMSG))
else do
SNDPGMMSG MSG('resulting date:' *BCAT &TODATE)
enddo
endpgm