Sub-file programming - loading a page at a time

This is the code for loading a subfile a page at a time written in the older style RPG format. If you would like to see this program written in the modern RPG-ILE format, click here.



         *************** 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 # (REC#)   
0005.00 FT400D002  CF   E             WORKSTN                                   
0006.00 F                                     SFILE(SFDATA:REC#)                
0007.00 FCUS01     IF   E           K DISK                                      
0008.00  *                                                                      
0009.00 C     *IN03         DOWEQ     *OFF                                      
0010.00  * Show screen for user to enter the salesperson's number               
0011.00 C                   EXFMT     ENTSLS                                    
0012.00 C     *IN03         IFEQ      *OFF                                      
0013.00  * Clear the subfile                                                    
0014.00 C                   EXSR      CLRSF                                     
0015.00  * !!!!! Start reading the customer file for this salesperson           
0016.00 C     CUSSLS        SETLL     CUS01                                     
0017.00 C     CUSSLS        READE     CUS01                                  95 
0018.00  * !!!!! Turn off indicator that indicates SFLEND                       
0019.00 C                   MOVE      *OFF          *IN95                       
0020.00  * Load  the subfile                                                    
0021.00 C                   EXSR      LODSF                                     
0022.00  * Show the command key footer and then the subfile SFCTL               
0023.00 C                   WRITE     CMDKEYS                                   
0024.00 C                   EXFMT     SFCTL                                     
0025.00  * !!!!! Loop to continue loading a new page when PAGE-DOWN hit         
0026.00 C     *IN21         DOWEQ     *ON                                       
0027.00 C                   EXSR      LODSF                                     
0028.00 C                   EXFMT     SFCTL                                     
0029.00 C                   ENDDO                                               
0030.00  * Process any seleted records                                          
0031.00 C                   EXSR      SELRCD                                    
0032.00 C                   ENDIF                                               
0033.00 C                   ENDDO                                               
0034.00 C                   MOVE      *ON           *INLR                       
0035.00 C                   RETURN                                              
0036.00  *---------------------------------------------------------------       
0037.00 C     CLRSF         BEGSR                                               
0038.00  * Clear the subfile by writing a SFCTL record with Indicator 50        
0039.00 C                   MOVE      *OFF          *IN50                       
0040.00 C                   WRITE     SFCTL                                     
0041.00 C                   MOVE      *ON           *IN50                       
0042.00  * Set the record number variable to zero                               
0043.00 C                   MOVE      *ZERO         REC#              4 0       
0044.00 C                   ENDSR                                               
0045.00  *--------------------------------------------------------------        
0046.00 C     LODSF         BEGSR                                               
0047.00  * !!!!! Keep record number for positioning cursor in sub-file          
0048.00 C     1             ADD       REC#          SFLRCD                      
0049.00  * !!!!! load 1 page of subfile (DO this # of times = to SFLPAG)        
0050.00 C                   DO        5                                         
0051.00 C                   ADD       1             REC#                        
0052.00 C                   WRITE     SFDATA                                    
0053.00 C     CUSSLS        READE     CUS01                                  95 
0054.00 C     *IN95         IFEQ      *ON                                       
0055.00 C                   LEAVE                                               
0056.00 C                   ENDIF                                               
0057.00 C                   ENDDO                                               
0058.00  * If subfile is empty, write a record that says "*NO RECORDS"          
0059.00 C     REC#          IFEQ      *ZERO                                     
0060.00 C                   ADD       1             REC#                        
0061.00 C                   CLEAR                   SFDATA                      
0062.00 C                   MOVEL     '*NO RECORDS*'CUSNAM                      
0063.00 C                   WRITE     SFDATA                                    
0064.00 C                   ENDIF                                               
0065.00 C                   ENDSR                                               
0066.00  *----------------------------------------------------------------      
0067.00 C     SELRCD        BEGSR                                               
0068.00  * Read the changed subfile data records                                
0069.00 C                   READC     SFDATA                                 96 
0070.00 C     *IN96         DOWEQ     *OFF                                      
0071.00 C     SEL           IFEQ      'X'                                       
0072.00  * Process the customer                                                 
0073.00  *   either CHAIN to customer master and EXFMT a display screen         
0074.00  *   or CALL a program with CUSNUM as a parameter                       
0075.00 C                   ENDIF                                               
0076.00 C                   READC     SFDATA                                 96 
0077.00 C                   ENDDO                                               
0078.00 C                   ENDSR                                                                                                                    
0079.00	*----------------------------------------------------------------


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