ibm-midrangerpglerpg

Is there way to trap QCMDEXC error in an RPG program other than using MONITOR


I have issued a CL command in a RPGLE program using the QCMDEXC api. Suppose the CL command throws an error. Is there any way of capturing the error without using the MONITOR.


Solution

  • You can use the "e" code extender

        *  Setup QCMDEXEC
        C                   eval      cmdStr = 'CALL PGM(DMACCT001) PARM(REGIONA)'
        C                   eval      cmdLen = %len( cmdStr )
        C* call to QCMDEXC
        C                   callp(e)  command(cmdStr : cmdLen)
        C                   if        %error
        C*    ZZZ    Friendly error handler goes here
        C                   endif
    
    D Command         PR                  ExtPgm('QCMDEXC')
    D  CmdStr                    32702    const options(*varsize)
    D  CmdLen                       15p 5 const