Now, Get RPG Codes in all three formats only on this website on every RPGLE related programming article.

Fixed, /Free and Fully Free RPG


Run Time Array in RPG AS400

Run Time Array in RPG AS400
Run Time Array in RPG AS400, array, types of array, run time array, as400, create,make, what, difference
Run Time Array in RPG AS400

Introduction to Run-Time Array

Run Time Array will be loaded during the run time i.e. program execution time and the values will be dynamic in nature.

Code Example of Run-Time Array in RPG

RPG Code in Fixed format for Run Time Array in AS400
      *Header Specification                                                 
     HDebug(*Yes)                                                           
     HOption(*NoDebugio)                                                    
      * program variables                                                                                                   
     D Array           S             10A   DIM(10)                                 
      *                                                                     
     D Index           S             10i 0                                                                    
      *                                                                     
     C                   EVAL      Index = 1                                
     C                   DOW       Index <=10                                
     C                   EVAL      Array(Index) = 'TEST' +                            
     C                             %Trim(%Char(Index))       
     C     Array(Index)  DSPLY                                              
     C                   EVAL      Index = Index + 1                        
     C                   ENDDO                        
     C                   EVAL      *INLR = *ON                                                    
RPG Code in /Free format for Run Time Array in AS400
      *Header Specification                                            
     HDebug(*Yes)                                                      
     HOption(*NoDebugio)                                               
      * program variables                                                                                                   
     D Array           S             10A   DIM(10)                                 
      *                                                                     
     D Index           S             10i 0                               
      *                                                                
      /Free                                                            
       // Begin program                                                
       Index =  1;                                                     
       Dow (Index <=10);                                                
         Array(Index) = 'TEST' + %Trim(%Char(Index));                   
         DSPLY Array(Index);                                           
         Index = Index + 1;                      
       EndDo;                                    
                                                 
       //Set Last Record Indicator ON            
       *Inlr = *ON;                              
                                                 
      /End-Free                                                                                                                             
RPG Code in fully Free format for Run Time Array in AS400
**FREE                                                     
                                                           
ctl-opt debug(*yes);                                       
ctl-opt Option(*NoDebugio);                                
                                                           
dcl-s Array char(10) DIM(10);                      
                                                           
dcl-s Index int(10);                                                                    
                                                           
// Begin program                                           
Index =  1;                                                
Dow (Index <=10);                                           
  Array(Index) = 'TEST' + %Trim(%Char(Index));       
  DSPLY Array(Index);                                      
  Index = Index + 1;                                       
EndDo;        
                                             
//Set Last Record Indicator ON   
*Inlr = *ON;                                                                         

Program Output

DSPLY  TEST1   
DSPLY  TEST2   
DSPLY  TEST3   
DSPLY  TEST4   
DSPLY  TEST5   
DSPLY  TEST6   
DSPLY  TEST7   
DSPLY  TEST8   
DSPLY  TEST9   
DSPLY  TEST10  

Related Post

Post a Comment

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