Example: Changing an active job
This command interface to the Change Active Jobs (CHGACTJOB) program can reduce the run priority of active jobs with the same name.
You can also reduce the run priority of jobs using a specified user name. You have the following options:
- Specify a job name or the *ALL value.
- Specify the user name as the *ALL value.
- Use the default run priority of 99.
The CHGACTJOB command ensures that one of the following is true:
- Not all jobs were specified.
- The *ALL value was not specified for the JOB parameter.
- The *ALL value was not specified for the USER parameter.
This example uses the following APIs:
- Create User Space (QUSCRTUS)
- List Job (QUSLJOB)
- Retrieve User Space (QUSRTVUS)
- Retrieve Job Information (QUSRJOBI)
The following is the message description needed for the Change Active Jobs (CHGACTJOB) command:
ADDMSGD MSGID(USR3C01) MSGF(QCPFMSG) +
MSG('JOB(*ALL) is not valid with USER(*ALL)') SEV(30)
The following is the command definition for the CHGACTJOB command:
CMD PROMPT('Change Active Jobs')
/* CPP CHGACTJOB */
PARM KWD(JOB) TYPE(*NAME) LEN(10) +
SPCVAL((*ALL)) MIN(1) +
PROMPT('Job name:')
PARM KWD(USER) TYPE(*NAME) LEN(10) DFT(*ALL) +
SPCVAL((*ALL) (*CURRENT)) PROMPT('User +
name:')
PARM KWD(RUNPTY) TYPE(*DEC) LEN(5 0) DFT(99) +
RANGE(00 99) PROMPT('Run priority:')
DEP CTL(&USER *EQ *ALL) PARM((&JOB *NE *ALL)) +
NBRTRUE(*EQ 1) MSGID(USR3C01)
To create the command, specify the following:
CRTCMD CMD(QGPL/CHGACTJOB) PGM(QGPL/CHGACTJOB) +
SRCFILE(QGPL/CMDSRC)
The following is the command-processing program that is written in CL to list the active jobs and reduce the run priority if necessary:
/* ***************************************************************** */
/* PROGRAM: CHGACTJOB */
/* */
/* LANGUAGE: CL */
/* */
/* DESCRIPTION: THIS PROGRAM WILL REDUCE THE RUN PRIORITY OF ACTIVE */
/* JOBS WITH THE SAME NAME. */
/* */
/* APIs USED: QUSCRTUS, QUSLJOB, QUSRTVUS, QUSRJOBI */
/* */
/* ***************************************************************** */
PGM PARM(&JOB &USER &RUNPTY)
/* */
/* Input parameters */
/* */
DCL VAR(&JOB) TYPE(*CHAR) LEN(10) +
/* Input job name */
DCL VAR(&USER) TYPE(*CHAR) LEN(10) +
/* Input user name */
DCL VAR(&RUNPTY) TYPE(*DEC) LEN(5 0) +
/* Input run priority */
/* */
/* Local variables */
/* */
DCL VAR(&RJOB) TYPE(*CHAR) LEN(10) +
/* Retrieve job name */
DCL VAR(&RUSER) TYPE(*CHAR) LEN(10) +
/* Retrieve user name */
DCL VAR(&RNBR) TYPE(*CHAR) LEN(6) +
/* Retrieve job number */
DCL VAR(&RUNPTYC) TYPE(*CHAR) LEN(5) +
/* Input run priority in character form */
DCL VAR(&RUNPTY8) TYPE(*DEC) LEN(8 0) +
/* Retrieve run priority after convert from +
binary 4 */
DCL VAR(&RUNPTY5) TYPE(*DEC) LEN(5 0) +
/* Retrieve run priority in decimal 5,0 +
form */
DCL VAR(&RUNPTY5C) TYPE(*CHAR) LEN(5) +
/* Retrieve run priority in character form */
DCL VAR(&RUNPTY4) TYPE(*CHAR) LEN(4) +
/* Retrieve run priority in binary 4 form */
DCL VAR(&NUMBER) TYPE(*CHAR) LEN(6) +
/* Current job number */
DCL VAR(&USRSPC) TYPE(*CHAR) LEN(20) +
VALUE('CHGA QTEMP ') +
/* User space name for APIs */
DCL VAR(&EUSRSPC) TYPE(*CHAR) LEN(10) +
/* User space name for commands */
DCL VAR(&JOBNAME) TYPE(*CHAR) LEN(26) +
VALUE(' *ALL ') +
/* Full job name for list job */
DCL VAR(&BIN4) TYPE(*CHAR) LEN(4) +
/* Number of jobs for list job and +
User space offset in binary 4 form */
DCL VAR(&LOOP) TYPE(*DEC) LEN(8 0) +
/* Number of jobs from list job */
DCL VAR(&DEC8) TYPE(*DEC) LEN(8 0) +
/* User space offset in decimal 8,0 form */
DCL VAR(&ELEN) TYPE(*DEC) LEN(8 0) +
/* List job entry length in decimal 8,0 +
form */
DCL VAR(&ELENB) TYPE(*CHAR) LEN(4) +
/* List job entry length in binary 4 +
form */
DCL VAR(&LJOBE) TYPE(*CHAR) LEN(52) +
/* Retrieve area for list job entry */
DCL VAR(&INTJOB) TYPE(*CHAR) LEN(16) +
/* Retrieve area for internal job id */
DCL VAR(&JOBI) TYPE(*CHAR) LEN(104) +
/* Retrieve area for job information */
DCL VAR(&JOBTYPE) TYPE(*CHAR) LEN(1) +
/* Job type */
/* */
/* Start of executable code */
/* */
/* */
/* Retrieve job number to use for local user space name */
/* */
RTVJOBA NBR(&NUMBER)
CHGVAR VAR(%SST(&USRSPC 5 6)) VALUE(&NUMBER)
CHGVAR VAR(&EUSRSPC) VALUE(%SST(&USRSPC 1 10))
/* */
/* Delete user space if it already exists */
/* */
DLTUSRSPC USRSPC(QTEMP/&EUSRSPC)
MONMSG CPF0000
/* */
/* Create user space */
/* */
CALL QUSCRTUS (&USRSPC 'CHGACTJOB ' X'00000100' ' ' +
'*ALL ' +
'CHGACTJOB TEMPORARY USER SPACE-
')
/* */
/* Set up job name for list jobs */
/* */
CHGVAR VAR(%SST(&JOBNAME 1 10)) VALUE(&JOB)
CHGVAR VAR(%SST(&JOBNAME 11 10)) VALUE(&USER)
/* */
/* List active jobs with job name specified */
/* */
CALL QUSLJOB (&USRSPC 'JOBL0100' &JOBNAME +
'*ACTIVE ')
/* */
/* Retrieve number of entries returned. Convert to decimal and */
/* if zero go to NOJOBS label to send out 'No jobs' message. */
/* */
CALL QUSRTVUS (&USRSPC X'00000085' X'00000004' +
&BIN4)
CHGVAR &LOOP %BINARY(&BIN4)
IF COND(&LOOP = 0) THEN(GOTO CMDLBL(NOJOBS))
/* */
/* Retrieve list entry length, convert to decimal. */
/* Retrieve list entry offset, convert to decimal, and add one */
/* to set the position. */
/* */
CALL QUSRTVUS (&USRSPC X'00000089' X'00000004' +
&ELENB)
CHGVAR &ELEN %BINARY(&ELENB)
CALL QUSRTVUS (&USRSPC X'0000007D' X'00000004' +
&BIN4)
CHGVAR &DEC8 %BINARY(&BIN4)
CHGVAR VAR(&DEC8) VALUE(&DEC8 + 1)
/* */
/* Loop for the number of jobs until no more jobs then go to */
/* ALLDONE label */
/* */
STARTLOOP: IF (&LOOP = 0) THEN(GOTO ALLDONE)
/* */
/* Convert decimal position to binary 4 and retrieve list job entry */
/* */
CHGVAR %BINARY(&BIN4) &DEC8
CALL QUSRTVUS (&USRSPC &BIN4 &ELENB +
&LJOBE)
/* */
/* Copy internal job identifier and retrieve job information for */
/* basic performance information. */
/* */
CHGVAR VAR(&INTJOB) VALUE(%SST(&LJOBE 27 16))
CALL QUSRJOBI (&JOBI X'00000068' 'JOBI0100' +
'*INT ' +
&INTJOB)
/* */
/* Copy job type and if subsystem monitor, spool reader, system job, */
/* spool writer, or SCPF system job then loop to next job */
/* */
CHGVAR VAR(&JOBTYPE) VALUE(%SST(&JOBI 61 1))
IF COND((&JOBTYPE = 'M') *OR (&JOBTYPE = 'R') +
*OR (&JOBTYPE = 'S') *OR (&JOBTYPE = 'W') +
*OR (&JOBTYPE = 'X')) +
THEN(GOTO CMDLBL(ENDLOOP))
/* */
/* Copy run priority, convert to decimal, convert to decimal 5,0, */
/* and if request run priority is less than or equal to the current */
/* run priority then loop to next job. */
/* */
CHGVAR VAR(&RUNPTY4) VALUE(%SST(&JOBI 65 4))
CHGVAR &RUNPTY8 %BINARY(&RUNPTY4)
CHGVAR VAR(&RUNPTY5) VALUE(&RUNPTY8)
IF COND(&RUNPTY5 *GE &RUNPTY) THEN(GOTO +
CMDLBL(ENDLOOP))
/* */
/* Retrieve job name, convert to run priority to character, change */
/* the job run priority and seen message stating the run priority */
/* was changed. */
/* */
CHGVAR VAR(&RJOB) VALUE(%SST(&JOBI 9 10))
CHGVAR VAR(&RUSER) VALUE(%SST(&JOBI 19 10))
CHGVAR VAR(&RNBR) VALUE(%SST(&JOBI 29 6))
CHGVAR VAR(&RUNPTYC) VALUE(&RUNPTY)
CHGVAR VAR(&RUNPTY5C) VALUE(&RUNPTY5)
CHGJOB JOB(&RNBR/&RUSER/&RJOB) RUNPTY(&RUNPTYC)
MONMSG MSGID(CPF1343) EXEC(GOTO CMDLBL(ENDLOOP))
SNDPGMMSG MSG('Job' *BCAT &RNBR *TCAT '/' *TCAT +
&RUSER *TCAT '/' *TCAT &RJOB *BCAT 'run +
priority was change from' *BCAT &RUNPTY5C +
*BCAT 'to' *BCAT &RUNPTYC *TCAT '.')
/* */
/* At end of loop set new decimal position to next entry and */
/* decrement loop counter by one. */
/* */
ENDLOOP: CHGVAR VAR(&DEC8) VALUE(&DEC8 + &ELEN)
CHGVAR VAR(&LOOP) VALUE(&LOOP - 1)
GOTO CMDLBL(STARTLOOP)
/* */
/* Send message that no jobs were found. */
/* */
NOJOBS: SNDPGMMSG MSG('No jobs found.')
/* */
/* All done. Now delete temporary user space that we created. */
/* */
ALLDONE: DLTUSRSPC USRSPC(QTEMP/&EUSRSPC)
MONMSG CPF0000
ENDPGM
The program can be changed to change the run priority by removing the IF statement to compare the current and requested run priority.
To create the CL program, specify the following:
CRTCLPGM PGM(QGPL/CHGACTJOB) SRCFILE(QGPL/QCLSRC)
You can change the command to:
- Specify a different printer device.
- Specify a different output queue.
- Specify different job attributes that the Change Job (CHGJOB) command can change.
- List only jobs on an output queue and remove the spooled files.
- Provide a menu to select jobs to be changed.