Introduction to RPG Subfiles for AS400, iSeries and IBM i Power Systems

About Introduction to RPG Subfiles for AS400, iSeries and IBM i Power Systems

What is a subfile? A programming technique to display data on the screen in a multi-page format.
What types of subfile? We can code full load, expanding and single page subfiles
How can I do that? Easily ;)

Come with me while we look at all the different types of subfiles and go through some RPG and SQL RPG examples from cradle to grave. All modules will look at a range of subfiles from brand new simple examples to modifying someone elses code.

Module Content

What is a subfile? A programming technique to display data on the screen in a multi-page format. What types of subfile? We can code full load, expanding and single page subfiles How can I do that? Easily ;) Come with me while we look at all the different types of subfiles and go through some RPG and SQL RPG examples from cradle to grave. All modules will look at a range of subfiles from brand new simple examples to modifying someone elses code.

Video lesson

Let's look at the basics of a subfile and how it works. An IBM i subfile has the same setup as previous generations of AS/400 and iSeries. A subfile is a powerful feature that allows you to display and manage multiple records on a single screen. Let me break it down for you: Purpose of Subfiles: Subfiles are used to present a list of values or records to the user. They allow you to handle multiple records of the same type on a display screen. You can perform actions like scrolling through the list, selecting items, and making changes. How Subfiles Work: A subfile is defined in a display file (DSPF). The records displayed in the subfile are read from a database file through a program. The program writes the records to the device file, which is then displayed on the subfile screen. Types of Subfiles: Load All Subfile: Loads the entire subfile at once. Suitable for smaller datasets. Page at a Time Subfile: Loads one page of records at a time. More efficient for larger datasets.

What are the SFL (Subfile) Indicators and how do they work? SFL | SFLDSP | SFLDSPTCTL | SFLCLR

Time to play with a simple **load-all subfile** in RPG for the IBM i Power System). 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. Note that you'll need to adapt this code to your specific requirements and file structures: ```rpg FCustomer IF E K Disk FSubfile CF E Workstn FControl CF E Workstn D CustList S 10A Dim(100) 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 CustList(SubfileRecNo) = CustName C Eval SubfileRecNo += 1 C Read Customer C Enddo C Eval NumRecords = SubfileRecNo - 1 C Return C Endsr C DisplaySubfile Begsr C Eval *In50 = *On // Display indicator C Write Control C Eval *In50 = *Off // Clear indicator C Return 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. Feel free to modify and enhance this code to suit your specific needs.

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