Professional Documents
Culture Documents
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
If the value changes, no need to change each program and recompile, simply change the data area.
12
DATA AREAS
CRTDTAARA DTAARA(MYLIBXX/DAYS) + TYPE(*CHAR) + VALUE('312831303130313130313031')
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
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
15
DATA QUEUES
SEQ keyword used to define stack CRTDTAQ DTAQ(MYLIBXX/TXS) MAXLEN(80) SEQ(*LIFO) + +
Or KEYED access
+ + +
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')
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
22
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
24