It's time to create a simple load-all subfile in RPG for the AS/400 (now known as IBM i). In this example, we’ll display a list of customers on the screen in alphabetical order. The user can search for a customer by entering their name or partial name. Once the list is displayed, the user can select a customer to view more details.

Here are the steps to create this basic subfile:

  1. Define the Display File (DSPF):
    • Create a display file with two record formats: one for the subfile (SFL) and another for the control record (CTL).
    • Define the subfile record format (SFL) with the necessary fields (e.g., customer name, ID, etc.).
    • Specify the page size, record number, and display mode for the subfile.
  2. Design the Subfile Layout:
    • In the subfile record format (SFL), add headings, colors, and fields from the physical file (e.g., customer data).
    • Define any indicators needed for display, end, and clear functions.
  3. Write the RPGLE Program:
    • Declare the physical file (containing customer data) and the display file.
    • Define a variable for the record number of the subfile.
    • Write a subroutine to clear the subfile (switch on the clear indicator and write the control record).
    • Write a subroutine to load the subfile (read the physical file and write the subfile record format for each record).
    • In the main routine, call the clear and load subroutines, then display the subfile (switch on the display indicator and write the control record).
  4. Example RPGLE Code: Below is a simplified example of an RPGLE program for a load-all subfile. This is not a working RPG code example, instead it is an example of the type of code you will write for a typical RPG SUBFILE program. You’ll need to adapt this code to your specific requirements and file structures:

** Assume the Table (file) is called "customer"
** The DSPF is "subfile" with two record formats: SFL001 (the subfile) and CTL001 (the control format)

F Customer IF E K Disk
F Subfile  CF E Workstn

D NumRecords S 5 0
D SubfileRecNo S 5 0

C *Entry PLIST
C Eval SubfileRecNo = 1
C CallP LoadSubfile
C CallP DisplaySubfile
C *InLR Seton

C LoadSubfile Begsr
C Read Customer
C Dow Not %Eof(Customer)
C Eval SubfileRecNo += 1
C Write SFL001
C Read Customer
C Enddo
C Endsr

C DisplaySubfile Begsr
C Eval *In50 = *off // SFLCLR Indicator
C Write CTL001
C Eval *In50 = *on // SFLDSP/SFLDSPCTL Indicator
C Exfmt CTL001
C Endsr

Remember to replace Customer with your actual file name and adapt the field names accordingly. This example demonstrates the basic structure of a load-all subfile program.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>