What are single page subfiles?
A single page subfile is a SCREEN OF DISPLAYED DATA loaded at a one time in one go. The displayed data 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 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 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 = 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 = 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