Ü  Array

Array is collection of elements of same data type.

 

 

Ü  Types of Array

1)      Compile time array

2)      Pre-runtime array

3)      Run time array

 

1)     Compile time array

·         The compile time array means the elements of the array will be loaded before the execution of the programs i.e. at compile time.

·         The value will be static.

·         We must declare in keyword command DIM (), CTDATA (), and PERRCD ().

DIM() represents the size of the array.

CTDATA() represents that it is compile time array.

PERRCD() represents the number of entries in one array record.

Dim = row i* col j

e.g.   PERRCD=2, NO. OF ROWS=3, THEN DIM = PERRCD*NO. OF ROWS=6

·         We mention the array element just after the last statement of the program.

 

Example

Columns . . . :    1 100                                      Browse           
 SEU==>                                                                         
 FMT D  .....DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++
        *************** Beginning of data **************************************
0001.00      darr1             s              3P 0 dim(5) ctdata perrcd(1)      
0002.00      darr2             s              3P 0 dim(5) ctdata perrcd(1)      
0003.00      dS                s              3p 0 inz(0)                       
0004.00      dn                s              2p 0 inz(1)                       
0005.00      c     n             do        5                                    
0006.00      c                   eval      s=arr2(n)-arr1(n)                    
0007.00      c     s             dsply                                          
0008.00      c                   add       1             n                      
0009.00      c                   enddo                                          
0010.00      c                   seton                                      lr
0011.00 ** CTDATA arr1                                                          
0012.00 101                                                                     
0013.00 102                                                                     
0014.00 103                                                                     
0015.00 104                                                                     
0016.00 105                                                                     
0017.00 ** CTDATA arr2                                                          
0018.00 201                                                                     
0019.00 202                                                                     
0020.00 203                                                                        
0021.00 204                                                                        
0022.00 205                                                                        
        ****************** End of data ********************************************

 

 

OUTPUT

DSPLY    100

DSPLY    100

DSPLY    100

DSPLY    100

DSPLY    100

 

 

2)     Pre-runtime array

·         There are some limitations of compile time array. E.g. If we want to change the value of an array element, we need to make changes in the program source code where the array’s element is defined and then recompile the program.

·         In pre-runtime array, we maintain the array element in separate file. Hence, if we are making any change in array element we can just change this file containing the array element; we don’t need to compile the source program again and again as in compile time array.

·         The file that stores the array element must be defined in the F specs with ‘T’ as File Designation entry.

·         Record length is also a mandatory entry in F spec.

 length of record = Perrcd *size of 1 element

·         The file is opened at program initialization. At that time the array loads from this external file.

·         To define the array in our program, we use keyword FROMFILE() instead of CTDATA().

 

Example- I

Flat-File USED: Flat01

 

FLAT1

AAAAA

BBBBB

CCCCC

DDDDD

EEEEE

 

 

Columns . . . :    6  80                         Browse                       AMITCC/QRPGLESRC
SEU==>                                                                             PRE_RUN_AR
FMT F  FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++++++++++++++++++++++++++
        *************** Beginning of data ****************************************************
0001.00 FFLAT01    IT   F    5        DISK                                              130201
0002.00 DPRE_ARR          S              5    DIM(5) FROMFILE(FLAT01) PERRCD(1)         130201
0003.00 C     PRE_ARR(1)    DSPLY                                                       130201
0004.00 C     PRE_ARR(2)    DSPLY                                                       130201
0005.00 C     PRE_ARR(3)    DSPLY                                                       130201
0006.00 C     PRE_ARR(4)    DSPLY                                                       130201
0007.00 C     PRE_ARR(5)    DSPLY                                                       130201
0008.00 C                   SETON                                        LR             130201
        ****************** End of data *******************************************************

 

 

OUTPUT

AAAAA

BBBBB

CCCCC

DDDDD

EEEEE

 

 

Example - II

PHYSICAL FILE USED IN THE PRORAM: PF2

  FLD1     FLD2

