Pre-Run Time Array in RPG AS400 |
Introduction to PreRun-Time Array
It is loaded from the array file when the program starts executing.
We can use a Pre-run time array when we want data to be loaded in an array at the program start before any I/O, calculation, or O specs operations and we want to keep array data dynamic.
Steps to code PreRun-Time Array
Create a Flat file
Let's create two flat files namely FLATFILE1 and FLATFILE2 with record length 112. Use the CRTPF command as below to create the FLATFILE1 and FLATFILE2 objects in your current library.
CRTPF FILE(FLATFILE1) RCDLEN(112)
CRTPF FILE(FLATFILE2) RCDLEN(112)
Inserted Array element records in Flat file
You can insert data using SQL INSERT from STSRQL and UPDDTA command as below in FLATFILE1 and FLATFILE2.
FLATFILE1 AJAY AMIT AMAR ABHAY ******** End of data ********
FLATFILE2 AJAY SINGH AMIT KUMAR AMAR PRATAP ABHAY SHARMA ANKUR SINGH ******** End of data ********
Coding a PrRun-Time Array in RPGLE
Let's write a program for PreRun-Time Array in RPGLE fixed, free, and fully free format.
*Header Specification HDebug(*Yes) HOption(*NoDebugio) FFLATFILE1 IT F 112 DISK FFLATFILE2 IT F 112 DISK * program variables D PreRunTimeArray1... D S 10A DIM(5) FROMFILE(FLATFILE1) PERRCD(1) D PreRunTimeArray2... D S 10A DIM(10) FROMFILE(FLATFILE2) PERRCD(2) * D Index S 10i 0 D AddArrayData1 S 10A D AddArrayData2 S 10A * C EVAL Index = 1 C DOW Index <=5 C EVAL ArrayData1 = C %Trim(PreRunTimeArray1(Index)) C ArrayData1 DSPLY C EVAL Index = Index + 1 C ENDDO C EVAL Index = 1 C DOW Index <=10 C EVAL ArrayData2 = C %Trim(PreRunTimeArray2(Index)) C ArrayData2 DSPLY C EVAL Index = Index + 1 C ENDDO C EVAL *INLR = *ON
*Header Specification HDebug(*Yes) HOption(*NoDebugio) FFLATFILE1 IT F 112 DISK FFLATFILE2 IT F 112 DISK * program variables D PreRunTimeArray1... D S 10A DIM(5) FROMFILE(FLATFILE1) PERRCD(1) D PreRunTimeArray2... D S 10A DIM(10) FROMFILE(FLATFILE2) PERRCD(2) * D Index S 10i 0 D AddArrayData1 S 10A D AddArrayData2 S 10A /Free // Begin program Index = 1; Dow (Index <=5); AddArrayData1= %Trim(PreRunTimeArray1(Index)) ; DSPLY AddArrayData1; Index = Index + 1; EndDo; Index = 1; Dow (Index <=10); AddArrayData2= %Trim(PreRunTimeArray2(Index)) ; DSPLY AddArrayData2; Index = Index + 1; EndDo; //Set Last Record Indicator ON *Inlr = *ON; /End-Free
Please note that PERRCD concept can be referred from here.In PreRun-Time Array case the record referred from flat file.
Create the RPGLE object of SQLRPGLE source member
Use CRTSQLRPGI command or option 14 on the RPG source member using WRKMBRPDM.
Create SQL ILE RPG Object (CRTSQLRPGI) Type choices, press Enter. Object . . . . . . . . . . . . . OBJ > ARRAYPRE Library . . . . . . . . . . . > IBMICLASS1 Source file . . . . . . . . . . SRCFILE > QRPGLESRC Library . . . . . . . . . . . > IBMICLASS2 Source member . . . . . . . . . SRCMBR > ARRAYPRE Source stream file . . . . . . . SRCSTMF Commitment control . . . . . . . COMMIT *CHG Relational database . . . . . . RDB *LOCAL Compile type . . . . . . . . . . OBJTYPE > *PGM Listing output . . . . . . . . . OUTPUT *NONE Text 'description' . . . . . . . TEXT *SRCMBRTXT
An object is created as follows
Work with Objects Type options, press Enter. 2=Edit authority 3=Copy 4=Delete 5=Display authority 7=Rename 8=Display description 13=Change description Opt Object Type Library Attribute Text ARRAYPRE *PGM IBMICLASS1 RPGLE Pre Run Time Array
Program Output
DSPLY AJAY DSPLY AMIT DSPLY AMAR DSPLY ABHAY DSPLY AJAY DSPLY SINGH DSPLY AMIT DSPLY KUMAR DSPLY AMAR DSPLY PRATAP DSPLY ABHAY DSPLY SHARMA DSPLY ANKUR
Related Post
- Array and Types of Array in RPG AS400
- Compile Time Array in RPG AS400
- Using PERRCD keyword in compile Time Array in RPG AS400
- 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