A subfile is a special type of AS/400 display-file record. It is designed to hold column based list of data and to display that list in a column format. Sub Subfiles are used when you want to display multiple records on the display that have the same record layout.
The two major reasons for using subfiles are productivity and simplicity. A complex looking Display file can be totally written in a matter of minutes and takes only few lines of code.
Modifying a subfile program is much easier than modifying a non-subfile program, especially since there is much less program code to handle. The reason subfile programs are easy to write and maintain is because most of the functionality resides within the DDS specifications of the display file.
• A subfile may contain a maximum of 9999 Records.
• A subfile is of temporary nature and is active only for the duration of one program execution.
Components of Subfile
Subfile mainly requires two formats, v.i.z.,
• SUBFILE FORMAT {SFL}.
• SUBFILE CONTROL FORMAT {SFLCTL}.
Subfile format {SFL} defines the layout of the records in the subfile. The Subfile format is actually a file that resides in memory. The subfile format describes the subfile records, and also contains data. The DDS keyword to describe the subfile format is SFL. The SFL Keyword is the mandatory keyword for any subfile.
Subfile control format {SFLCTL} defines the subfile as a whole, such as how many records it can contain, how many records to display on a screen and so on. It is also used to display the subfile, or to clear records out of a subfile. The DDS keyword used to define a subfile control format is SFLCTL.
There are 22 keywords in Subfiles 17 in SFLCTL format & 5 in SFL format.
The Mandatory Keywords in subfiles are
• SFL { Subfile Record Format}
• SFLCTL { Subfile Control Format}
• SFLPAG { Subfile Page}
• SFLSIZ {Subfile Size }
•
Subfile Keywords
The following keywords are defined in the subfile control record format and are attributed to all the record for the subfile.
SFL Subfile Record Format
Identifies the named record format as a subfile record format
SLFCLR Subfile clear
Used to indicate that when the associated indicator is set on the next output operation to the subfile record format to clear all the record of the subfile.
SFLCTL Subfile control record format
Identifies the named record format as the subfile control record format
SFLDLT Delete subfile
Used to indicate that when the associated indicator is set on the next output operation to the subfile record format is to delete the subfile. The subfile would therefore be inactive.
SFLDROP Subfile drop
Used to indicate that when the associated command key is pressed, the secondary line(s) of a multiple line of subfile record are to be displayed. Upon the first output operation of the subfile, only the first line of each subfile record would be displayed.
SFLDSP Display subfile
Used to indicate that when the associated indicator is set on, the subfile is to be displayed upon the next output operation.
SFLDSPCTL Display subfile control
Used to indicate that the associated indicator is set on, the subfile record format is to be displayed upon the next output operation.
SFLEND Subfile end
Used to indicate that when the associated indicator is sent on, the constant ‘More…’ normally displayed at the bottom of the every multi-page subfile is suppressed. This condition is exercised when there are no more subfile records to be displayed.
SFLINZ Initialize subfile
Used to indicate that when the associated indicator is set on, the next output operation to the subfile is to initialise all the alphanumeric variable in the subfile record to blanks and all the numeric variable to zeros in every record for the subfile.
SFLLIN Subfile line
Used to specify the number of subfile records that should be displayed in the line of display
SFLMSG Subfile message
Used to associate an error message with an error condition at the subfile control record level
SFLPAG Subfile page
Used to specify the number of subfile records to be displayed in one page of display
SFLRCDNBR Subfile record number
Used to associate a variable name which would contain the value of a valid subfile relative record number. The page of the subfile containing the record whose relative record number is present in this variable would be displayed upon the next output operation to the subfile.
SFLRNA Subfile not active
Used to specify that the named subfile record format is to be made inactive. When used in association with the initialise subfile (SLFINZ) keyword, this has the effect of deleting the subfile.
SFLROLVAL Subfile roll value
Used to specify the number of records that are to be paged up/down when the Roll Up/Roll Down keys are used
SFLSIZ Subfile size
Used to specify the maximum number of records that are to displayed in a subfile at a time. The following keyword is the only keyword that is applicable at the subfile record. Thus this keyword, may be applicable or not to individual records in the subfile.
SFL Subfile record format
Identifies the named record format as a subfile record format
SFLNXTCHG Subfile next changed record
Associate an indicator with this keyword. This indicator may be set on/off individually for each record in the subfile. If this indicator set on, then the modified data tag for the associated subfile record is set on. In this case, the subfile record can be picked by a READC operation within the program.
Handling Subfiles in RPG Programs
File Declarations
• The Display file is declared as file in the file specification. Details that are included are
• Name of the display file
• Type which is ‘C’ and Designation ‘F’ to indicate combined Fully procedural file
• Device definition which is ‘WORKSTN’ to indicate a display file
• In the Continuation specification of the file specification, a variable name is identified as the subfile relative record number with the following RPG reserved word
RRNBR KSFILE SUBFIL
In the above example, a subfile record format SUBFIL with a relative record number RRNBR is declared.
• Within the ‘C’ specification itself, there would not be any reference in the display file name.
• All references would be to particular record formats only.
• Individual record formats may be returned or read from the screen
• If an output operation is done, (that is WRITE or related operation) the display is sent to the screen.
• If an input operation is done, (that is, READ or related operation) the display is read from the screen and the displayed data is made available to the program. At this point the control passes to the program.
Steps Involved In Subfile Programming :
• INITIALIZE - Initialize the RRN to Zero.
• CLEAR - Set On the SFL clear indicator, clear SFLCTL, write the SFLCTL & setoff the Indicator
• BUILD - Load the subfile by reading the PF & writing the Subfile record
Format.
• DISPLAY - Set on the SFLDSPCTL indicator & EXFMT the SFLCTL
• PROCESS - Process Changed Records Using READC or CHAIN opcodes
Multi page subfiles:
The first method of loading a subfile is to load all of the records that you want to display into the subfile at one time. After this load is complete you can display the subfile, which gives the users access to all of the subfile records by allowing them to roll backwards and forwards. Every record that you want to display must be loaded into the subfile before displaying the subfile.
Sometimes you may only load a few records into the subfile, other times you might load hundreds. But for the load-all subfile method, you simply load every record in before you display the subfile.
The subfile itself handles the roll keys, and you don’t even have to make reference of them in either the RPG program or the DDS specifications for the display file.
SUBFILE PAGE < SUBFILE SIZE
The following is the display file for load all subfiles.
******************************* Beginning of data *******************************************
F SFLRRNKSFILE DSFRCD C*
C EXSR INZSR C EXSR BLDSR C EXSR DSPSR
C SETON LR C*
C INZSR BEGSR //Clear subfile C Z-ADD*ZEROS SFLRRN 40
C SETON 93 CLRSFL C WRITEDSFCTL
C SETOF 93 C ENDSR
C*
C DSPSR BEGSR
C SETON 9091 //Display subfile C *IN03 DOUEQ'1'
C WRITESFLFTR C EXFMTDSFCTL C *IN03 IFEQ '0' C *IN05 IFEQ '1' C EXSR BLDSR C ENDIF C ENDIF C*
C ENDDO C ENDSR C*
C BLDSR BEGSR //Build Subfile C *LOVAL SETLLTSTREC
C READ TSTREC 94 C *IN94 DOWEQ'0'
C ADD 1 SFLRRN C WRITEDSFRCD
C READ TSTREC 94 C ENDDO
C ENDSR
*************************** End *******************
Expanding Subfile:
The second method of loading a subfile is to start by loading a specific number of records
into the subfile. You can then display the subfile to the user. If the information the user needs is not currently loaded into the subfile, your program can load more subfile records behind those already loaded. This technique is known as an expanding subfile.
If the user rolls forward (ROLL UP), then the subfile automatically switches the display to subfile page two for you. Here you have to set the indicator for ROLL UP keyword in DDS and handle it in the RPG program. ROLL DOWN(Page Up) is automatically taken care by the system.
One advantage of expanding subfile over a load-all-subfile is that the subfile is displayed to the user in a very stable amount of time, depending on how many records the program loads. With the expanding subfile, you can divide the load process into a fixed number of records. For instance, suppose you load six records at a time in an expanding subfile, It would not matter if there were a possibility of loading 5,000 records into the subfile, your program would only load six records before it displays the subfile to the user. This method displays the screen to the user very quickly.
SUBFILE PAGE << SUBFILE SIZE.
The following is the DDS code for display file (Expanding Subfile)
A* *******************************************************************
A DSPATR(UL)
The following is the RPG program for Expanding subfile
**************** Beginning of data************************************************************
C READ TSTREC 94
The third method of loading is known as a single-page load. In this process you only load the number of subfile records that can be displayed on the screen at one time. If the information the user needs is not in the subfile, then the existing subfile records are discarded, and another page worth of subfile records is loaded.If the information the user wants to see is not on this page of subfile records, then you can’t just add more records to the subfile like you do in an expanding subfile method. You must first clear the existing records out of the subfile. You clear a subfile by setting on an indicator located in the subfile control format that controls the clear operation. Then you write the subfile control format, which removes all data from the subfile.
This type of subfile is used when there are more than 9999 records in a database.
SUBFILE PAGE = SUBFILE SIZE
A DSPATR(UL)
************************************ End of data
*******************************************************
RPG program for Page-By-Page Build Subfile
**************** Beginning of data************************************************************
C COUNT IFEQ 6
The data to be displayed on a screen frequently exceeds the space available to display it. This is especially true when you design displays with subfiles that are usually limited to a single row of 80 characters.
The subfile keyword that initially displays only the first line of the subfile records and reacts to a function key by switching into a multi line format is SFLDROP .Conversely , The
keyword SFLFOLD initially displays the subfile in a multi line format and reacts to a function key by switching to a single line format .
Ex :
* CF06 is the function key that causes the display file to switch from the drop(single line format ) to the fold(multiline format)
* Subfile page size( SFLPAG) has been changed to the number of folded records that can be displayed.
Other interesting Subfile Keywords:
SFLRCDNBR , SFLMODE, SFLCSRRRN, SFLROLVAL
Additional Recommended Reading Material 1. SC21-9658-2 Data Management Guide