Assume that you are using a data area named ORDINFO to track the status of an order file. This data area is designed so that:
You would declare these fields in your procedure as follows:
DCL VAR(&ORDSTAT) TYPE(*CHAR) LEN(1) DCL VAR(&STOCKC) TYPE(*CHAR) LEN(1) DCL VAR(&CLERK) TYPE(*CHAR) LEN(3)
To retrieve the order status into &ORDSTAT, you would enter the following:
RTVDTAARA DTAARA(ORDINFO (1 1)) RTNVAR(&ORDSTAT)
To retrieve the stock condition into &STOCK, you would enter the following:
RTVDTAARA DTAARA(ORDINFO (2 1)) RTNVAR(&STOCKC)
To retrieve the clerk's initials into &CLERK, you would enter the following:
RTVDTAARA DTAARA(ORDINFO (3 3)) RTNVAR(&CLERK)
Each use of the RTVDTAARA command requires the data area to be accessed. If you are retrieving many subfields, it is more efficient to retrieve the entire data area into a variable, then use the substring built-in function to extract the subfields.
The following example of the RTVDTAARA command places the specified contents of a 5-character data area into a 3-character variable. This example:
To do this, the following commands would be entered:
CRTDTAARA DTAARA(MYLIB/DA1) TYPE(*CHAR) LEN(5) VALUE(ABCDE) . . . DCL VAR(&CLVAR1) TYPE(*CHAR) LEN(3) RTVDTAARA DTAARA(MYLIB/DA1 (3 3)) RTNVAR(&CLVAR1)
&CLVAR1 now contains 'CDE'.
The following example of the RTVDTAARA command places the contents of a 5-digit decimal data area into a 5-digit decimal digit variable. This example:
To do this, the following commands would be entered:
CRTDTAARA DTAARA(MYLIB/DA2) TYPE(*DEC) LEN(5 2) VALUE(12.39) . . . DCL VAR(&CLVAR2) TYPE(*DEC) LEN(5 1) RTVDTAARA DTAARA(MYLIB/DA2) RTNVAR(&CLVAR2)
&CLVAR2 now contains 0012.3 (fractional truncation occurred).
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.