Friday, November 20, 2009

AS/400 Tip 2

Data Areas are chunks of memory to hold a few control values. A typical use is to keep track of the last invoice number for a system.

To create a data area, use the command
CRTDTAARA (Create Data Area).
For example, to create a 100 character data area named LASTINV#:
CRTDTAARA DTAARA(MYLIB/LASTINV#) TYPE(*CHAR) LEN(100)
Now, load the first 10 positions with the value "AA12345678" with the CHGDTAARA (Change Data Area) command
CHGDTAARA DTAARA(QTEMP/LASTINV# (1 10)) VALUE('AA12345678')
Look at the value of the data area with DSPDTAARA (Display Data Area):
DSPDTAARA MYLIB/LASTINV# A CL program can retrieve the value with RTVDTAARA.
An RPG program uses the "IN" operation to retrieve the value and the "OUT" operation to change it. There is a special Data Area known as the LDA (Local Data Area). It is 1024 characters and is associated with a job. So, any display session has an LDA associated with it. Not only that, when a job is submitted to run in batch, the LDA gets sent with the job so the batch job can read the LDA of the display session that submitted it.

View and change your LDA by using *LDA instead of a data area name:
DSPDTAARA *LDA CHGDTAARA DTAARA(*LDA (1 10)) VALUE('AA12345678')
Using the LDA is considered by many to be an obsolete style. Older programs use the LDA to store and pass parameters.

Source: http://www.texas400.com/b400tip1.html

No comments:

Computers Add to Technorati Favorites Programming Blogs - BlogCatalog Blog Directory