Sub-file programming - loading a page at a time

This is the code for loading a subfile a page at a time written in RPG-ILE.



        *************** Beginning of data ************************************* 
0001.00  * All "1 page at a time" logic is indicated with a comment that        
0002.00  *     has !!!!! at the beginning                                       
0003.00  *                                                                      
0004.00  * Define the subfile and the variable that will hold record # (R EC#)  
0005.00 FT400D002  CF   E             WORKSTN                                   
0006.00 F                                     SFILE(SFDATA:REC#)                
0007.00 FCUS01     IF   E           K DISK                                      
0008.00  *                                                                      
0009.00 D REC#            S              4  0                                   
0010.00  *                                                                      
0011.00 C                   DoW       *In03 = *off                              
0012.00  * Show screen for user to enter the salesperson's number               
0013.00 C                   ExFmt     ENTSLS                                    
0014.00 C                   If        *In03 = *off                              
0015.00  * Clear the subfile                                                    
0016.00 C                   ExSr      ClearSubFile                              
0017.00  * !!!!! Start reading the customer file for this salesperson           
0018.00 C     CUSSLS        SetLL     CUS01                                     
0019.00 C     CUSSLS        ReadE     CUS01                                  95 
0020.00  * !!!!! Turn off indicator that indicates SFLEND                       
0021.00 C                   Eval      *In95 = *off                              
0022.00  * Load  the subfile                                                    
0023.00 C                   ExSr      LoadSubFile                               
0024.00  * Show the command key footer and then the subfile SFCTL               
0025.00 C                   Write     CMDKEYS                                   
0026.00 C                   ExFmt     SFCTL                                     
0027.00  * !!!!! Loop to continue loading a new page when PAGE-DOWN hit         
0028.00 C                   DoW       *In21 = *on                               
0029.00 C                   ExSr      LoadSubFile                               
0030.00 C                   ExFmt     SFCTL                                     
0031.00 C                   EndDo                                               
0032.00  * Process any seleted records                                          
0033.00 C                   ExSr      SelectRecord                              
0034.00 C                   EndIf                                               
0035.00 C                   EndDo                                               
0036.00 C                   Eval      *INLR = *on                               
0037.00 C                   Return                                              
0038.00  *---------------------------------------------------------------       
0039.00 C     ClearSubFile  BEGSR                                               
0040.00  * Clear the subfile by writing a SFCTL record with Indicator 50        
0041.00 C                   Eval      *In50 = *off                              
0042.00 C                   Write     SFCTL                                     
0043.00 C                   Eval      *In50 = *on                               
0044.00  * Set the record number variable to zero                               
0045.00 C                   Eval      REC# = *zero                              
0046.00 C                   EndSr                                               
0047.00  *--------------------------------------------------------------        
0048.00 C     LoadSubFile   BEGSR                                               
0049.00  * !!!!! Keep record number for positioning cursor in sub-file          
0050.00 C                   Eval      SFLRCD = REC# + 1                         
0051.00  * !!!!! load 1 page of subfile (DO this # of times = to SFLPAG)        
0052.00 C                   Do        5                                         
0053.00 C                   Eval      REC# = REC# + 1                           
0054.00 C                   Write     SFDATA                                    
0055.00 C     CUSSLS        ReadE     CUS01                                  95 
0056.00 C                   If        *In95 = *on                               
0057.00 C                   Leave                                               
0058.00 C                   EndIf                                               
0059.00 C                   EndDo                                               
0060.00  * If subfile is empty, write a record that says "*NO RECORDS"          
0061.00 C                   If        REC# = *zero                              
0062.00 C                   Eval      REC# = REC# + 1                           
0063.00 C                   Clear                   SFDATA                      
0064.00 C                   Eval      CUSNAM =  '*NO RECORDS*'                  
0065.00 C                   Write     SFDATA                                    
0066.00 C                   EndIf                                               
0067.00 C                   EndSr                                               
0068.00  *----------------------------------------------------------------      
0069.00 C     SelectRecord  BEGSR                                               
0070.00  * Read the changed subfile data records                                
0071.00 C                   ReadC     SFDATA                                 96 
0072.00 C                   DoW       *In96 = *off                              
0073.00 C                   If        SEL = 'X' or SEL = '1'                    
0074.00  * Process the customer                                                 
0075.00  *   either CHAIN to customer master and EXFMT a display screen         
0076.00  *   or CALL a program with CUSNUM as a parameter                       
0077.00 C                   EndIf                                               
0078.00 C                   ReadC     SFDATA                                 96 
0079.00 C                   EndDo                                               
0080.00 C                   EndSr                                               
0081.00  *----------------------------------------------------------------      


Back to Source Code Page   |   Basic 400 Skills   |   Main Page