subfile
load all subfile has fixed size of 9999 records
What is a load all subfile?
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 subfile at a time. In that situation the records will not be placed at contiguous memory location.
So, conceptually a load all subfile is the one in which all records are loaded at one go before they are displayed. Also, they should occupy contiguous memory locations.
Load all subfiles are the easiest concept in subfile. That too when the subfile is display only! Let us now see the example of a load all subfile DDS.
** 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
A R LOADALLSF SFL
** Declare fields as we would do in case of normal record format.
A $CUSNAME 20A 5 10TEXT('Customer name')
A DSPATR(HI)
**
A $CUSNO 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 associa
** 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 ** FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++ 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 ** CL0N01Factor1+++++++Opcode&ExtExtended-factor2++++++++++++ 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. 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). ** 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 $CusNo = 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
how to define an expanding page size subfile using rpg on the as400
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.
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 $CUSNAME 20A 5 10TEXT('Customer Name')
A DSPATR(HI)
**
A $CUSNO 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 $CusNo = 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
Single Page Subfiles
What are single page subfiles?
A single page subfile is a subfile in the number of records loaded at a time is equal to the maximum number of records which can be displayed at a time. In other words in a single page subfile all loaded records are displayed at a time. We delete all previously loaded records from the subfile whenever we need to load the next page of the subfile.
A single page subfile is characterized by equal number of subfile and page sizes. Also, in a single page subfile both ROLLUP and ROLLDOWN keywords must be defined in the DDS of the subfile control format. This is because the ROLLUP and ROLLDOWN activities are handled by the program.
After learning the expandable subfile processing with ILE RPG in the previous chapter, a single page subfile should not be very difficult for you. The source code of the DDS and RPG IV program which processes the subfile are given in the example below.
Example to process a single page subfile in ILE RPG IV.
**
** 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 SINGLESF SFL
**
** Declare fields as we would do in case of normal record format.
**
A $CUSNAME 20A 5 10TEXT('Customer Name')
A DSPATR(HI)
**
A $CUSNO 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 SINGLECF SFLCTL(SINGLESF)
**
** Function keys are defined in the record format.
**
A CA01
A CA05
**
** Declare the page size and subfile size
**
A SFLPAG(15)
A SFLSIZ(15)
**
** 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)
**
** Declare the ROLLDOWN key. The number inside the bracket is the
** indicator which would be set on when ROLLDOWN key has been press
** ed.
**
A ROLLDOWN(61)
**
** 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 RPG IV (ILE RPG) program which processes the above subfile is given below. Notice that the function key F5 to refresh the page (Meaning reloading the subfile from beginning) has not been implemented. You can try it as an excercise.
** ** Declare the display file which contains the SINGLE PAGE subfile ** FFilename++IPEASF.....L.....A.Device+.Keywords++++++++++++++++++++++ FSingleSFL CF E WorkStn ** ** Declare the relative record number (RRN) for the subfile. Notice ** the keyword used to declare subfile. ** F SFILE(SINGLESF: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 records written ** to subfile at any time. ** DW@Counter S 2 0 Inz ** ** Define the variable to store the last displayed value ** DW@LastVal S 4 0 Inz ** ** Load the first page of the subfile. ** CL0N01Factor1+++++++Opcode&ExtFactor2+++++++Result++++++++Len++D+HiLoEq C ExSr #NextPage ** C DoW *INKA = *Off ** ** ** ExFmt the CONTROL FORMAT of the subfile. ** C ExFmt SINGLECF ** C Select ** ** Indicator 60 is set on by the as400 system when ROLLUP is pressed ** C When *In(60) = *On ** ** Execute subroutine to load the next page of subfile ** C ExSr #NextPage ** ** Indicator 60 is set on by the as400 system when ROLLDOWN is pressed ** C When *In(61) = *On ** ** Execute subroutine to load the next page of subfile, if this is not ** the first page of the subfile. ** C If W@LastVal > 15 C ExSr #PrevPage C EndIf ** C EndSl ** C EndDo ** ** Free up resources and return ** C Eval *InLr = *On C Return ** ** The subroutine #CLRSFL to clear the subfile and reset the RRN ** 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 SINGLECF C Eval *In(50) = *Off C Eval W@Rrn1 = *Zeros C EndSr ** ** Subroutine to process the ROLLUP key. ** C #NextPage BegSr ** ** The subfile is to be cleared every time a new page is loaded. ** C ExSr #ClrSfl ** ** Reset the counter ** C Eval W@Counter = *Zeros ** ** Set a looping condition. This condition 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 ** ** In single page subfiles, the last and first values of a subfile are ** are very important to keep track of the records currently being ** displayed. Here, we are storing the last value only. We will subtr- ** act 15 to get the first record ** C Eval W@LastVal += 1 ** ** Populate the fields defined in the subfiles. To load a blank subfil ** e we can just intialize the subfile fields. ** C Eval $CusNo = W@LastVal ** ** Perform actual write to the subfile. Notice that each write actuall ** y adds a record to the subfile just like in case of any other type ** of subfile! ** C Write SINGLESF C EndDo C EndSr ** ** Load the previous page of the subfile. ** C #PrevPage BegSr ** ** The subfile is to be cleared every time a new page is loaded. ** C ExSr #ClrSfl ** ** Reset the counters, Retrieve the value of the first record of the ** subfile. Here we are sutracting the page size from the last value. ** This is OK here, but in practical situation where we do not have ** such straight-forward relationship we do the followings ** 1. Store the key values in variables each time the subfile is loded ** 2. Chain the first record of the subfile and retrieve the required ** value. ** C Eval W@Counter = 15 C Eval W@LastVal -= 15 ** C DoW W@Counter > 0 And W@LastVal > 0 ** C Eval W@Counter -= 1 ** C Eval W@Rrn1 += 1 ** ** Populate the fields defined in the subfiles. We populate the custom ** er number by the last displayed value - the RRN. ** C Eval $CusNo = W@LastVal - W@Counter ** ** Perform actual write to the subfile. Notice that each write actuall ** y adds a record to the subfile. ** C Write SINGLESF C EndDo ** C EndSr







