Programming - Everything You Wanted To Know About Subfiles But Were Afraid To Ask

About Programming - Everything You Wanted To Know About Subfiles But Were Afraid To Ask

Let's talk about SUBFILE programming in RPG.

If you have grown up through the world of AS400 a few decades ago, or through the wonderful ISERIES machines of the early 2000's then you *maybe* are using the current IBM i POWER SYSTEMS that replaced those old boxes.

If that's the case, in most places you are using subfiles to display information on those smelly old green screen terminals. Writing a SUBFILE PROGRAM means knowing how to code them, ranging from simple full load, to expanding, to page at a time. Each type of Subfile has different programming styles... so let's dive in and have a play with SUBFILES in RPG Programming.

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

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

Let's talk about SUBFILE programming in RPG. If you have grown up through the world of AS400 a few decades ago, or through the wonderful ISERIES machines of the early 2000's then you *maybe* are using the current IBM i POWER SYSTEMS that replaced those old boxes. If that's the case, in most places you are using subfiles to display information on those smelly old green screen terminals. Writing a SUBFILE PROGRAM means knowing how to code them, ranging from simple full load, to expanding, to page at a time. Each type of Subfile has different programming styles... so let's dive in and have a play with SUBFILES in RPG Programming. 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 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.

Stepping into the world of Subfiles

MEMBERS ONLY

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. Expanding Page Subfile: Loads a page each time the PAGEDOWN key is pressed. 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.

Load All RPGLE Subfile

MEMBERS ONLY

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.

A Strangers (Dodgy) Sample Subfile Program

MEMBERS ONLY

Come with me while we step through the code, discuss what it's doing and why it's doing it. Then we can compile it. Fix any problems we find along the way and finally... hopefully... end up with a working program.

Introduction to a Simple RPG Subfile So, I found an old RPGLE Subfile example on a website that is top of the search engine list. This means it's been visited and downloaded thousands of times. But does that mean it's anygood? Don't waste time trying yourself - watch me do it for you :)

RPG Subfile DSPF - A Quick Look at the data description specifications (DDS)

RPG Subfile - Review the RPG program source code - Part 1 COPYBOOK

RPG Subfile - Review the RPG program source code - Part 2 RPG BODY

RPG Subfile - Making this dodgy program compile!

RPG Subfile - Test the RPG program and see what it does

Now that we've walked through this RPGLE subfile example, and have a working version, we have to ask ourselves - IS THIS A GOOD EXAMPLE? If YES - then what is good about it? If NO - then what is bad? What do we hate? What do we tolerate? What can we improve? If ***** (that is a swear word) then what kind of subfile example would I write? *SPOILER ALERT* This subfile code example is NOT LITTEN APPROVED. Be prepared for some Bawdy Anglo-Saxon Expletives

Expanding Size RPGLE Subfile

MEMBERS ONLY

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.

Single Page RPGLE Subfile

MEMBERS ONLY

A single page subfile is a SCREEN OF DISPLAYED DATA, loaded one page at a time. The displayed data is equal to the maximum number of records that 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 the subfile size equaling the page size. 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 PAGEUP/PAGEDOWN activities are handled by the program

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