
Arrays & Tables
-
Arrays and tables are systematic program-internal arrangement of data fields with the same field length and data type
-
Both can be searched sequentially for identifiable elements.
Difference between Tables & Arrays
-
Unlike array elements, table elements cannot be referred to by their positions within the table
-
Table name does not refer to the entire set of table element
Arrays
Arrays are of 3 types.
-
Run-time (is loaded when the program is running)
-
Compile time (is loaded when the program is created)
-
Prerun time (is loaded from an array file when program begins running before any input,calculation, or output operation is processed)
Array Name and Index
-
Entire array is referred to by name alone
-
Individual elements are referred to by array name followed by a comma followed by an index
-
The index indicates the element position
-
The array name with comma and index can be upto 6 characters long
-
Array name in columns 27-32
-
Number of array entries (right justified) in columns 36-39
-
Entry length (right justified) in columns 40-42
-
Decimal position for numeric elements in position 44
-
Blanks in columns 33-35 for run time arrays
Run Time Arrays
Coding a Run Time array
Only Essential array specifications are required
Example
E ARC 8 12 4
Defines a Run time array of name ARC
Loading Run Time arrays
Assign initial values through Input or Calculation specifications
Using I specification, you can fill an array with the data from a file
d LoArry s 1a dim(26)
c movea Lo LoArry
pos = %scan(LoArry(x):pTxtStr:1);
Compile Time Array
Coding a Compile Time Array
-
Number of array entries in an array input record specified in position 33-35 of E specs
-
Rest all specifications are the same as in Essential Array specifications
-
Loading a Compile Time Array
-
Enter array input data into records in the program source member, following the source records for this program and following the alternative collating sequence records and the file transaction records if any
-
The data gets loaded when the program is compiled
Prerun - time Array
Coding a Prerun-Time Array
-
Specify the name of the file with array input data in positions 11-18 ,in addition to Essential array specification
-
Name of file to which array is written could be given from 19-26 column
-
For a combined file both the names should match
-
Position 43 specifies array data type
P - Packed
B - Binary
L - indicates sign on the left of a data element
R - indicates sign on the right of a data element
File with array input data should have T in column 16 on F spec
-
Loading a Prerun-time Array
-
Enter array input data into a file
-
File should be sequential & program described
-
Array gets loaded when the program is called
-
File values can be changed to alter array's initial values on the next call to the program
-
File is read in arrival sequence
Example of Compile time array and pre run time array
* File declaration
FPRERUNARR IT F 10 DISK
* Array Declaration
**********************************************************************
D Ary_Msg S 100 CTDATA PERRCD(1)
D DIM(20)
D Ary_Msg1 S 10 PERRCD(1) FROMFILE(PRERUNARR) DIM
D Var1 s 500
**********************************************************************
/Free
Var1= Ary_Msg(1);
Var1= Ary_Msg(2);
Var1= Ary_Msg(3);
Dsply Ary_Msg1(1);
Dsply Ary_Msg1(2);
Dsply Ary_Msg1(3);
Dsply Ary_Msg1(4);
Dsply Ary_Msg1(5);
*INLR = *On;
/End-Free
**********************************
**CTDATA Ary_Msg
Option is Invalid. Field is Not blank.
Field is Blank. perrcd2 test
Record Allready Exist.
Record Added to dataBase.
Record Changed in dataBase.
Record Deleted from dataBase.
Tables
-
The name must begin with letters TAB
-
Can be loaded only at compilation & prerun time
-
LOKUP operation can be used to search tables
-
Factor 1 & 2 and at least one resulting indicator must be specified
-
The searched table element when found, is placed in an area in the system & is replaced by the newly found member every time a search is successful
-
Factor 1 contains search argument
-
Factor 2 contains the name of table to be searched
-
Result field contains table name from which data is also made available for use
-
Resulting indicators must be used
LOKUP with Two Tables
-
When two tables are used in a search, only one is actually searched
-
When the search condition is satisfied, the corresponding elements from both tables are placed in their respective areas in the system & made available for use
-
Both tables must have the same number of entries
-
Whenever a table name is used in an operation after other than LOKUP, the table name actually refers to the data retrieved by last successful search.
Example
C*
C*
C EMPNUM LOKUPTABEMP TABPAY ----09
C*
C 09 HRSWKD MULT TABPAY AMT
C 09 MOVE TABEMP EMPNO