Using the job log to diagnose API errors

When your program encounters an API error, use messages in the job log to determine the cause.

Sometimes an API might issue a message stating that the API failed, and the message might direct you to see the previously listed messages in the job log. If you need to determine the cause of an error message, use the Receive Message (RCVMSG) command or the receive message APIs to receive the messages that explain the reason for the error.

In some cases, you can write an application program to use the diagnostic message to identify and correct the parameter values that caused the error.

The following CL program receives error messages from the job log.
Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

/*                                                                   */
/*********************************************************************/
/*                                                                   */
/*    PROGRAM: CLRCVMSG                                              */
/*                                                                   */
/*    LANGUAGE: CL                                                   */
/*                                                                   */
/*    DESCRIPTION: THIS PROGRAM DEMONSTRATES HOW TO RECEIVE          */
/*                 DIAGNOSTIC MESSAGES FROM THE JOB LOG              */
/*                                                                   */
/*    APIs USED: QUSCRTUS                                            */
/*                                                                   */
/*********************************************************************/
/*                                                                   */
CLRCVMSG:    PGM

             DCL        VAR(&MSGDATA) TYPE(*CHAR) LEN(80)
             DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)
             DCL        VAR(&MSGLEN) TYPE(*DEC) LEN(5 0)

             MONMSG     MSGID(CPF3C01) EXEC(GOTO CMDLBL(GETDIAGS))

             CALL       PGM(QUSCRTUS) PARM('!BADNAME  !BADLIB   ' +
                          '!BADEXATTR' -1 '@' '*BADAUTH  ' 'Text +
                          Description')

             /* IF WE MAKE IT HERE, THE SPACE WAS CREATED OK    */

             GOTO       CMDLBL(ALLDONE)

 /* IF THIS PART OF THE PROGRAM RECEIVES CONTROL, A CPF3C01     */
 /* WAS RECEIVED INDICATING THAT THE SPACE WAS NOT CREATED.     */
 /* THERE WILL BE ONE OR MORE DIAGNOSTICS THAT WE WILL RECEIVE  */
 /* TO DETERMINE WHAT WENT WRONG. FOR THIS EXAMPLE WE WILL      */
 /* JUST USE SNDPGMMSG TO SEND THE ID'S OF THE MESSAGES         */
 /* RECEIVED.                                                   */

 GETDIAGS:   RCVMSG     PGMQ(*SAME) MSGQ(*PGMQ) MSGTYPE(*DIAG) +
                          WAIT(3) RMV(*NO) MSGDTA(&MSGDATA) +
                          MSGDTALEN(&MSGLEN) MSGID(&MSGID)
             IF         COND(&MSGID = '       ') THEN(GOTO +
                          CMDLBL(ALLDONE))
             ELSE       CMD(DO)
             SNDPGMMSG  MSG(&MSGID)
             GOTO       CMDLBL(GETDIAGS)
             ENDDO
 ALLDONE:    ENDPGM