Compile Time Array in RPG AS400

Compile Time Array in RPG AS400
Compile Time Array in RPG AS400,Compile time array,array,types of array,DIM() keyword,CTDATA() keyword,PERRCD() keyword,array related op-code,introduction,about,what is,what,create,make
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

RPG Code in Fixed format for Compile Time Array in AS400
      *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                                             
RPG Code in /Free format for Compile Time Array in AS400
      *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                                                                                            
RPG Code in fully Free format for Compile Time Array in AS400
**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 AS400

Related Post

Post a Comment

© AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain