Example: Changing a job schedule entry

This command interface to the Change Job Schedule Entry User (CHGSCDEUSR) program can change the user for a job schedule entry.

You have the following options:

  • Specify a job schedule entry name.
  • Specify a generic job schedule entry name.
  • Specify the *ALL value.

This example uses the following APIs:

  • Create User Space (QUSCRTUS)
  • List Job Schedule Entries (QWCLSCDE)
  • Retrieve User Space (QUSRTVUS)

The following is the command definition for the CHGSCDEUSR command:


    CMD        PROMPT('Change Job Schedule Entry User')
               /* CPP CHGSCDEUSR */
    PARM       KWD(JOB) TYPE(*GENERIC) LEN(10) +
                 SPCVAL((*ALL)) +
                 MIN(1) PROMPT('Job name:')
    PARM       KWD(OLDUSER) TYPE(*NAME) LEN(10) +
                 MIN(1) PROMPT('Old user name:')
    PARM       KWD(NEWUSER) TYPE(*NAME) LEN(10) +
                 MIN(1) PROMPT('New user name:')

To create the command, specify the following:

CRTCMD CMD(QGPL/CHGSCDEUSR) PGM(QGPL/CHGSCDEUSR) +
  SRCFILE(QGPL/QCMDSRC)

The following is the command-processing program that is written in CL to list the job schedule entries and change the user if necessary:

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

 /* **************************************************************** */
 /* PROGRAM:  CHGSCDEUSR                                             */
 /*                                                                  */
 /* LANGUAGE:  CL                                                    */
 /*                                                                  */
 /* DESCRIPTION:  THIS PROGRAM WILL CHANGE THE USER FOR A LIST OF    */
 /*              JOB SCHEDULE ENTRIES.                               */
 /*                                                                  */
 /* APIs USED:  QUSCRTUS, QWCLSCDE, QUSRTVUS                         */
 /*                                                                  */
 /* **************************************************************** */
             PGM        PARM(&JOBNAME &OLDUSER &NEWUSER)

 /*                                                                  */
 /* Input parameters are as follows:                                 */
 /*                                                                  */

             DCL        VAR(&JOBNAME) TYPE(*CHAR) LEN(10) /* Input +
                          job name */
             DCL        VAR(&OLDUSER) TYPE(*CHAR) LEN(10) /* Input +
                          old user name */
             DCL        VAR(&NEWUSER) TYPE(*CHAR) LEN(10) /* Input +
                          new user name */

 /*                                                                  */
 /* Local variables are as follows:                                  */
 /*                                                                  */

             DCL        VAR(&USRSPC) TYPE(*CHAR) LEN(20) +
                          VALUE('CHGSCDEUSRQTEMP     ') /* User +
                          space name for APIs */
             DCL        VAR(&CNTHDL) TYPE(*CHAR) LEN(16) +
                          VALUE('                ') /* Continuation +
                          handle */
             DCL        VAR(&NUMENTB) TYPE(*CHAR) LEN(4) /* Number +
                          of entries from list job schedule entries +
                          in binary form */
             DCL        VAR(&NUMENT) TYPE(*DEC) LEN(8 0) /* Number +
                          of entries from list job schedule entries +
                          in decimal form */
             DCL        VAR(&HDROFFB) TYPE(*CHAR) LEN(4) /* Offset +
                          to the header portion of the user space in +
                          binary form */
             DCL        VAR(&HDRLENB) TYPE(*CHAR) LEN(4) /* Length +
                          to the header portion of the user space in +
                          binary form */
             DCL        VAR(&GENHDR) TYPE(*CHAR) LEN(140) /* Generic +
                          header information from the user space */
             DCL        VAR(&HDRINFO) TYPE(*CHAR) LEN(26) /* Header +
                          information from the user space */
             DCL        VAR(&LSTSTS) TYPE(*CHAR) LEN(1) /* Status +
                          of the list in the user space */
             DCL        VAR(&OFFSETB) TYPE(*CHAR) LEN(4) /* Offset +
                          to the list portion of the user space in +
                          binary form */
             DCL        VAR(&STRPOSB) TYPE(*CHAR) LEN(4) /* Starting +
                          position in the user space  in binary form */
             DCL        VAR(&ELENB) TYPE(*CHAR) LEN(4) /* List job +
                          entry length in binary 4 form */
             DCL        VAR(&LENTRY) TYPE(*CHAR) LEN(1156) /* +
                          Retrieve area for list job schedule entry */
             DCL        VAR(&INFOSTS) TYPE(*CHAR) LEN(1) /* Retrieve +
                          area for information status */
             DCL        VAR(&JOBNAM) TYPE(*CHAR) LEN(10) /* Retrieve +
                          area for job name */
             DCL        VAR(&ENTRY#) TYPE(*CHAR) LEN(6) /* Retrieve +
                          area for entry number  */
             DCL        VAR(&USERNM) TYPE(*CHAR) LEN(10) /* Retrieve +
                          area for user name */

 /*                                                                  */
 /* Start of code                                                    */
 /*                                                                  */

 /*                                                                  */
 /* You may want to monitor for additional messages here.            */
 /*                                                                  */

 /*                                                                  */
 /* This creates the user space.  The user space will be 256 bytes   */
 /* and will be initialized to blanks.                               */
 /*                                                                  */

             CALL       PGM(QUSCRTUS) PARM(&USRSPC 'CHGSCDEUSR' +
                          X'00000100' ' ' '*ALL      ' 'CHGSCDEUSR +
                          TEMPORARY USER SPACE                    ')
             MONMSG     MSGID(CPF3C00) EXEC(GOTO CMDLBL(ERROR))

 /*                                                                  */
 /* This lists job schedule entries of the name specified.           */
 /*                                                                  */

 PARTLIST:   CALL       PGM(QWCLSCDE) PARM(&USRSPC 'SCDL0200' +
                          &JOBNAME &CNTHDL 0)

 /*                                                                  */
 /* Retrieve the generic header from the user space.                 */
 /*                                                                  */

             CALL       PGM(QUSRTVUS) PARM(&USRSPC X'00000001' +
                          X'0000008C' &GENHDR)
             MONMSG     MSGID(CPF3C00) EXEC(GOTO CMDLBL(ERROR))
 /*                                                                  */
 /* Get the information status for the list from the generic header. */
 /* If it is incomplete, go to BADLIST label and send out 'Bad list' */
 /* message.                                                         */
 /*                                                                  */

             CHGVAR     VAR(&LSTSTS) VALUE(%SST(&GENHDR 104 1))
             IF         COND(&LSTSTS = 'I') THEN(GOTO CMDLBL(BADLIST))

 /*                                                                  */
 /* Get the number of entries returned. Convert to decimal and       */
 /* if zero go to NOENTS label to send out 'No entries' message.     */
 /*                                                                  */

             CHGVAR     VAR(&NUMENTB) VALUE(%SST(&GENHDR 133 4))
             CHGVAR     VAR(&NUMENT) VALUE(%BIN(&NUMENTB))
             IF         COND(&NUMENT = 0) THEN(GOTO CMDLBL(NOENTS))

 /*                                                                  */
 /* Get the list entry length and the list entry offset.             */
 /* These values are used to set up the starting position.           */
 /*                                                                  */

             CHGVAR     VAR(&ELENB) VALUE(%SST(&GENHDR 137 4))
             CHGVAR     VAR(&OFFSETB) VALUE(%SST(&GENHDR 125 4))
             CHGVAR     VAR(%BIN(&STRPOSB)) VALUE(%BIN(&OFFSETB) + 1)

 /*                                                                  */
 /* This loops for the number of entries until no more entries are   */
 /* found and goes to the ALLDONE label.                             */
 /*                                                                  */

 STARTLOOP:  IF         COND(&NUMENT = 0) THEN(GOTO CMDLBL(PARTCHK))

 /*                                                                  */
 /* This retrieves the list entry.                                   */
 /*                                                                  */
             CALL       PGM(QUSRTVUS) PARM(&USRSPC &STRPOSB &ELENB +
                          &LENTRY)
             MONMSG     MSGID(CPF3C00) EXEC(GOTO CMDLBL(ERROR))
 /*                                                                  */
 /* This copies the information status, job name, entry number, and  */
 /* user name.                                                       */
 /*                                                                  */

             CHGVAR     VAR(&INFOSTS) VALUE(%SST(&LENTRY 1 1))
             CHGVAR     VAR(&JOBNAM)  VALUE(%SST(&LENTRY 2 10))
             CHGVAR     VAR(&ENTRY#)  VALUE(%SST(&LENTRY 12 10))
             CHGVAR     VAR(&USERNM)  VALUE(%SST(&LENTRY 547 10))

 /*                                                                  */
 /* This checks to make sure the list entry contains the user name.  */
 /* If it does, the user name is compared to the old user name       */
 /* passed in.  If either of these checks fails, this entry will     */
 /* be skipped.                                                      */
 /*                                                                  */

             IF         COND(&INFOSTS *NE ' ') THEN(GOTO +
                          CMDLBL(ENDLOOP))

             IF         COND(&USERNM *NE &OLDUSER) THEN(GOTO +
                          CMDLBL(ENDLOOP))

 /*                                                                  */
 /* This code will issue the CHGJOBSCDE command for the entry.       */
 /*                                                                  */

             CHGJOBSCDE JOB(&JOBNAM) ENTRYNBR(&ENTRY#) USER(&NEWUSER)
             MONMSG     MSGID(CPF1620) EXEC(GOTO CMDLBL(NOCHG))
             SNDPGMMSG  MSG('Entry' *BCAT &JOBNAM *BCAT &ENTRY# +
                          *BCAT 'was changed.')
             GOTO       CMDLBL(ENDLOOP)
 NOCHG:      SNDPGMMSG  MSG('Entry' *BCAT &JOBNAM *BCAT &ENTRY# +
                          *BCAT 'was NOT changed.')

 /*                                                                  */
 /* At end of loop, set new decimal position to the next entry and   */
 /* decrement the loop counter by one.                               */
 /*                                                                  */

 ENDLOOP:    CHGVAR     VAR(%BIN(&STRPOSB)) VALUE(%BIN(&STRPOSB) +
                        + %BIN(&ELENB))
             CHGVAR     VAR(&NUMENT) VALUE(&NUMENT - 1)
             GOTO       CMDLBL(STARTLOOP)

 /*                                                                  */
 /* This sends a message that no entries were found.                 */
 /*                                                                  */

 NOENTS:     SNDPGMMSG  MSG('No entries found.')
             GOTO       CMDLBL(ALLDONE)

 /*                                                                  */
 /* This sends a message that the list was incomplete.               */
 /*                                                                  */

 BADLIST:    SNDPGMMSG  MSG('Incomplete list in the user space. +
                             See joblog for details.')
             GOTO       CMDLBL(ALLDONE)

 /*                                                                  */
 /* This sends a message that an unexpected error occurred.          */
 /*                                                                  */

 ERROR:      SNDPGMMSG  MSG('Unexpected error. +
                             See joblog for details.')
             GOTO       CMDLBL(ALLDONE)

 /*                                                                  */
 /* This will check for a partial list in the user space and         */
 /* finish processing the rest of the list.                          */
 /*                                                                  */

 PARTCHK:    IF         COND(&LSTSTS = 'C') THEN(GOTO CMDLBL(ALLDONE))
 /*                                                                  */
 /* Retrieve the header information from the user space.             */
 /* Use this information to get the rest of the list.                */
 /*                                                                  */

             CHGVAR     VAR(&HDROFFB) VALUE(%SST(&GENHDR 121 4))
             CHGVAR     VAR(&HDRLENB) VALUE(%SST(&GENHDR 117 4))
             CALL       PGM(QUSRTVUS) PARM(&USRSPC &HDROFFB +
                          &HDRLENB &HDRINFO)
             MONMSG     MSGID(CPF3C00) EXEC(GOTO CMDLBL(ERROR))
             CHGVAR     VAR(&CNTHDL) VALUE(%SST(&HDRINFO 11 16))
             GOTO       CMDLBL(PARTLIST)


 /*                                                                  */
 /* All done.  Now the temporary user space is deleted.              */
 /*                                                                  */

 ALLDONE:    DLTUSRSPC  USRSPC(QTEMP/%SST(&USRSPC 1 10))
             MONMSG     MSGID(CPF0000)
             ENDPGM

To create the CL program, specify the following:

CRTCLPGM PGM(QGPL/CHGSCDEUSR) SRCFILE(QGPL/QCLSRC)

You can change the command to:

  • Specify different parameters that the Change Job Schedule Entry (CHGJOBSCDE) command can change.
  • Provide a menu to select job schedule entries to be changed.