|Introduction to Subfile and its Types in AS400|
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
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.
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
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)
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.
Types of Subfile
There are three types of Subfile in AS400 which are described as follows:
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.
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.
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.
page up and page down should be handled in program