You can retrieve the job attributes and place their values in a CL variable to control your applications.
Job attributes are retrieved using the Retrieve Job Attribute (RTVJOBA) command. You can retrieve all job attributes, or any combination of them, with the RTVJOBA command.
In the following CL procedure, a RTVJOBA command retrieves the name of the user who called the procedure.
PGM /* ORD410C Order entry program */ DCL &CLKNAM TYPE(*CHAR) LEN(10) DCL &NXTPGM TYPE(*CHAR) LEN(3) . . . RTVJOBA USER(&CLKNAM) BEGIN: CALL ORD410S2 PARM(&NXTPGM &CLKNAM) /* Customer prompt */ IF (&NXTPGM *EQ 'END') THEN(RETURN) . . .
The variable &CLKNAM, in which the user name is to be passed, is first declared using a DCL command. The RTVJOBA command follows the declare commands. When the program ORD410S2 is called, two variables, &NXTPGM and &CLKNAM, are passed to it. &NXTPGM is passed as blanks but could be changed by ORD410S2.
Assume in the following CL procedure, an interactive job submits a program including the CL procedure to batch. A Retrieve Job Attributes (RTVJOBA) command retrieves the name of the message queue to which the job's completion message is sent, and uses that message queue to communicate with the user who submitted the job.
PGM DCL &MSGQ *CHAR 10 DCL &MSGQLIB *CHAR 10 DCL &MSGKEY *CHAR 4 DCL &REPLY *CHAR 1 DCL &ACCTNO *CHAR 6 . . . RTVJOBA SBMMSGQ(&MSGQ) SBMMSGQLIB(&MSGQLIB) IF (&MSGQ *EQ '*NONE') THEN(DO) CHGVAR &MSGQ 'QSYSOPR' CHGVAR &MSGQLIB 'QSYS' ENDDO . . . IF (. . . ) THEN(DO) SNDMSG:SNDPGMMSG MSG('Account number ' *CAT &ACCTNO *CAT 'is + not valid. Do you want to cancel the update + (Y or N)?') TOMSGQ(&MSGQLIB/&MSGQ) MSGTYPE(*INQ) + KEYVAR(&MSGKEY) RCVMSG MSGQ(*PGMQ) MSGTYPE(*RPY) MSGKEY(&MSGKEY) + MSG(&REPLY) WAIT(*MAX) IF (&REPLY *EQ 'Y') THEN(RETURN) ELSE IF (&REPLY *NE 'N') THEN(GOTO SNDMSG) ENDDO . . .
Two variables, &MSGQ and &MSGQLIB, are declared to receive the name and library of the message queue to be used. The RTVJOBA command is used to retrieve the message queue name and library name. Because it is possible that a message queue is not specified for the job, the message queue name is compared to the value *NONE. If the comparison is equal, no message queue is specified, and the variables are changed so that message queue QSYSOPR in library QSYS is used. Later in the procedure, when an error condition is detected, an inquiry message is sent to the specified message queue and the reply is received and processed. Some of the other possible uses of the RTVJOBA command are:
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.