Can you be more specific on the MSGW you’re getting?
If you display the message with F1 what does it say?
Do you have the option to respond e.g. (999999) in order to continue processing?
This looks wrong:
MONMSG MSGID(CPF0864) CMPDTA(THEN) EXEC(GOTO CMDLBL(END)
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END)
CL programs don’t typically write to files.
I would create a small RPG pgoram to write to the log file and call it from the CL passing it the necessary parameters.