As we know, CL program is nothing but a bunch of commands which are executed by the system one after other. Hence, All commands which we have used previously (On the previous sections) for a data area like CRTDTAARA, DSPDTAARA, CHGDTAARA, DLTDTAARA are valid for the CL program also. However, the commands CRTDTAARA (Create a data area) and DLTDTAARA(Delete a data area) are seldom used in a CL Program as Data area's are mostly permanently objects. Yet, these two commands could be used in a CL program when we have to create a temporary data area.
The command DSPDTAARA is not used in a CL program (Though one is free to use it, if required (to see the changed values of data area while debugging)). The command CHGDTAARA is extensively used in a CL Program to change/update the value of an AS400 data area.
Retrieve value of a data area in CL program:
As we know the command DSPDTAARA just displays (Or prints a spool) the current value of a data area. It does not return anything. If we need to retrieve the value of a data area as a variable, we need to execute the command RTVDTAARA. However, The RTVDTAARA command is valid only in a CL program. It can be run independantly from the command line.
The RTVDTAARA command takes the following arguments.
A typical syntax of the command RTVDTAARA is given here for your reference. Most of the times the library will not be required so it's omitted for simplicity. However, you can add it if required.
RTVDTAARA DTAARA(NAME (5 10)) RTNVAR(&VAR1)
CRTDTAARA DTAARA(EMP#) TYPE(*DEC) LEN(10 0) TEXT(1)
The source code of the Data Area Example is given below.
PGM
/* Declare Variable */
DCL VAR(&EMP#) TYPE(*DEC) LEN(10 0) VALUE(0)
/* Retrive data area into CL variable */
RTVDTAARA DTAARA(EMP# *ALL) RTNVAR(&EMP#)
/* Increment the variable by one */
CHGVAR VAR(&EMP#) VALUE(&EMP# + 1)
/* Update the data area with next employee number */
CHGDTAARA DTAARA(EMP#) VALUE(&EMP#)
ENDPGM
To test this program see the value of the data area before and after running it by running the command DSPDTAARA from command line. You will see that the program updates the data area's value after incrementing it by one.
Note:- To retrieve specific portion of the data area just use the command
RTVDTAARA DTAARA(EMP# (1 5)) RTNVAR(&EMP#)
That's how data area is handled in a CL Program. Do write your comments below.
Next we will learn how to handle a data area in an RPG program.
Recent comments
5 days 1 hour ago
5 days 2 hours ago
5 days 2 hours ago
5 days 4 hours ago
5 days 15 hours ago
5 days 17 hours ago
5 days 18 hours ago
5 days 19 hours ago
6 days 8 hours ago
6 days 18 hours ago