You are on page 1of 24

1

STORING DATA
Storing data is not limited to files There are alternative structures The alternative structures are categorized as: Linear (stacks, queues) Non-Linear (plexes) Linear structures only allow access to data in sequential order.

STACK
A single-ended, vertical linear structure Reads and writes are performed from a single entry point within the structure

Another way to look at a stack: Data is read from a stack in LIFO (last-in-first-out) order

STACK
When data is entered into a stack, each entry sits on top of the preceding entries When data is retrieved from the stack, the topmost entry is returned (last one in, is first one out)

QUEUE
A double-ended, horizontal linear structure Data is added to the left end and retrieve from the right end of the structure

Another way to look at a queue: Data is read from a queue in FIFO (first-in-first-out) order

QUEUE
When data is entered into a queue, each entry pushes the preceding entries to the right When data is retrieved from the queue, the rightmost entry is returned (first one in, is first one out)

STORING DATA
On the AS/400 data can be stored in data queues and data areas Data queues and data areas are created in main memory (default) This means reading and writing is faster You can force queues to secondary storage Data queues and data areas take up less space then files (less overhead)

STORING DATA
Data areas are objects with a type of *DTAARA CHGDTAARA DLTDTAARA RTVDTAARA CRTDTAARA DSPDTAARA WRKDTAARA

Data queues are objects with a type of *DTAQ CRTDTAQ DLTDTAQ WRKDTAQ

DATA AREAS
Hold a limited amount of data Three types of data areas: Character (*CHAR) Default size 32 characters Max size 2000 characters Numeric (*DEC) Default size 15 digits with 5 decimal places Max size 24 digits with 9 decimal places Logical (*LGL) Fixed length of 1 Can only hold the character value 1 or 0

DATA AREAS
Take up less space than a file, therefore much more efficient for holding a small amount Character data area: hold the number of days in each month Numeric data area: hold the local sales tax rate Logical data areas: indicate week, month, quarter, and/or year end processing

10

DATA AREAS
CRTDTAARA DTAARA(MYLIBXX/WE) + TYPE(*LGL) VALUE('0') DTAARA(MYLIBXX/ME) + TYPE(*LGL) VALUE('0') DTAARA(MYLIBXX//QE) + TYPE(*LGL) VALUE('0') DTAARA(MYLIBXX/YE) + TYPE(*LGL) VALUE('0')

CRTDTAARA

CRTDTAARA

CRTDTAARA

Instead of each pgm figuring out if week, month, quarter or year end processing should occur, have one pgm daily figure it out and set the data area values

11

DATA AREAS
Instead of hard coding the sales tax percentage in each program create a data area to hold the value

CRTDTAARA DTAARA(MYLIBXX/SALESTAX) + TYPE(*DEC) LEN(2 1) VALUE(6.5)

If the value changes, no need to change each program and recompile, simply change the data area.

CHGDTAARA DTAARA(MYLIBXX/SALESTAX) + VALUE(7.0)

12

DATA AREAS
CRTDTAARA DTAARA(MYLIBXX/DAYS) + TYPE(*CHAR) + VALUE('312831303130313130313031')

Character data areas can be partially changed

CHGDTAARA DTAARA(MYLIBXX/DAYS (3 2)) + VALUE(29)

When identifying the data area, specify a substring within the data area to be changed. Indicate the starting position and length of the substring

13

DATA AREAS
To display the contents of a data area: DSPDTAARA MYLIBXX/SALESTAX
Display Data Area System: Data area Library Type . . Length . Text . . Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . : : : : : : SALESTAX MYLIBXX *DEC 2 1 7.0

Press Enter to continue. F3=Exit F12=Cancel

In a program, to get data from a data area: RTVDTAARA MYLIBXX/SALESTAX &TAX


14

Data Queues
Can act as both a stack or a queue, default is a queue Can provide keyed access to data Only hold character data When creating must specify a record length

CRTDTAQ DTAQ(MYLIBXX/TXS) + MAXLEN(80)

15

DATA QUEUES
SEQ keyword used to define stack CRTDTAQ DTAQ(MYLIBXX/TXS) MAXLEN(80) SEQ(*LIFO) + +

Or KEYED access

CRTDTAQ DTAQ(MYLIBXX/TXS) MAXLEN(80) SEQ(*KEYED) KEYLEN(10)

+ + +

Must define key length. Key must be specified when reading/writing

16

DATA QUEUES
Useful for storing information from many applications for short periods of time For instance, many ways to receive order transactions: Fax Phone Internet RPG ordering application Instead of separate pgms processing each tx type, create a single order processing pgm and separate receive pgms

17

DATA QUEUES
Reading and writing not done directly Applications must call system programs and pass data These API (Application Program Interface) programs actually write and read the queue

QSNDDTAQ

data

Queue

Application Program
QRCVDTAQ data

18

WRITING TO A DTAQ
Must specify the following parameters Name of queue Library of queue Length of data being sent Program variable that contains the data being sent

DCL VAR(&DTAQ) TYPE(*CHAR) LEN(10) VALUE(..) DCL VAR(&LIB) TYPE(*CHAR) LEN(10) VALUE(..) DCL VAR(&LEN) TYPE(*DEC) LEN(5) VALUE(..) DCL VAR(&DATA) TYPE(*CHAR) LEN(80) VALUE(..) CALL PGM(QSNDDTAQ) + PARM(&DTAQ &LIB &LEN &DATA)

19

WRITING TO A DTAQ
All variables must be of the type and at least the length specified in the examples For instance declaring variables as follows:

DCL VAR(&DTAQ) TYPE(*CHAR) + LEN(5) VALUE('TXS') DCL VAR(&LIB) TYPE(*CHAR) + LEN(10) VALUE('MYLIBXX')

Object TXS MYLIB in library MYLIBXX not found.

20

WRITING TO A DTAQ
QSNDDTAQ is expecting:

T X S M Y L I B X X 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
You sent:

T X S M Y L I B X X 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
Program sees data queue name as:

T X S M Y L I B X X 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
21

RETRIEVING FROM A DTAQ


Must specify the following parameters: Name of queue Library of queue Length of data being retrieved Program variable that will hold the data being retrieved Wait instruction: Positive number: number of seconds for program to wait for data Zero: program does not wait Negative number: program waits until there is data on the queue

22

RETRIEVING FROM A DTAQ


When a record is retrieved from a queue it is removed When no more data is in the queue, the length returned is zero

DCL VAR(&DTAQ) TYPE(*CHAR) LEN(10) VALUE(..) DCL VAR(&LIB) TYPE(*CHAR) LEN(10) VALUE(..) DCL VAR(&LEN) TYPE(*DEC) LEN(5) VALUE(0) DCL VAR(&DATA) TYPE(*CHAR) LEN(80) VALUE(..) DCL VAR(&WAIT) TYPE(*DEC) LEN(5) VALUE(0) CALL QRCVDTAQ + PARM(&DTAQ &LIB &LEN &DATA &WAIT) IF (&LEN = 0) THEN(GOTO END)

23

MANAGING DATA QUEUES


Queues never get smaller Space is allocated to the queue and never released It is a good space management practice to periodically delete data queues and recreate them

24

You might also like