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

Fixed, /Free and Fully Free RPG


Introduction to Subfile and its Types in AS400

Introduction to Subfile and its Types in AS400
Introduction to Subfile and its Types in AS400, subfile,subfile in as400, subfile in ibmi, subfile in iseries,subfile in systemi, subfile record format, subfile control record format, use of subfile, subfile mandatory keywords, SFL, SFLCTL, SFLDSP, SFLDSPCTL, SFLPAG, SFLSIZ, Types of subfile,load-all subfile,load all subfile,single page subfile,non-elastic subfile,expandable subfile,elastic subfile,growing subfile,growing subfile, SFLRCDNBR, OVERLAY, OVERLAY keyword in DSPF, display file, workstation file, Using subfile, what, what is, about, introduction, explain, subfile display, option 17 for DSPF, option 12 for DSPF, Use of subfile, Example for subfile in as400
Introduction to Subfile and its Types in AS400

Using Subfiles

Subfiles allow us to handle multiple records of the same type on the display screen to the workstation user. A subfile basically displays the records which are read from the database file through the program and written to the device file which then can be changed on the subfile display. One DSPF can have more than one subfile. There are 2 subfiles that can be displayed at the same time and a maximum of 12 subfiles can be active concurrently.

Record Formats used in Subfile

  • Subfile record format (SFL keyword)
  • Subfile control record format (SFLCTL keyword)
  • The subfile record format contains the field information on the DSPF and is controlled through the subfile control record format. The subfile control record format allows the read, write or control operations to be performed on the subfile.

    Use the SFILE keyword in the RPG program to use the subfile for the externally described display device(WORKSTN) file. The format of the SFILE keyword is as follows.

    SFILE(Subfile_RecordFormat_Name:RRN_Field_Name)

    We can use CHAIN, READC, UPDATE, WRITE operation codes with the subfile record format to transfer data between the program and the subfile.

    We can use READ, WRITE, and EXFMT operation codes with the subfile control record format to transfer data between program and display device or to process control.

    Subfile is processed based upon the relative record number i.e. RRN. The RPG program use READC (Read changed) operation code to read the changed record from the subfile and places the retrieved RRN into the RRN variable field specified in the 2nd parameter of the SFILE keyword. The RRN field is numeric decimal zero. This RRN field is used when we perform the WRITE operation to the subfile.

    Example DDS of a Subfile Record format

          * 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                                                                          
    

  • We use the R keyword to specify a record format in DSPF source member along with the record format name. The mandatory keyword SFL is used with any record format to indicate that this is a subfile record format.
  • Then in the next lines, we define the fields either directly or referenced from the file as above, we need to mention the field usage such as above we use O which indicates this is an output field and cannot be used for input and can only be used for display. Also, we need to specify the line number and positions for the fields.
  • Example DDS of a Subfile Control Record format

          * 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)                      
    

  • SFLCTL mandatory keyword with parameter as Subfile record format name is used with the record format name to indicate that it is a subfile control record format.
  • SFLSIZ mandatory keyword is used for indicating the total number of records that can be loaded in a subfile. Here a total of 100 records can be loaded as SFLSIZ(100) is specified.
  • SFLPAG mandatory keyword indicates how many records are to be displayed on the page at a time keeping the screen size limit in mind. Here we specified SFLPAG(4) means 4 records will be displayed on a screen page display and once we take page sown will display the next 4 records if loaded and on PAGUP will display the previous 4 records if not on the first page on the subfile.
  • OVERLAY keyword is used to retain previous record formats on the screen while displaying any other record format.
  • SFLDSP mandatory keyword indicates that display the subfile when at least one record loaded in the subfile i.e. associated indicator with SFLDSP keyword sets to ON by the RPG program. Here, When Indicator 10 is set to ON that means, there is at least one record loaded in subfile record format and we need to display the subfile.
  • SFLDSPCTL mandatory keyword is used to indicate display the subfile control record.
  • SFLRCDNBR is an optional keyword and can only be used with the subfile control record format. If we do not specify this keyword then by default the first page will be displayed on the workstation display. The RRN field associated with this keyword must be zoned decimal zero fields and the length can be up to 4 digits. It can be defined as Output only, Input-output only, or a Hidden field
  • Subfile Record Format Display

    We can take option 17 against the DSPF type source member

                                Work with Members Using PDM            
                                                                     
    File  . . . . . .   QDDSSRC                                      
      Library . . . .     IBMICLASS1           Position to  . . . . .
                                                                     
    Type options, press Enter.                                       
      16=Run procedure    17=Change using SDA       19=Change using R
      25=Find string      54=Compare                55=Merge ...     
                                                                     
    Opt  Member      Type        Text                                
    17   ENQSUBFILE  DSPF        Student Records Subfile             
         FILE1       PF          File1                               
         STUDENT     PF          Student PF                          
                                                                     
                                                                     
      
      

    This will display the "Work with Display Records" screen where we can take option 12 to see the display for any record format available. Here we take option 12 on subfile record format.

                         Work with Display Records                                
                                                                                  
    File  . . . . . . :   QDDSSRC                Member . . . . . . :   ENQSUBFILE
      Library . . . . :     IBMICLASS1           Source type  . . . :   DSPF      
                                                                                  
    Type options, press Enter.                                                    
      1=Add             2=Edit comments          3=Copy          4=Delete         
      7=Rename          8=Select keywords       12=Design image                   
                                                                                  
    Opt  Order    Record        Type      Related Subfile   Date        DDS Error 
                                                                                  
    12      10    SFLRFMT       SFL                         11/10/19              
    __      20    SFLCTLRFMT    SFLCTL    SFLRFMT           11/14/19              
    __      30    FOOTER        RECORD                      11/10/19                
      

    This will show us the subfile record format display.

                      Student Information Subfile                      
                                                                       
                                                                       
                                                                       
                                                                       
       EMPNO  EMPNAME               EMPSTATUS                          
       OOOOOO OOOOOOOOOOOOOOOOOOOO  OOOOOOOOOO                         
       OOOOOO OOOOOOOOOOOOOOOOOOOO  OOOOOOOOOO                         
       OOOOOO OOOOOOOOOOOOOOOOOOOO  OOOOOOOOOO                         
       OOOOOO OOOOOOOOOOOOOOOOOOOO  OOOOOOOOOO                         
                                                                       
                                                                       
                                                                       
                                                                       
                                                                       
                                                                       
                                                                       
                                                                       
                                                                       
                                                                       
                                                                       
                                                                       
                                                                       
    Work screen for SFLRFMT. SFLCTLRFMT displayed as additional record.  
      

    Use of Subfile

    We can use subfiles for the following purposes.

  • For Display inquiry.
  • For data Entry and Update to the record with or without validity checking.
  • For record selection with display etc.
  • Types of Subfile

    There are three types of Subfile in AS400 which are described as follows:

    Load-All Subfile

    All the records up to SFLSIZ but not more than 9999 would be first loaded to buffer at once and then from buffer to the subfile.

  • SFLSIZ should be at least 1 greater than the SFLPAG value.
  • PAGEUP and PAGEDOWN functionality is handled by the system itself.
  • Load All Subfile in RPG AS400
  • Single Page Subfile

    The subfile buffer is loaded with the SFLPAG or SFLSIZ (same) number of records and then the buffer gets cleared before loading the next SFLPAG number of records on pressing PAGEDOWN key.

  • SFLSIZ should be equal to the SFLPAG value.
  • We can load any number of records using a Single page subfile which overcomes the 9999 limits faced by other subfiles.
  • PAGEUP and PAGEDOWN functionality have to be written by the RPG programmer.
  • Expanding Subfile

    The subfile buffer is loaded with the SFLPAG number of records and then the buffer is not cleared before loading the next SFLPAG number of records on pressing the PAGEDOWN key up to max 9999 records and resulting in increasing the buffer size.

  • SFLSIZ should be at least 1 greater than the SFLPAG value.
  • We can load any number of records using a Single page subfile which overcomes the 9999 limits faced by other subfiles.
  • PAGEUP handling is not required. However, PAGEDOWN functionality has to be written by the RPG programmer.
  • 4 comments

    1. There is no Single page Subfile code
      1. Will do
    2. Please provide here full single page subfile code with proper example
      page up and page down should be handled in program
      1. Yes sure will do.
    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain