%ELEM Built-In Functions in rpgle

%ELEM function is used to get total nunmberr of elements in an array, table, or multiple-occurrence data structure. In other words, we can get the dimension using this function.

It can be used in below formats:

 %ELEM(table_name)
 %ELEM(array_name)
 %ELEM(multiple_occurrence_data_structure_name)


Example –%elem built-in function in rpgle




0000.01 D table001        S              3P 0 dim(5) ctdata perrcd(1)              
0001.00 D arr001          S             10    dim(8)                               
0002.00 D ds001           DS                  occurs(10)                           
0003.00 D field001                1      5                                         
0004.00 D                                                                          
0005.00 D                                                                          
0006.00 D arr_table       S              2p 0                                      
0007.00 D arr_size        S              2p 0                                      
0008.00 D ds_size         S              2p 0                                      
0009.00                                                                            
0010.00 C                   Eval      arr_table  = %elem (table001)                
0011.00 C                   Eval      arr_size   = %elem (arr001)                  
0012.00 C                   Eval      ds_size    = %elem (ds001)                   
0013.00                                                                            
0014.00 C     arr_table     DSPLY                                                  
0015.00 C     arr_size      DSPLY                                                  
0016.00 C     ds_size       DSPLY                                                  
0017.00 C                                                                          
0018.00 C                   Seton                                        LR        


Output

DSPLY   5  
DSPLY   8  
DSPLY  10  











User Comments:



Copyright © www.go4as400.com, 2013-2023. Copyright notice   Terms of services   Privacy policy