10,001   20,001

10,002   20,002

10,003   20,003

10,004   20,004

10,005   20,005

********  End of data  ********

 

 

 


Columns . . . :    6  80                       Browse                                    AMITCC/QRPGLESRC
SEU==>                                                                                         PRE_RUN_A2
FMT F  FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++++++++++++++++++++++++++
*************** Beginning of data ***********************************************************************
0001.00 FPF2       IT   F   10        DISK    <<< Here length of record(10)= Perrcd(2)*size of 1 element(5)
0002.00 DPRE_ARR          S              5P 0 DIM(12) FROMFILE(PF2) PERRCD(2)  <<< 5P0 = size of 1 element,
	                                                                               DIM=2*5(i*j)
0003.00 D                                            EXTFMT(P)  <<<<<< Keyword to avoid decimal data error
0004.00 DN                S              2  0 INZ(1)
0005.00 C     N             DO        12
0006.00 C     PRE_ARR(N)    DSPLY
0007.00 C                   EVAL      N=N+1
0008.00 C                   ENDDO
0009.00 C                   SETON                                        LR
****************** End of data **************************************************************************

 

OUTPUT

10001

20001

10002

20002

10003

20003

10004

20004

10005

20005

10006

20006

 

 

3)     Run time array

·         The run time array means the value will be loaded during the runtime only.

·         The value will be dynamic.

 

Columns . . . :    1 100             Browse            
 SEU==>                                                                          
 FMT D  .....DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++++++++++
        *************** Beginning of data ***************************************
0001.00      darr1             s              3P 0 dim(5) 
0002.00      dn                s              2p 0 inz(1)                        
0003.00      c     n             do        5                                     
0004.00      c                   eval      arr1(n)=n                             
0005.00      c     arr1(n)       dsply                                           
0006.00      c                   add       1             n                       
0007.00      c                   enddo                                           
0008.00      c                   seton                                        lr 
        ****************** End of data ******************************************

 

O/P

DSPLY    1

DSPLY    2

DSPLY    3

DSPLY    4

DSPLY    5

 

 

 

Ü Some useful array related op-codes

Lookup: It is used to look for an element in the array.

Sorta: It is used to sort the array element

Xfoot: It is used to sum-up the array element.

 

 

Columns . . . :    1 100                   Browse                
 SEU==>                                                                              
 FMT D  .....DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++++++++++++++
        *************** Beginning of data *******************************************
0001.00      darr2             s              3P 0 dim(5) ctdata perrcd(1)           
0002.00      dn                s              2p 0 inz(1)                            
0003.00      C     n             do        5                                         
0004.00      C     arr2(n)       dsply                                               
0005.00      C                   eval      n=n+1                                     
0006.00      C                   enddo                                               
0007.00      C                   sorta     arr2                                      
0008.00      C                   eval      n=1                                       
0009.00      C     n             do        5                                         
0010.00      C     arr2(n)       dsply                                               
0011.00      C                   eval      n=n+1                                     
0012.00      C                   enddo                                               
0013.00      C     204           lookup    arr2                                   81 
0014.00      C                   if        *in81=*on                                 
0015.00      C     'found'      dsply                                               
0016.00      C                   endif                                               
0017.00      C                   xfoot     arr2          sum               4 0       
0018.00      C     sum           dsply                                               
0019.00      c                   seton                                        lr
0020.00 ** CTDATA arr2                                                                 
0021.00 201                                                                            
0022.00 205                                                                            
0023.00 203                                                                            
0024.00 202                                                                            
0025.00 204                                                                            
        ****************** End of data ************************************************

 

 

 

O/P

DSPLY  201   

DSPLY  205   

DSPLY  203   

DSPLY  202   

DSPLY  204   

DSPLY  201   

DSPLY  202   

DSPLY  203   

DSPLY  204   

DSPLY  205   

DSPLY  found 

DSPLY  1015  











User Comments:



Subscribe

.  


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