October 10

0 comments

RPG SQL: load all subfile has fixed maximum size of 9999 records

By NickLitten

October 10, 2008

RPG, code, example, sample, subfile

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 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 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 = 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
{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

>