AS/400 Chapter 9: Subfiles
With subfiles you can create a display file with lists of items. Let's see how that's done.
Previous chapter: AS/400 Chapter 8: Display Files
A subfile is a display file where you can place a listing of values and process changes on the list. The list of members that you can see in the PDM is an example of a subfile.
In this chapter we'll create a subfile wich will show all the cards from a client given its ID. To make the manipulation of several tables easier, we'll create a view with the fields we'll use on the subfile. In STRSQL insert this code:
CREATE VIEW CLICARD AS SELECT CL.ID_CLI, CR.ID_CRD, SH.NAME_SHP, CR.SHOP_CRD FROM DEMO/CLIENTS CL, DEMO/SHOP SH, DEMO/CARDS CR WHERE CL.ID_CLI = CR.CLIENT_CRD AND CR.SHOP_CRD = SH.ID_SHP
Open SDA (STRSDA) and create a new member:

Create a BOTTOM record that should look like this:

And the TOP record like this:

Let's create the subfile now. Create a new record, name it LIST, the record type is SFL:

When you press Enter a new record appears. Write SFLCTL on it:

This field creates a subfile control record, wich works like the heading on the list.
You have to activate some options now:

On the General Keywords menu insert the data you see below:

These indicators allow us to manipulate the status of the subfile from the RPG code. Press Enter to go back to the previous screen. Select Subfile display layout.

On subfile maximum size type 9999 and on the number of records for page type 9:

Press enter to go back. Select the option Select Record Keyword:

Choose Overlay keywords:

Select Overlay without erasing:

Press Enter until you're back on this screen:

Open the SFLCTL record. By default the record list is already visible on the design screen. Select to visualize the other 2 records, TOM and BOTTOM (F9).

Back to the design screen, write at the top “Client Nr.”. Select the fields from CLICARD view for input/output (F10) and select the ID_CLI field:

Type the titles of the subfile's columns and a separating line:

Let's add some proprieties to the Client ID field. Place an * before to the left of the field.

We're going to add an indicator to this field, wich will be activated when no record is found for an ID inserted (either the ID doesn't exist or it doesn't have any associated cards). Option Error Messages:

Insert the following information:

Close this record and open the LIST record. Select the TOP and BOTTOM records for display (F9):

To create an input field, where the user will type the options, type '+i' on the same position as in the following image and press Enter.

Notice how the field spread across the 9 line you previously defined as the subfile page size.

Select the records from CLICARD view for output.

The fields will probably be listed twice, because the SDA will show you the field that had been previously loaded from I/O in the SFLCTL record. You should select the fields further to the right, because they are the last ones loaded. You must be careful selecting the fields.
If there are more fields than the ones that can fit the message line, a plus (+) sign will appear at the end of the line. Press Page Down to see the remaining fields.

Place the fields on their positions:

The final result:

Don't forget to activate the indicator 03 at file-level so that “F3=Exit” can work and add the keyword INDARA to the code. Check out the Display file chapter if you don't remember how to do this.
You must add the red line to the SFLCTL record:
A R SFLCTL SFLCTL(LIST)
A SFLSIZ(9999)
A SFLPAG(0009)
A OVERLAY
A 30 SFLDSP
A 31 SFLDSPCTL
A 35 SFLCLR
A 33 SFLEND(*MORE)
A 4 8'Client Nr.'
A ID_CLI R B 4 19REFFLD(CLICARD/ID_CLI DEMO/CLICARD)
A 90 ERRMSG('No Data Found')
A 6 4'Op.'
A 6 12'Card Nr.'
A 6 27'Shop Nr.'
A 6 42'Shop Name'
A 7 2'__________________________________-
A ___________________________________-
A __________'
A RRN 4S 0H SFLRCDNBR(CURSOR)
In the LIST record change the name of the input field to OPTION. By default it must be named FLD001, or something like it.
A R LIST SFL A OPTION 1A I 9 5 (...)
Executing the subfile
To run the subfile you must create an RPGLE member. Check out the file QRPGLESRC.SHW_SFL for more details on how to write this member.
When you run the RPGLE code:

And so we finish this series on AS/400.
Previous chapter: AS/400 Chapter 8: Display Files
Comments
20:52 29-12-2008grajek
Exactly what I needed! Good job!15:24 30-12-2008Sumit
Simply Great for the Begginers to learn.Excellent!!!12:32 07-01-2009Naveen
Its Brilliant site to learn Things..14:35 27-01-2009ASHISH
Its really easy and effictive way to explain.23:12 03-02-2009krish
Good One11:00 06-03-2009Ezhil
Too Good.It was really very useful09:54 16-03-2009Nilmi
It's very effective.Good job23:52 25-03-2009Fcoppi
how can I display the "select additional records for display" menù ?thank...The rest is perfect....
06:02 01-04-2009Ricki
It is too good for beginners.Very useful & effective.22:07 05-04-2009MARTIAL_KOUASSI
THIS SITE IS REALLY UNDERSTANDABLE AND SHOULD BE ADVISED TO ALL BEGINERS.THAT'S GREAT!!!!
09:53 14-04-2009sHAVETA
rEALLY GOOD :) EXACTLY WHAT I NEEDED TO START WITH SUBFILES..12:20 06-05-2009TANMOY
SIMPLY BEST!!!!!!!!!15:56 13-05-2009Glenn
Very good article!!!!!Many thanks to the author!!!!
05:21 16-05-2009ragav
Very useful..,Can you please add the rpg code to fetch records.. based on the Client nr field
07:56 01-06-2009Kajal
Really useful one!!11:24 09-07-2009Prabhu
Could you please include RPG code for this16:47 22-07-2009FazalAhmed
Thank you very very very much for your great support. Its very precise intro to the world of AS400.17:07 06-08-2009orgeandeAyahoofr
Many thanks, master! So much time saved.12:00 25-08-2009Madhavi
Very helpful for someone new.Thanks a lot.12:01 28-08-2009Prem
This site reduces the need of a tutor. Explains each concepts in a understanding way for the begineers.Thanks a lot for the creativity of the creators.
I will definitely recommend this site for my friends.
11:35 25-09-2009Nityanand
Awosme!!!! really good one15:15 15-10-2009thupten
thanks a lot. very useful information in organised order.now i feel comfortable with the green scren.19:11 18-10-2009rajuvinay
best guidance for beginer's..21:08 27-10-2009Drew
*On general keywords, for SFLDSP, SFLDSPCTL, and SFLCLR I've found this works better:SFLDSP 30
SFLDSPCTL 31
SFLCLR N30N31
In the RPG program, you set off 30 & 31 and write the control record. Set on 31, and set 31 with the statement
eval *in31 = RRN > 0
(assuming RRN is the record number variable defined for the subfile)
That way you don't waste a 3rd indicator.
*Subfile Max Size should be Subfile Page +1. The system will automatically grow it if necessary.



08:42 29-10-2008Kiran
Good way to explain things dude!!