Subfile:
Subfile is one of the most used concept in IBM i.
There are three different types of Subfiles.
- Load All Sub File
- Expandable Sub File (Click Here to see more about Expandable Subfile with an Example)
- Single Page Subfile
Message Subfiles are used to display the messages on the screen. Click Here to see more about Message Subfiles.
We will see about Load All Subfile in this post. Click Here for Full Free Format RPGLE code for this example.
Load All Subfile:
In Load-All subfile all the records are written to the subfile buffer at once and then the data in the subfile loaded from the buffer.
In this case SFLSIZ should be at-least 1 greater than the SFLPAG.
If we are writing more records in the subfile buffer than the SFLSIZ declared and SFLSIZ<9999, then the SFLSIZ is extended to accommodate all records till the size of 9999. 9999 is the buffer limit.
In this case PAGEUP AND PAGEDOWN is taken care by system. SFLPAG should be less than SFLSIZ.
In load-All subfile if we do PAGEDOWN and then press ENTER on the page, by-default ENTER bring the display screen to the very first page irrespective of the current page number. To avoid this situation, we use file information data structure to get the current page RRN number and pass it to the SFLRCDNBR hidden field defined in the display file DDS.
Example:
Sample program below will load records from Physical file to Load all subfile. Output will be shown as below.Output:
TESTLODALL Test Load All Subfile 10/09/14
05:49:47
Display Records for Load All Subfile
Test Field1 Test Field2 Test Field3 Test Field4
----------- ----------- ----------- -----------
TESTREC17 TESTREC17 TESTREC17 TESTREC17
TESTREC18 TESTREC18 TESTREC18 TESTREC18
TESTREC19 TESTREC19 TESTREC19 TESTREC19
TESTREC20 TESTREC20 TESTREC20 TESTREC20
TESTREC21 TESTREC21 TESTREC21 TESTREC21
TESTREC22 TESTREC22 TESTREC22 TESTREC22
TESTREC23 TESTREC23 TESTREC23 TESTREC23
TESTREC24 TESTREC24 TESTREC24 TESTREC24
More...
F3=Exit F12=Cancel
Sample Code for Physical File (TESTFILE)
A R TESTFR
A TSFLD1 10A
A TSFLD2 10A
A TSFLD3 10A
A TSFLD4 10A
Sample Code for Display File (TESTSUBFIL)
A*%%TS SD 20141010 053209 USERNAME REL-V6R1M0 5761-WDS
A*%%EC
A DSPSIZ(24 80 *DS3)
A R SFDTAR SFL
A*%%TS SD 20141010 053209 USERNAME REL-V6R1M0 5761-WDS
A 70 SFLNXTCHG
A SFTSFLD1 10A O 10 3
A SFTSFLD2 10A O 10 21
A SFTSFLD3 10A O 10 38
A SFTSFLD4 10A O 10 57
A R SFCTLR SFLCTL(SFDTAR)
A*%%TS SD 20141010 053209 USERNAME REL-V6R1M0 5761-WDS
A CA03(03)
A CF12(12)
A PAGEDOWN(50)
A PAGEUP(51)
A OVERLAY
A 25 SFLDSP
A 26 SFLDSPCTL
A 27 SFLINZ
A 28 SFLCLR
A 40 SFLEND(*MORE)
A SFLSIZ(9999)
A SFLPAG(0008)
A 1 27'Test Load All Subfile'
A COLOR(WHT)
A 1 73DATE
A EDTCDE(Y)
A COLOR(BLU)
A 2 73TIME
A COLOR(BLU)
A SFPGMNAM 10A O 1 2
A 7 3'Test Field1'
A 7 21'Test Field2'
A 7 38'Test Field3'
A 7 57'Test Field4'
A 8 3'-----------'
A 8 21'-----------'
A 8 38'-----------'
A 8 57'-----------'
A 5 4'Display Records for Load All Subfi-
A le'
A COLOR(BLU)
A CSRRRN 4S 0H SFLRCDNBR(CURSOR)
A SFRRN 4S 0H
A R SFFTRR
A*%%TS SD 20141010 024314 USERNAME REL-V6R1M0 5761-WDS
A 23 3'F3=Exit F12=Cancel'
A COLOR(BLU)
Sample RPGLE Program for Loadall Subfile (TESTLODALL): Click Here for Full Free Format RPGLE code for this example.
// Define Physical File
FTESTFILE IF E DISK
// Define Subfile
FTESTSUBFILCF E WORKSTN SFILE(SFDTAR:SFRRN)
**********************************************************************
// Define Required Variables
**********************************************************************
C ExSr Sub_Init
C ExSr Sub_Main
C ExSr Sub_Exit
**********************************************************************
// Sub_Init - First time initialization routine
**********************************************************************
C Sub_Init BegSr
C Eval SFPGMNAM = 'TESTLODALL'
// Clear Subfile
C Eval *In25 = *Off
C Eval *In26 = *Off
C Eval *In28 = *On
C Write SFCTLR
C Eval *In28 = *Off
C Eval *In25 = *On
C Eval *In26 = *On
C EndSr
**********************************************************************
// Sub_Main - Main Processing Routine
**********************************************************************
C Sub_Main BegSr
C ExSr Sub_Load
C Dow *In03 = *Off
C And *In03 = *Off
// If You Need Cursor to be Pointed on Specific Record,
// You can move corresponding RRN to CSRRR field. In this
// example I am placing Cursor on 3rd Page.
C Eval CSRRRN = 17
C If SFRRN = 0
C Eval *In25 = *Off
C EndIf
C Write SFFTRR
C Exfmt SFCTLR
C EndDo
C EndSr
**********************************************************************
// Sub_Load - Load Subfile
**********************************************************************
C Sub_Load BegSr
C Eval SFRRN = 0
C Eval CSRRRN = 1
C Read TESTFILE
C Dow Not %Eof(TESTFILE)
C And SFRRN < 9999
C Eval SFRRN = SFRRN + 1
C Eval SFTSFLD1 = TSFLD1
C Eval SFTSFLD2 = TSFLD2
C Eval SFTSFLD3 = TSFLD3
C Eval SFTSFLD4 = TSFLD4
C Write SFDTAR
C Read TESTFILE
C EndDo
C Eval *In40 = *On
C EndSr
**********************************************************************
// Sub_Exit - Finalization Routine
**********************************************************************
C Sub_Exit BegSr
C Eval *InLr = *On
C EndSr
VERY GOOD EXEMPLE !! thanks !!
ReplyDeleteThanks Chris. Copy of the RPG code in full free format RPG is here if you are interested.
Deletehttp://www.ibmiupdates.com/2020/05/load-all-subfile-full-free-format-rpg.html