Subfile Coding in As400-Part1
Subfile is a display file where it can display physical file’s data and let users to manipulate the physical file’s data(similar to table which has data).
In this we will cover
- Subfile in simple words.
- Create a subfile.
- Create records of SFL and SFLCTL in subfile.
- Set indicators to handle subfile.
- Create RPGLE to handle user interactions with subfile.
- Call the subfile.
Example Subfile
In prior, we create a physical file with data just in purpose to display/manipulate data using subfile. We can also use array with data( ex: compile time array), or any data structure you name it.
Physical file named COUNTRY has STATE and CAPITAL column in it.
We can view physical file’s( table ) data.
using command: runqry () COUNTRY (or)
runqry *n COUNTRY
For user interaction we need a screen to display it and to let them manipulate.
Here I have attached the screen we are going to create.
Page down key in keyboard loads more data into the screen. Page up goes to the previous page.
Create a subfile
Prerequisite
Must read create library and create source physcical file.
Here by a quick walkthrough
Have a library with QDDSDSPF source physical file.
command: crtlib
Press enter to create a library named arc( user defined name ).
command: crtsrcpf
Press enter to create QDDSDSPF(source physical file) in library arc.
wrkmbrpdm into it.
Take F4=Prompt.
Enter to go into the source physical file arc/qddsdspf( library/source physical file).
Create a subfile
- Press F6=Create to create any file or program. Here we create a subfile
Source member denotes the subfile name, SUBFILE1.
Source type is the DSPF for subfile and also for display files. Press enter to create.
Type in FILE in Source Entry Utility. Enter to save.
Take Opt=17 to work in the subfile.
We end up entering into Display Records in the SUBFILE1.
We could see there are no records in the file SUBFILE1.
What is record?
In the display files and subfiles the records are the screens which are displayed to the user for interaction.
Record can hold variables, hardcoded values, display data from backend program(RPGLE) and handle user inputs.
Simply we can say that record is used to design the screen where user interacts with it
In subfile basically we have a structure to follow
In layman words, it can been seen as it has a header, body and footer similar to a word.
But in AS400 subfile,
Header, body and footer are created as seperate records(screens) and we use overlap keyword to display as a single screen.
So here,
SCREEN01 is the header.
SFL01 is the body.
SFLCTL01 is the footer.
SFL and SFLCTL works together
Why it should work together?
In the above image,
The section above the white line is Header- SCREEN01.
The section below the pink line is Footer- SFLCTL01( SFL Control).
Between the lines is the SFL which displays the data.
Data Definition and Control:
- SFL: Defines the structure and fields of the subfile records, determining what data will be displayed.
- SFLCTL: Controls the subfile’s overall behavior, such as the number of records, display attributes, and user interactions.
Synchronization:
- SFLCTL: Manages the interaction between the subfile and the display file. It handles functions like loading, clearing, and displaying subfile records.
- Without the SFLCTL, the subfile cannot be managed properly, leading to synchronization issues.
Screen Display Management:
- SFL: Specifies how each record looks.
- SFLCTL: Dictates when and how these records are shown on the screen, managing scrolling, page-up, and page-down functionalities.
Functional Cohesion:
- The subfile control format (SFLCTL) includes keywords that control the entire subfile (like SFLDSP and SFLEND), which need to be linked to the subfile (SFL) to function.
- Both parts must work together to provide a coherent user interface and proper data handling on the AS/400 system.
Lets now create SFL which here its named as SFL01, type as below and press Enter.
In Type mention as SFL and in new record its user defined name, its convention to start the name with sfl.
Press Enter. Now unlike like display file, here it asks for the subfile control file name, sfl is very hard to manage without sflctl( sfl control ) as it provides the important keywords.
After giving name and pressing enter it takes us to subfile keywords screen where we are about to set the indicators.
Handling Indicators
Press Enter. To set indicators in subfile control keywords.
Taking Yes on General keywords.
Basically sfldsp( indicator to control the sfl ), sflctl( indicator for subfile control ) and sflclr are used to create a simple subfile.
Related subfile record says which sfl belongs to the corresponding sflctl.
Display subfile records…SFLDSP — Give Y with 40 as indicator, This indicator controls whether the subfile records( data )are displayed on the screen.
Display control record…SFLDSPCTL — Give Y as 41 as indicator, This indicator controls whether the subfile control record is displayed. The subfile control information will be displayed.
Clear subfile record……SFLCLR — Give 42 as indicator, This indicator controls whether the subfile is cleared, We use subfile clear (SFLCLR) to remove all records from the subfile to prepare it for new data( Like for ever page down and page up from the buffer new data is loaded rather than existing one).
Press Enter. you head to below page.
(or)Taking Opt=8 on sflctl it directs to same page.
Taking Yes on subfile Display Layout.
SFLSIZ — subfile size says in buffer only 20 records are stored.
SFLPAG — subfile page says in the screen only 14 records are displayed, in page down next 14 is loaded and vice versa.
Press Enter to create it
Create the footer SCREEN01 as a normal display file’s record.
Press enter to enter into screen, you can see the blank screen as below
Design as same procedure we followed in display file blog.
In sflctl01 also set the F3 function same as in display file blog.
How? here come Quick bite😋
Shift + F2 — Y in select indicators
F3 — CA03
Below is SFL design.
SFL, SFLCTL and SCREEN01 should not overlap while designing else it throws error.
There are around 3 types of subfile regarding the loading data from buffer we will cover in next blog.
Now we are done designing the subfile. In next ones, we will code in rpgle for subfile to load the data from pf( physical file ) with debugging too..
Ending Note
I will follow up with rpgle coding for the subfile.
Stay happy and cheers❤
To stay updated with the blogs please follow Life@Twenty. It will really really make me to love my passion even more and more.