This example illustrates how RPG can use externally defined files to provide a data structure for an application.

0036.00 D detail        E DS                  extname(ADMHDRPF) inz          
0037.00 D ScreenFields  E DS                  extname(ADMHDRPF) prefix('ZF':2
0038.00 D After         E DS                  extname(ADMHDRPF) inz qualified
0039.00 D Before        E DS                  extname(ADMHDRPF) inz qualified
0040.00 D FunctionKey   E DS                  EXTNAME(SWKEYSP) qualified     
0041.00 D PGMDS         ESDS                  EXTNAME(SWPSTSP)               
0042.00 D DSPDS         E DS                  EXTNAME(SWDSPFP)               
0043.00 D MACDS         E DS                  EXTNAME(SWFUNCP) INZ           
0044.00 D OPTDS         E DS                  EXTNAME(SWOPTNP) INZ           
0045.00 D FUNCT         E DS                  EXTNAME(SWMACRP) INZ             

The code above shows database files used to define the program status data structure as well as create before and after images of a data record (the qualified data structures, before and after). Loading the data structures are an easy way of moving the file data without using multiple moves, or assignments.

0153.00           CHAIN(N)  p_OID ADMHDRPF;
0154.00           IF %found(ADMHDRPF);     
0155.00              before = detail;      
0156.00              after = detail;       
0157.00              IF adhsts = 'X';      
0158.00                 p$mode = 'V';      
0159.00              ENDIF;                
0160.00           ELSE;                    
0161.00              EXSR @Exit;           
0162.00           ENDIF;                   

Determining if something on the record has changed during the course of the program is simple, then. Compare the BEFORE data with the AFTER data and update the database if the data has changed.

0241.00              IF before <> after           
0242.00                 EXSR @GetRecord           
0243.00                 IF RecordLocked           
0244.00                    EXSR @UpdateDetail     
0245.00                       IF NoErrorFound     
0246.00                          msgid = 'MIS0009'
0247.00                          EXSR @GetMsg     
0248.00                       ELSE                
0249.00                          msgid = 'ADM0016'
0250.00                          EXSR @GetMsg     
0251.00                       ENDIF               
0252.00                 ENDIF                     
0253.00              ELSE                         
0254.00                 ReturnRequested = *on     
0255.00              ENDIF