Expandable subfiles in RPGLE
An expandable subfile is one in which ideally one page of records are loaded at a time. Subsequent pages are added to the subfile as per the user demand.
In the expandable subfile the subfile size must be at least one greater than the page size.
The ILE RPG program to process an expandable subfile has typically the following flow
1. Load the subfile: Initially the only the first one page of the subfile is loaded.
2. Display the subfile: The subfile screen is displayed to the user.
3. Rollup: Check if user pressed the rollup key. Many a times no rollup is defined and the next page is loaded with ENTER (RETURN) key only. If ROLLUP key has been pressed, load the next page and display it.
Note: In expandable subfiles, we do not need to handle ROLLDOWN. This is handled by the system itself. This is because we do not clear subfile before loading the next page. The next page records are simply added to already existing first page.
Special Offer for all NICKLITTEN Punters
20% Off with Coupon: NICKLITTEN
In Partnership with SNUG CBD - American readers get 20% off
CBD helps with relaxation, focus and great for pain relief. I highly recommend the SNUG CBD Tincture to help keep you in the zone when programming!
The following example illustrates how to process an expandable subfile (Some people like to call it extensible subfile because the subfile extends to accommodate the newly written records). Comments have been given at appropriate places to help you understand the flow of the program easily. Notice the ROLLUP function defined in the DDS here.
** Declare the name of the record format of the subfile. Notice ** that this time the function SFL has been used to distinguish ** this record format as a subfile ** AAN01N02N03T.Name++++++RLen++TDpBLinPosFunctions++++++++++++++++++ A R EXPANDSF 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 EXPANDCF SFLCTL(EXPANDSF) ** ** Function keys are defined in the record format. ** A CA01 A CA05 ** ** Declare the page size and subfile size ** A SFLPAG(15) A SFLSIZ(16) ** ** 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 ** ** Declare the ROLLUP key. The number inside the bracket is the ** indicator which would be set on when ROLLUP key has been press ** ed. ** A ROLLUP(60) ** ** The SFLRCDNBR is the subfile record number. SFLRCDNBR is a ** hidden filed. This is used here to display the last page ** whenever a new page is loaded. The name and data type of this ** field has been kept same as the RRN of this subfile in the ** program. This ensures that we do not have to explicitly popula ** te this field. This field automatically contains the last RRN ** of the subfile which always would be on the last page. ** Caution: SFLRCDNBR variable can not be zero, so ensure that ** you do not display the subfile when it is zero. ** A W@RRN1 4 0H SFLRCDNBR ** ** 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 F5=Refresh' A 4 02'Id' A DSPATR(UL) A 4 10'Customer Name' A DSPATR(UL)
/**** The program to process the above subfile. Currently only one field is being populated ***/
** ** Declare the display file which contains the expandable subfile ** FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++ FEXPANDSFL CF E WorkStn ** ** Declare the relative record number (RRN) for the subfile. Notice ** the keyword used to declare subfile. ** F SFILE(EXPANDSF: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 ** ** Define a couter variable to keep track of number of record ** to subfile at any time. ** DW@Counter S 2 0 Inz ** ** Execute subroutine to clear the subfile. The subfile is to ** ed everytime the screen is refreshed. ** CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len+ C ExSr #ClrSfl ** ** Load the first page of the subfile. ** C ExSr #LodSfl ** C DoW *INKA = *Off ** ** ExFmt the CONTROL FORMAT of the subfile. ** C ExFmt ExpandCF ** C Select C When *INKE = *On ** ** Execute subroutine to load the subfile after clearing it. ** C ExSr #ClrSfl C ExSr #LodSfl ** C When *In(60) = *On ** ** Execute subroutine to load the next page of subfile. ** C ExSr #LodSfl C EndSl ** C EndDo ** ** Free up resources and return ** C Eval *InLr = *On C Return ** ** The subroutine #LODSFL ** ** C #CLRSFL BegSr ** ** Clear the subfile. Clearing a subfile involves the following four ** statements. ** 1. Swicth on the SFLCLR indicator ** 2. Write to the control format ** 3. Swicth off the SFLCLR indicator ** 4. Reset the RRN to zero (Or one). ** C Eval *In(50) = *On C Write ExpandCF C Eval *In(50) = *Off C Eval W@Rrn1 = *Zeros C EndSr C #LODSFL BegSr ** ** ** Reset the counter ** C Eval W@Counter = *Zeros ** ** Set a looping condition. This condition this time will be based on ** the page size. You can club it with any other condition you require ** However, the number of records loaded at a time should ideally not ** exceed the page size. ** C DoW W@Counter < 15 ** ** Increment the counter to keep track of number of record written at ** a time to the subfile. This count should not exceed the page size. ** C Eval W@Counter += 1 ** ** 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. You may add a check here to confirm ** that the RRN is within the valid range. ** C Eval W@Rrn1 += 1 ** ** Populate the fields defined in the subfiles. To load a blank subfile ** e we can just intialize the subfile fields. ** C Eval = W@Rrn1 ** ** Perform actual write to the subfile. Notice that each write actually ** adds a record to the subfile. ** ** C Write ExpandSF C EndDo ** C EndSr