Load All Subfile
Load All Subfile in IBM i: Decoding a Classic
Subfiles are a core concept in IBM i programming—built for showing multiple records on a screen fast. Load All Subfile is a workhorse type every coder should know. Welcome to Decoding Complexities. This post breaks down what Load All is, how it runs, and throws in a full free-format RPGLE example to prove it.
No nonsense—let’s get into the mechanics, quirks, and code.
Subfile Rundown
Subfiles in IBM i handle lists or tables on green screens—think RPG and DDS at their best. Three types dominate:
- Load All Subfile—dumps everything at once.
- Expandable Subfile—loads on demand (example here).
- Single Page Subfile—one page, no extras.
Message Subfiles show alerts—more here. Load All’s the focus today—simple, heavy, and worth decoding.
Load All Subfile: The Mechanics
Load All Subfile writes all records to the buffer upfront, then displays them. SFLSIZ (buffer size) needs to be SFLPAG (page size) + 1 or more. Push past SFLSIZ under 9999 records, and it stretches—maxes out at 9999.
PAGEUP and PAGEDOWN? System’s got it—keep SFLPAG less than SFLSIZ. One hitch: PAGEDOWN then ENTER jumps you to page one. Fix it with a file info data structure—grab the current RRN and set SFLRCDNBR in the DDS. Done right, it sticks where you want.
Example Output
Here’s what a Load All Subfile looks like, pulling records from a physical file:
TESTLODALL Test Load All Subfile 03/19/25 14:30:00 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
Eight records per page (SFLPAG=0008), buffer up to SFLSIZ=9999—clean and fast.
The Code
Physical File (TESTFILE)
A R TESTFR A TSFLD1 10A A TSFLD2 10A A TSFLD3 10A A TSFLD4 10A
Four 10-char fields—your data backbone.
Display File (TESTSUBFIL)
A*%%TS SD 20141010 053209 USERNAME REL-V6R1M0 5761-WDS A DSPSIZ(24 80 *DS3) A R SFDTAR SFL 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 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 Subfile' A COLOR(BLU) A CSRRRN 4S 0H SFLRCDNBR(CURSOR) A SFRRN 4S 0H A R SFFTRR A 23 3'F3=Exit F12=Cancel' A COLOR(BLU)
SFLSIZ=9999, SFLPAG=0008—big capacity, tight pages.
Full Free-Format RPGLE (TESTLODALL)
Full free-format RPGLE—modern take on the classic. Also at this link.
**FREE // Sample RPGLE Program for Load All Subfile (TESTLODALL) - Full Free Format // Define Physical File DCL-F TESTFILE DISK(*EXT) USAGE(*INPUT); // Define Subfile Display File DCL-F TESTSUBFIL WORKSTN SFILE(SFDTAR:SFRRN) USAGE(*INPUT:*OUTPUT); // Define Required Variables DCL-S CSRRRN ZONED(4:0); // Cursor RRN for SFLRCDNBR DCL-S SFRRN ZONED(4:0); // Subfile RRN DCL-S SFPGMNAM CHAR(10); // Program Name // Main Procedure /FREE ExSr Sub_Init; ExSr Sub_Main; ExSr Sub_Exit; *INLR = *ON; // End program /END-FREE // Sub_Init - First time initialization routine BEGSR Sub_Init; SFPGMNAM = 'TESTLODALL'; // Clear Subfile *IN25 = *OFF; // SFLDSP off *IN26 = *OFF; // SFLDSPCTL off *IN28 = *ON; // SFLCLR on WRITE SFCTLR; *IN28 = *OFF; // SFLCLR off *IN25 = *ON; // SFLDSP on *IN26 = *ON; // SFLDSPCTL on ENDSR; // Sub_Main - Main Processing Routine BEGSR Sub_Main; ExSr Sub_Load; DOU *IN03 = *ON OR *IN12 = *ON; // Loop until F3 or F12 CSRRRN = 17; // Set cursor to 3rd page (example) IF SFRRN = 0; *IN25 = *OFF; // Hide subfile if empty ENDIF; WRITE SFFTRR; EXFMT SFCTLR; ENDDO; ENDSR; // Sub_Load - Load Subfile BEGSR Sub_Load; SFRRN = 0; CSRRRN = 1; READ TESTFILE; DOW NOT %EOF(TESTFILE) AND SFRRN < 9999; SFRRN += 1; SFTSFLD1 = TSFLD1; SFTSFLD2 = TSFLD2; SFTSFLD3 = TSFLD3; SFTSFLD4 = TSFLD4; WRITE SFDTAR; READ TESTFILE; ENDDO; *IN40 = *ON; // SFLEND(*MORE) on ENDSR; // Sub_Exit - Finalization Routine BEGSR Sub_Exit; *INLR = *ON; // Ensure program ends ENDSR;
Loads all records, parks the cursor on page 3 (RRN 17)—solid IBM i stuff.
Wrapping Up
Load All Subfile’s a classic—loads records fast into a 9999 max buffer. Full free-format RPGLE above keeps it modern. More on Expandable Subfiles here. Got a subfile tweak? Comment below—let’s decode more IBM i tricks.
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