Now, Get RPG Codes in all three formats only on this website on every RPGLE related programming article.

Fixed, /Free and Fully Free RPG


Load All Subfile in RPG AS400

Load All Subfile in RPG AS400
Load All Subfile in RPG AS400, load-all subfile, load all subfile, rpg subfile, load all subfile in rpgle, load all subfile in as400, ibmi, iseries, example of load all subfile, coding load all subfile
Load All Subfile in RPG AS400

Load-All Subfile

You can read about the Load-all subfile introduction.

How to code a Load All subfile for Enquiry screens.

Create a DDS PF source member and its object

     A          R RSTUDENT                   
     A            EMPNO          6A          
     A            EMPNAME       20A          
     A            EMPSTATUS     10A          

The File STUDENT will be created/compiled using the CRTPF command or option 14 against the PF source member STUDENT.

  • WRKOBJ IBMICLASS1/STUDENT
  •                                Work with Objects                              
                                                                                  
     Type options, press Enter.                                                   
       2=Edit authority        3=Copy   4=Delete   5=Display authority   7=Rename 
       8=Display description   13=Change description                              
                                                                                  
     Opt  Object      Type      Library     Attribute   Text                      
     __   STUDENT     *FILE     IBMICLASS1  PF          Student PF                
    
  • Insert following records in STUDENT PF either using SQL INSERT or using UPDDTA command.
  • RUNQRY *N ibmiclass1/student

    Line   ....+....1....+....2....+....3....+....4 
           EMPNO   EMPNAME               EMPSTATUS  
    000001 1       NAME1                 ACTIVE     
    000002 2       NAME2                 INACTIVE   
    000003 3       NAME3                 ACTIVE     
    000004 4       NAME4                 ACTIVE     
    000005 5       NAME5                 ACTIVE     
    000006 6       NAME6                 ACTIVE     
    000007 7       NAME7                 ACTIVE     
    000008 8       NAME8                 INACTIVE   
    000009 9       NAME9                 INACTIVE   
    000010 10      NAME10                ACTIVE     
    000011 11      NAME11                ACTIVE     
    000012 5456    SDASDASD              SADASD     
    ****** ********  End of report  ********        
    

    Create a DDS DSPF source member using the Load-All subfile and its object

         A                                      DSPSIZ(24 80 *DS3)                     
         A                                      CA03(03)                               
          * Subfile Record format                                                      
         A          R SFLRFMT                   SFL                                    
         A            EMPNO     R        O  7  5REFFLD(RSTUDENT/EMPNO *LIBL/STUDENT)   
         A            EMPNAME   R        O  7 12REFFLD(RSTUDENT/EMPNAME +              
         A                                             *LIBL/STUDENT)                  
         A            EMPSTATUS R        O  7 34REFFLD(RSTUDENT/EMPSTATUS +            
         A                                             *LIBL/STUDENT)                  
         A                                                                             
          * Subfile control record format                                              
         A          R SFLCTLRFMT                SFLCTL(SFLRFMT)                        
         A                                      SFLSIZ(100)                            
         A                                      SFLPAG(4)                              
         A                                      OVERLAY                                
         A  10                                  SFLDSP                                 
         A                                      SFLDSPCTL                              
         A                                                                             
         A            SRRN           4S 0H      SFLRCDNBR                              
         A* Heading information inside Subfile control record format           
         A                                  6  5'EMPNO'                        
         A                                      DSPATR(UL)                     
         A                                  6 12'EMPNAME'                      
         A                                      DSPATR(UL)                     
         A                                  6 34'EMPSTATUS'                    
         A                                      DSPATR(UL)                     
         A                                  1 20'Student Information Subfile'  
         A                                      COLOR(BLU)                     
         A                                                                     
         A* Footer Record format                                               
         A          R FOOTER                                                   
         A                                                                     
         A                                 15  5'F3 = Exit'                    
         A                                      COLOR(BLU)                     
    

    You can read about the above keywords used with Subfile record format and Keywords used with Subfile control record format.

    Here we will create/compile DSPF named ENQSUBFILE either using command CRTDSPF or taking option 14 against the DSPF source member ENQSUBFILE.

  • WRKOBJ IBMICLASS1/ENQSUBFILE
  •                               Work with Objects                            
                                                                               
    Type options, press Enter.                                                 
      2=Edit authority        3=Copy   4=Delete   5=Display authority   7=Renam
      8=Display description   13=Change description                            
                                                                               
    Opt  Object      Type      Library     Attribute   Text                    
    __   ENQSUBFILE  *FILE     IBMICLASS1  DSPF        Student Records Subfile 
    

    Create an SQLRPGLE source member using Load-All Subfile and its object

    RPG Code in Fixed format for Load-All Subfile for Enquiry screens.
         F* File Specification                                                                      
         FSTUDENT   IF   E             DISK                                         * PF            
         FENQSUBFILECF   E             WORKSTN                                      * DSPF subfile  
         F                                     SFILE(SFLRFMT:RRN)                   * SFILE keyword 
         F                                     INFDS(infds)       
          * Data structure
         Dinfds            DS                                                                       
         DDRRN                   378    379B 0                                                      
          *                                                                                         
         D*Varibale declaration                                                                     
         D RRN             S              4  0                                      * RRN define    
                                                                                                    
          * Write Footer record format                                                              
         C                   WRITE     FOOTER                                                       
                                                                                                    
          * Display subfile control record format to display loaded subfile                         
          * records with SFLPAG and SFLSIZ settings defined in SFLCTLRFMT                           
         C                   EXFMT     SFLCTLRFMT                                                   
                                                                                                    
          * Process the command attention Keys                                                      
          * If user takes F3 to Exit on screen after subfile                   
          * has been displayed to the user                                     
         C                   EXSR      ProcKeyboard                            
                                                                               
          * ------------------                                                 
          * Subroutine : INZSR                                                 
          * ------------------                                                 
         C     *INZSR        BEGSR                                             
          * Set subfile RRN  = 0                                               
         C                   EVAL      RRN = 0                                 
          * SFLRCDNBR                                                          
         C                   EVAL      SRRN = 0                                
                                                                               
          * STEP 1: Load                                                       
          * Execute LOAD subroutine to write subfile records to Subfile format 
         C                   EXSR      LOAD                                    
         C                   ENDSR                                             
          * ------------------                                                 
          * Subroutine : LOAD                                                  
          * ------------------                                                 
         C     LOAD          BEGSR                                                
                                                                                  
          * Read file STUDENT and load the subfile records to                     
          * the subfile format (SFLRFMT) till the SFLSIZ reaches (100 here)       
          * LOAD-ALL Subfile                                                      
          * Reserve Indicator 99 for Stop loading the Subfile when SFLSIZ reaches 
                                                                                  
          * Initialize indicators                                                 
          * Stop loading SFLSIZ value reaches                                     
         C                   EVAL      *IN99 = *OFF                               
          * For SFLDSP                                                            
         C                   EVAL      *IN10 = *OFF                               
          * SFLRCDNBR                                                             
         C                   EVAL      srrN = srrn + 1                            
                                                                                  
         C     1             SETLL     RSTUDENT                                   
         C                   READ      RSTUDENT                                   
         C                   DOW       NOT%EOF(STUDENT) AND                       
         C                             NOT%ERROR AND                              
         C                             *IN99 <> *ON                               
                                                                               
          * Increase the RRN by 1                                              
         C                   EVAL      RRN = RRN + 1                           
                                                                               
          * Fields in Subfile format are referenced-> No need wvaluate here    
          * Write the Subfile record format SFLRFMT to load individual         
          * subfile records by reading database file STUDENT                   
                                                                               
         C                   WRITE     SFLRFMT                                 
                                                                               
          * Set Indicator 99 as ON when RRN reaches SFLSIZ value               
         C                   IF        RRN = 100                               
         C                   EVAL      *IN99 = *ON                             
         C                   ENDIF                                             
                                                                               
          * If you have loaded atleast one record into the subfile,            
          * then turn on indicator 10 associated with SFLDSP keyword.          
          * All OK to display the subfile.                                     
         C                   IF        RRN > 0                                 
         C                   EVAL      *IN10 = *ON                             
         C                   ENDIF                                            
                                                                              
         C                   READ      STUDENT                                
         C                   ENDDO                                            
                                                                              
         C                   IF        SRRN =  0                              
         C                   EVAL      SRRN = 1                               
         C                   ENDIF                                            
         C                   ENDSR                                            
                                                                              
          * --------------------------------                                  
          * Subroutine : ProcessKeyboardKeys                                  
          * --------------------------------                                  
         C     procKeyboard  BEGSR                                            
                                                                              
          * Execute this subroutine after every EXFMT(Write and Read)         
                                                                              
          * Check If F3 is pressed then, Set the LR (Last Record Indicator)   
          * to *ON and Exit from the program                                  
         C                   IF        *IN03 = *ON                            
         C                   EVAL      *INLR = *ON           
         C                   RETURN                          
         C                   ENDIF                           
                                                             
          * Check If ENTER key is pressed from the Keyboard  
         C                   IF        *IN03 <> *ON          
         C                   EVAL      SRRN = DRRN           
         C                   ENDIF                           
                                                             
         C                   ENDSR                                                                          
    
    RPG Code in /Free format for Load-All Subfile for Enquiry screens.
         F* File Specification                                                                        
         FSTUDENT   IF   E             DISK                                         * PF              
         FENQSUBFILECF   E             WORKSTN                                      * DSPF subfile    
         F                                     SFILE(SFLRFMT:RRN)                   * SFILE keyword   
         F                                     INFDS(infds)                                           
          * Data Structure
         Dinfds            DS                                                                         
         DDRRN                   378    379B 0                                                        
          *                                                                                           
         D*Varibale declaration                                                                       
         D RRN             S              4  0                                      * RRN define      
                                                                                                      
          /Free                                                                                       
             // Write Footer record format                                                            
                Write Footer;                                                                         
                                                                                                      
                                                                                                      
             // Display subfile control record format to display loaded subfile                       
             // records with SFLPAG and SFLSIZ settings defined in SFLCTLRFMT                         
                EXFMT SFLCTLRFMT;                                                                     
                                                                  
             // Process the command attention Keys                
             // If user takes F3 to Exit on screen after subfile  
             // has been displayed to the user                    
                EXSR ProcessKeyboardKeys ; 
                           
            // ------------------              
            // Subroutine : INZSR              
            // ------------------              
               BegSr *INZSR;                   
             // Set subfile RRN  = 0           
                RRN = 0 ;                      
                SRRN = 0 ;  // SFLRCDNBR       
                                               
             // STEP 1: Load            
             // Execute LOAD subroutine to write subfile records to Subfile format         
                EXSR LOAD;                                                                 
                                                                                           
                ENDSR;                                                                     
                                                                                           
                                                                                           
            // ------------------                                                          
            // Subroutine : LOAD                                                           
            // ------------------                                                          
               BegSr LOAD;                                                                 
                                                                                           
                 // Read file STUDENT and load the subfile records to                      
                 // the subfile format (SFLRFMT) till the SFLSIZ reaches (100 here)        
                 // LOAD-ALL Subfile                                                       
                 // Reserve Indicator 99 for Stop loading the Subfile when SFLSIZ reaches  
                                                                                           
                 //Initialize indicators                                                   
                   *IN99 = *OFF; // Stop loading SFLSIZ value reaches                      
                   *IN10 = *OFF;  // For SFLDSP                                            
                     srrN = srrn + 1 ;  //sflrcdnbr                                      
                                                                                         
                 Setll 1 RSTUDENT;                                                       
                 Read  RSTUDENT;                                                         
                 Dow NOT%EOF(STUDENT) and Not%error AND *IN99 <> *ON;                    
                                                                                         
                     // Increase the RRN by 1                                            
                     RRN = RRN + 1;                                                      
                                                                                         
                     // Fields in Subfile format are referenced-> No need wvaluate here  
                     // Write the Subfile record format SFLRFMT to load individual       
                     // subfile records by reading database file STUDENT                 
                                                                                         
                     Write SFLRFMT;                                                      
                                                                                         
                     // Set Indicator 99 as ON when RRN reaches SFLSIZ value             
                     If RRN = 100;                                                       
                        *IN99 = *ON;                                                     
                     EndIf;                                                              
                     // If you have loaded atleast one record into the subfile,   
                     // then turn on indicator 10 associated with SFLDSP keyword. 
                     // All OK to display the subfile.                            
                     If RRN > 0;                                                  
                        *IN10 = *ON;                                              
                     EndIf;                                                       
                                                                                  
                 Read STUDENT;                                                    
                 ENDDO;                                                           
                                                                                  
                 If SRRN =  0;                                                    
                   SRRN = 1;                                                      
                 EndIf;                                                           
               ENDSR;                                                             
                                                                                  
            // --------------------------------                                   
            // Subroutine : ProcessKeyboardKeys                                   
            // --------------------------------                                   
               BegSr ProcessKeyboardKeys;                                         
               // Execute this subroutine after every EXFMT(Write and Read)        
                                                                                   
               // Check If F3 is pressed then, Set the LR (Last Record Indicator)  
               // to *ON and Exit from the program                                 
               If *IN03 = *ON;                                                     
                 *INLR = *ON;                                                      
                 RETURN;                                                           
               EndIf;                                                              
                                                                                   
                                                                                   
                                                                                   
               // Check If ENTER key is pressed from the Keyboard                  
               If *IN03 <> *ON;                                                    
                  SRRN = DRRN;                                                     
                                                                                   
               EndIf;                                                              
                                                                                   
               EndSr;                                                              
                                                                                   
          /End-Free                                                                                                                                                                                                  
    
    RPG Code in Fully Free format for Load-All Subfile for Enquiry screens.
    **FREE                                                   
    DCL-F STUDENT;                                           
    DCL-F ENQSUBFILE WORKSTN SFILE(SFLRFMT:RRN) infds(infds);
                                                             
    dcl-ds infds;                                            
      drrn BINDEC(2:0) POS(378);                             
    end-ds;                                                  
                                                             
    dcl-s rrn packed(4);                                     
    
    // Write Footer record format
       Write Footer;             
    
    // Display subfile control record format to display loaded subfile 
    // records with SFLPAG and SFLSIZ settings defined in SFLCTLRFMT   
       EXFMT SFLCTLRFMT;                                               
    
    // Process the command attention Keys                
    // If user takes F3 to Exit on screen after subfile  
    // has been displayed to the user                    
       EXSR ProcessKeyboardKeys ;                        
    
    // ------------------                                                 
    // Subroutine : INZSR                                                 
    // ------------------                                                 
       BegSr *INZSR;                                                      
     // Set subfile RRN  = 0                                              
        RRN = 0 ;                                                         
        SRRN = 0 ;  // SFLRCDNBR                                          
                                                                          
     // STEP 1: Load                                                      
     // Execute LOAD subroutine to write subfile records to Subfile format
        EXSR LOAD;                                                        
                                                                          
        ENDSR;                                                            
                                                                                                                                               
    // ------------------                                                 
    // Subroutine : LOAD                                                  
    // ------------------                                                 
       BegSr LOAD;  
    
    // Read file STUDENT and load the subfile records to                    
    // the subfile format (SFLRFMT) till the SFLSIZ reaches (100 here)      
    // LOAD-ALL Subfile                                                     
    // Reserve Indicator 99 for Stop loading the Subfile when SFLSIZ reaches
                                                                            
    //Initialize indicators                                                 
      *IN99 = *OFF; // Stop loading SFLSIZ value reaches                    
      *IN10 = *OFF;  // For SFLDSP                                          
                                                                            
        srrN = srrn + 1 ;  //sflrcdnbr                                      
                                                                            
    Setll 1 RSTUDENT;                                                       
    Read  RSTUDENT;                                                         
    Dow NOT%EOF(STUDENT) and Not%error AND *IN99 <> *ON;                    
                                                                            
        // Increase the RRN by 1                                            
        RRN = RRN + 1;                                                      
                                                                            
        // Fields in Subfile format are referenced-> No need wvaluate here  
        // Write the Subfile record format SFLRFMT to load individual       
        // subfile records by reading database file STUDENT         
                                                                    
        Write SFLRFMT;                                              
                                                                    
        // Set Indicator 99 as ON when RRN reaches SFLSIZ value     
        If RRN = 100;                                               
           *IN99 = *ON;                                             
        EndIf;                                                      
                                                                    
        // If you have loaded atleast one record into the subfile,  
        // then turn on indicator 10 associated with SFLDSP keyword.
        // All OK to display the subfile.                           
        If RRN > 0;                                                 
           *IN10 = *ON;                                             
        EndIf;                                                      
                                                                    
    Read STUDENT;                                                   
    ENDDO;                                                          
                                                                    
    If SRRN =  0;                                                   
           SRRN = 1;                                                     
         EndIf;                                                          
       ENDSR;                                                            
                                                                         
    // --------------------------------                                  
    // Subroutine : ProcessKeyboardKeys                                 
    // --------------------------------                                  
       BegSr ProcessKeyboardKeys;                                        
                                                                         
       // Execute this subroutine after every EXFMT(Write and Read)      
                                                                         
       // Check If F3 is pressed then, Set the LR (Last Record Indicator)
       // to *ON and Exit from the program                               
       If *IN03 = *ON;                                                   
         *INLR = *ON;                                                    
         RETURN;                                                         
       EndIf;                                                            
    
     // Check If ENTER key is pressed from the Keyboard 
     If *IN03 <> *ON;                                   
        SRRN = DRRN;                                    
                                                        
     EndIf;                                             
                                                        
     EndSr;                                                                                                                       
    

    Create the object using the command CRTSQLRPGI or using option 14 against the ENQUIRYPGM SQLRPGLE source member.

  • WRKOBJ ENQUIRYPGM
  • Call and Test Subfile program

    CALL ENQUIRYPGM

    On the first page of the subfile, 4 records are displayed at a time.

                   Student Information Subfile   
                                                 
                                                 
                                                 
                                                 
    EMPNO  EMPNAME               EMPSTATUS       
    1      NAME1                 ACTIVE          
    2      NAME2                 INACTIVE        
    3      NAME3                 ACTIVE          
    4      NAME4                 ACTIVE          
                                                 
                                                 
                                                 
                                                 
    F3 = Exit                                    
    

    Press PAGEDOWN will bring the second page to the display screen.

                   Student Information Subfile  
                                                
                                                
                                                
                                                
    EMPNO  EMPNAME               EMPSTATUS      
    5      NAME5                 ACTIVE         
    6      NAME6                 ACTIVE         
    7      NAME7                 ACTIVE         
    8      NAME8                 INACTIVE       
                                                
                                                
                                                
                                                
    F3 = Exit                                   
    

    On the last page of the subfile when you press PAGEDOWN, will show the message at the last line of the screen display "Roll up or down past the first or last record in the file."

                      Student Information Subfile          
                                                           
                                                           
                                                           
                                                           
       EMPNO  EMPNAME               EMPSTATUS              
       9      NAME9                 INACTIVE               
       10     NAME10                ACTIVE                 
       11     NAME11                ACTIVE                 
       5456   SDASDASD              SADASD                 
                                                           
                                                           
                                                           
                                                           
       F3 = Exit                                           
                                                           
                                                           
                                                           
                                                           
                                                           
                                                           
                                                           
                                                           
    Roll up or down past the first or last record in file.             
    

    PAGEUP will bring the previous pages in the subfile buffer and on the first page if you press PAGEUP will show the message "Roll up or down past the first or last record in the file."

                      Student Information Subfile             
                                                              
                                                              
                                                              
                                                              
       EMPNO  EMPNAME               EMPSTATUS                 
       1      NAME1                 ACTIVE                    
       2      NAME2                 INACTIVE                  
       3      NAME3                 ACTIVE                    
       4      NAME4                 ACTIVE                    
                                                              
                                                              
                                                              
                                                              
       F3 = Exit                                              
                                                              
                                                              
                                                              
                                                              
                                                              
                                                              
                                                              
                                                              
    Roll up or down past the first or last record in file.    
    

    Refer material for Load All subfile Enquiry screen.


    Did you find the information listed in this article helpful? If you enjoyed this article, share it with your friends and colleagues!

    Thanks!

    Related Post

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain