Load All Subfile - Full Free Format RPGLE

Pradeep Panga · May 1, 2020 · 1 min read

Load All Subfile in Full Free Format RPGLE

Earlier in my post I shared a simple Load All Subfile in RPGLE. Click Here for this post and for more details on Subfile.In this post, we will use the same Example using Full Free Format RPGLE.Refer this link for the Sample Physical file and Display File used in this Article.Below is the Sample RPGLE code for Load All Subfile.
**Free
  // Define Physical File
  Dcl-F TESTFILE ;
  // Define Subfile
  Dcl-F TESTSUBFIL WORKSTN SFILE(SFDTAR:SFRRN) ;

  // Define Required Variables

  // Main Process
  ExSr Sub_Init ;
  ExSr Sub_Main ;
  ExSr Sub_Exit ;

  // Sub_Init - First time initialization routine
  BegSr Sub_Init ;
    SFPGMNAM = 'TESTLODALL'
    // Clear Subfile
    *In25 = *Off ;
    *In26 = *Off ;
    *In28 = *On ;
    Write SFCTLR ;
    *In28 = *Off ;
    *In25 = *On ;
    *In26 = *On ;
   EndSr ;

   // Sub_Main - Main Processing Routine
   BegSr Sub_Main ;

     ExSr Sub_Load ;

     Dow *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.
       CSRRRN = 17 ;
       If SFRRN = 0 ;
         *In25 = *Off ;
       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 = SFRRN + 1 ;
       SFTSFLD1 = TSFLD1 ;
       SFTSFLD2 = TSFLD2 ;
       SFTSFLD3 = TSFLD3 ;
       SFTSFLD4 = TSFLD4 ;
       Write SFDTAR ;
       Read TESTFILE ;
     EndDo ;
     *In40 = *On ;

   EndSr ;

   // Sub_Exit - Finalization Routine
   BegSr Sub_Exit ;

     *InLr = *On ;

   EndSr ;

Keep reading

More from IBM i →