Compile-Time Array in RPG AS400 |
Introduction to Compile-Time Arrays
Compile-Time Array is loaded when the RPG program gets created. The data is static in a compile-time array and cannot be changed during program execution.
Keywords such as DIM, CTDATA, PERRCD are used to declare the compile-time array in the RPG program.
We declare the array elements after the last source statement of the RPG program.
DIM keyword
We input the number of elements in the DIM keyword as a parameter for the size of the Array.
CTDATA keyword
This keyword tells that it is a compile-time array in the RPG program.
PERRCD keyword
This keyword is an optional keyword and represents the number of input record entries in one array record in the RPG program. If the keyword is not defined the value defaults to 1 for the PERRCD keyword.
If the PERRCD parameter is 2 and number of rows are 5 then the DIM would get doubled DIM(10) PERRCD(2)
Coding Compile-Time Array in Fixed, Free, and Fully Free format in RPG
*Header Specification HDebug(*Yes) HOption(*NoDebugio) * program variables D CompileTimeArray1... D S 10A DIM(5) CTDATA D CompileTimeArray2... D S 20A DIM(5) CTDATA * D Index S 10i 0 D AddArrayData S 30A * C EVAL Index = 1 C DOW Index <=5 C EVAL AddArrayData = C %Trim(CompileTimeArray1(Index)) + '-' + C %Trim(CompileTimeArray2(Index)) C AddArrayData DSPLY C EVAL Index = Index + 1 C ENDDO C EVAL *INLR = *ON ** CTDATA CompileTimeArray1 AMIT ABHAY AJAY AMAR ANUJ ** CTDATA CompileTimeArray2 SINGH KAPOOR VERMA LAL SINGHANIA
*Header Specification HDebug(*Yes) HOption(*NoDebugio) * program variables D CompileTimeArray1... D S 10A DIM(5) CTDATA D CompileTimeArray2... D S 20A DIM(5) CTDATA * D Index S 10i 0 D AddArrayData S 30A * /Free // Begin program Index = 1; Dow (Index <=5); AddArrayData = %Trim(CompileTimeArray1(Index)) + '-' + %Trim(CompileTimeArray2(Index)) ; DSPLY AddArrayData; Index = Index + 1; EndDo; //Set Last Record Indicator ON *Inlr = *ON; /End-Free ** CTDATA CompileTimeArray1 AMIT ABHAY AJAY AMAR ANUJ ** CTDATA CompileTimeArray2 SINGH KAPOOR VERMA LAL SINGHANIA
**FREE ctl-opt debug(*yes); ctl-opt Option(*NoDebugio); dcl-s CompileTimeArray1 char(10) DIM(5) CTDATA; dcl-s CompileTimeArray2 char(20) DIM(5) CTDATA; dcl-s Index int(10); dcl-s AddArrayData char(30); // Begin program Index = 1; Dow (Index <=5); AddArrayData = %Trim(CompileTimeArray1(Index)) + '-' + %Trim(CompileTimeArray2(Index)) ; DSPLY AddArrayData; Index = Index + 1; EndDo; //Set Last Record Indicator ON *Inlr = *ON; ** CTDATA CompileTimeArray1 AMIT ABHAY AJAY AMAR ANUJ ** CTDATA CompileTimeArray2 SINGH KAPOOR VERMA LAL SINGHANIA
Program Output:
DSPLY AMIT-SINGH DSPLY ABHAY-KAPOOR DSPLY AJAY-VERMA DSPLY AMAR-LAL DSPLY ANUJ-SINGHANIA
Using PERRCD keyword in compile Time Array in RPG
Click on the link to see the PERRCD keyword usage with a code example in RPG.
Using PERRCD keyword in compile Time Array in RPG AS400Related Post
- Array and Types of Array in RPG AS400
- Run Time Array in RPG AS400
- Pre-Run Time Array in RPG AS400
- Lookup an Array element in RPGLE AS400
- Sorting Array (SORTA) opcode for ARRAY in RPG AS400
- XFOOT opcode for ARRAY in RPG AS400
- Using keywords QUALIFIED, LIKEDS, and DIM with data structures
- Array Data Structures in RPG AS400