What is a load all subfile?
Quite simply, an RPG load all subfile is loaded until all rows are read, or the subfile has reached it's maximum size of 9999 rows.
A load all subfile is one in which we generally specify the subfile size as 9999 in the record format itself. However, you may define the subfile size to be less than 9999 in the record format and still load all your rows into that subfile at a time.
A load all subfile will be defined as 9999 max, but may contain any amoutn of data from NOTHING up to 9999 rows.
Load all subfiles are the easiest concept in subfile. Especially when the subfile is display only!
Let's see the example of a load all subfile DDS.
A R LOADALLSF SFL
** Declare fields as we would do in case of normal record format.
A 20A 5 10TEXT('Customer name')
A DSPATR(HI)
**
A 4Y 0 5 02TEXT('customer Number')
A DSPATR(HI)
**
** Control Format of the subfile. Notice the usage of function SFLCTL. The name of the subfile has been given here to associate this control format with a specific subfile.
A R LOADALLCF SFLCTL(LOADALLSF)
** Function keys are defined in the record format.
A CA01
** Declare the page size and subfile size
A SFLPAG(2)
A SFLSIZ(9999)
** Declare the function SFLCLR. We need this function to clear a subfile.
A 50 SFLCLR
** The SFLDSP and SFLDSPCTL functions are necessary to display subfile.
A SFLDSP
A SFLDSPCTL
** Define the control format fields. Generally the heading and subfile specific instructions are given here.
A 1 26' Customer Display '
A DSPATR(RI)
A 2 02'F1=Exit'
A 4 02'Id'
A DSPATR(UL)
A 4 10'Customer name'
A DSPATR(UL)
The source code with explanation of the ILE RPG program to process the load all subfile in the above example is given below.
**Declare the display file which contains the subfile
**
FLOAD_ALL CF E WorkStn
**
** Declare the relative record number (RRN) for the subfile. Notice
** the keyword used to declare subfile.
**
F SFILE(LOADALLSF:W@Rrn1)
**
** Define the RRN of subfile (Typically 4 or 5 length with zero
** decimal places depending on how you handle it. If it's likely to
** reach 10000 then declare the length as 5 otherwise 4.)
**
DW@Rrn1 S 4 0 Inz
**
C DoW *INKA = *Off
**
** Execute subroutine to load the subfile
**
C ExSr #LodSfl
**
** ExFmt the CONTROL FORMAT of the subfile.
**
C ExFmt LOADALLCF
C EndDo
**
** Free up resources and return
**
C Eval *InLr = *On
C Return
**
** The subroutine #LODSFL
**
C #LODSFL BegSr
**
** Clear the subfile. Clearing a subfile involves the following four
** statements.
** 1. Switch on the SFLCLR indicator
** 2. Write to the control format
** 3. Switch off the SFLCLR indicator
** 4. Reset the RRN to zero (Or one).
** The fourth statement actually is not related to subfile. However,
** we generally reset this value while clearing the subfile itself.
**
C Eval *In(50) = *On
C Write LOADALLCF
C Eval *In(50) = *Off
C Eval W@Rrn1 = *Zeros
**
** Set a looping condition. This condition may be based on anything.
** But in any case, just ensure that RRN does not exceed 9999.
**
C DoW W@Rrn1 < 9999
**
** Increment the RRN to mark a new record of subfile. Remember that
** the variable corresponding to RRN should not be less than one (1) a
** nd it should never exceed 9999.
**
C Eval W@Rrn1 += 1
**
** Populate the fields defined in the subfiles. To load a blank subfil
** e we can just intialize the subfile fields.
**
C Eval = W@Rrn1
**
** Perform actual write to the subfile. Notice that each write actuall
** y adds a record to the subfile.
**
C Write LOADALLSF
C EndDo
**
C EndSr