CL & Data Areas
CLPs can easily manipulate data areas.
RTVDTAARA Command
The Retrieve Data Area (RTVDTAARA) command is used in a CL program or REXX procedure to retrieve all or part of a specified data area and copy it into a variable. RTVDTAARA does not retrieve any other attributes of the data area. Existence of the data area is not required at the time the CL program is compiled.
PGM PARM(&QUERY &LIBRARY) DCL VAR(&LNGTEXT) TYPE(*CHAR) LEN(255) VALUE('An error occurred attempting + to process your request. Please contact IT to help determine the + cause of the error and repair the query program.') DCL VAR(&TEXTLEN) TYPE(*INT) DCL VAR(&TXTTITLE) TYPE(*CHAR) LEN(7) DCL VAR(&TXTMSGF) TYPE(*CHAR) LEN(20) DCL VAR(&ERRCODE) TYPE(*CHAR) LEN(16) DCL VAR(&QUERY) TYPE(*CHAR) LEN(10) DCL VAR(&LIBRARY) TYPE(*CHAR) LEN(10) DCL VAR(&DFTLIB) TYPE(*CHAR) LEN(10) MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR)) RTVDTAARA DTAARA(SC0000DA) RTNVAR(&DFTLIB) /*-------------------------------------------------------------------*/ /* default library is &DFTLIB */ /*-------------------------------------------------------------------*/ IF COND(&LIBRARY *EQ ' ') THEN(CHGVAR + VAR(&LIBRARY) VALUE(&DFTLIB)) DSPOBJD OBJ(&LIBRARY/*ALL) OBJTYPE(*QRYDFN) OUTPUT(*OUTFILE) + OUTFILE(QTEMP/SC0560WF) OVRDBF FILE(SC0560WF) TOFILE(QTEMP/SC0560WF) OVRSCOPE(*JOB) CALL PGM(SC0560RP) PARM(&QUERY &LIBRARY) DLTOVR FILE(SC0560WF) LVL(*JOB) GOTO CMDLBL(EXITPGM) ERROR: CALLSUBR SUBR(@MESSAGES) EXITPGM: RETURN /*===================================================================*/ MESSAGES: SUBR SUBR(@MESSAGES) CALL PGM(QUILNGTX) PARM(&LNGTEXT &TEXTLEN + &TXTTITLE &TXTMSGF &ERRCODE) CALLPRC PRC(SETJOBKEY) ENDSUBR ENDPGM
CHGDTAARA
In the sample above the &LIBRARY parameter may be blank. The RTVDTAARA command retrieves a library name from the data area. This is the name of a default library to use in the CL process when a library name has not been passed to the program. A data area is changed by using the Change Data Area (CHGDTAARA) command. In the sample below, a data area has been created to represent the status of a process. The data area is retrieved and if the data area indicates the process is in the intial state, (*INIT), the program submits a job, and changes the data area to indicate the process has been initiated.
/*********************************************************************/ /* PROGRAM NAME - EXP501CL */ /* */ /* FUNCTION - This program launches the file expansion phase of */ /* the PNE implementation process. */ /* */ /* PROGRAMMER - STEVE CROY 02/05/2010 iSoftwerks, Inc */ /*********************************************************************/ /*********************************************************************/ /* MODIFICATION LOG */ /* */ /* DATE PROGRAMMER DESCRIPTION */ /*********************************************************************/ PGM DCL VAR(&STATUS) TYPE(*CHAR) LEN(10) DCL VAR(&FUNCTION) TYPE(*CHAR) LEN(10) /*-------------------------------------------------------------------*/ /* Retrieve the status data area, if the status is not *INIT, then */ /* notifiy the user and exit the program. */ /*-------------------------------------------------------------------*/ RTVDTAARA DTAARA(EXP301DA) RTNVAR(&STATUS) CALL PGM(EXP301RP) PARM(&STATUS &FUNCTION) IF COND(&FUNCTION = 'EXIT') THEN(GOTO + CMDLBL(EXITPGM)) /*-------------------------------------------------------------------*/ /* If the status retrieved was *INIT, then begin the file expansion */ /* EXP320RP to read the object list and begin expanding files. */ /*-------------------------------------------------------------------*/ IF COND(&STATUS *EQ '*INIT') THEN(DO) CHGDTAARA DTAARA(EXP5301A) VALUE('*PROCESS ') SBMJOB CMD(CALL PGM(EXP320RP)) JOB(EXP_FILES) SNDPGMMSG MSGID(CPD0006) MSGF(*LIBL/QCPFMSG) + MSGDTA(' PNE file expansion job + EXP_FILES has been submitted. Status is + now ' *CAT &STATUS) TOPGMQ(*EXT) + MSGTYPE(*INFO) ENDDO EXITPGM: ENDPGM