%FIELDS Built-In Functions in rpgle

%FIELDS funtion is used to partially update a file. In other words, we may need to update only 1 or 2 fields of a file. For that we use this funtion.

Format of %FIELDS function is: %FIELDS(field1: field2: ....) In the parameter of %FIELDS, We enter the fields name we want to update in file. Only the mentioned fields are updated.

Example –%fields built-in function in rpgle


In the example below, ACCMNGR and COUNTRY will be updated for physical file(ACCOUNT) with record format(rec5).


DDS of Input File "ACCOUNT" -

Field              File               Type                 Length 
ORG                ACCOUNT            NUMERIC                   3 
ACC                ACCOUNT            CHARACTER                12 
CCY                ACCOUNT            CHARACTER                 3 
ACCMNGR            ACCOUNT            CHARACTER                10 
COUNTRY            ACCOUNT            CHARACTER                10 
PARTY              ACCOUNT            CHARACTER                12 


Data in Input File "ACCOUNT" -

ORG CODE  ACC NUMBER    CURRENCY  ACCOUNT MNG  COUNTRY     PARTY              
   190    A00000000001    EUR     SHERRY       USA         P00000000001        
   190    A00000000002    EUR     MERRY        KOREA       P00000000002       
   190    A00000000003    USD     MING         CHINA       P00000000003       
   191    A00000000004    TRY     JHING        CHINA       P00000000004       
   190    A00000000005    USD     SHAAN        INDIA       P00000000005      
********  End of data  ********       


Program to demonstrate "%fields ( )" function -




 Columns . . . :    6  80                                              AMIT/QRPGSRC
 SEU==>                                                                     TESTRPG
 FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8
        *************** Beginning of data *****************************************
0001.00 FACCOUNT   UF A E           K DISK                                         
0002.00 C                                                                          
0003.00 C     K0001         Klist                                                  
0004.00 C                   kfld                    PARTY                          
0005.00 C                                                                          
0006.00 C                   Eval      PARTY = 'P00000000005'                       
0007.00 C     K0001         Chain     REC5                                         
0008.00 C                   IF        %FOUND()                                     
0009.00  /free                                                                     
0010.00    ACCMNGR = 'Josh';                                                       
0011.00    COUNTRY = 'AUS';                                                        
0012.00    Update rec5 %fields(ACCMNGR:COUNTRY);                                   
0013.00  /end-free                                                                 
0014.00 C                   Endif                                                  
0015.00 C                                                                          
0016.00 C                   Seton                                        LR        
        ****************** End of data ********************************************


Output

Last record of file ACCOUNT is updated with ACCMNGR = 'Josh' & COUNTRY = 'AUS'

ORG CODE  ACC NUMBER    CURRENCY  ACCOUNT MNG  COUNTRY     PARTY              
   190    A00000000001    EUR     SHERRY       USA         P00000000001        
   190    A00000000002    EUR     MERRY        KOREA       P00000000002       
   190    A00000000003    USD     MING         CHINA       P00000000003       
   191    A00000000004    TRY     JHING        CHINA       P00000000004       
   190    A00000000005    USD     SHAAN        INDIA       P00000000005      
********  End of data  ********   

 











User Comments:



Subscribe

.  


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