Skip to main content

Load All Subfile - Full Free Format RPGLE

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 ; 

Comments

  1. Hi PR, your code is showing last page of the subfile. How i can display first page of subfile.

    ReplyDelete
    Replies
    1. Hi Sandeep, Yes it does point to the last page as we are setting the CSRRRN to 17. See the below code and change CSRRRN to 1 to point to the first record.

      // 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 ;

      Delete
  2. Hi Can you please help for selection option
    suppose if i select any record by select option 1 it will go to next screen
    can you please help me

    ReplyDelete
    Replies
    1. Hi Durga,

      You could take a look at the below post (example for expandable sub file) which also has a piece of sample code for options processing as well. In brief you would be reading subfile record format using READC which would fetch the changed record, you would then need to check for the option and do the required operation.

      https://www.codewithpr.com/2020/08/expandable-subfile-example-program.html

      Please see if this is of any help, If not, you could consider sharing more specific details on what you are looking at, so that I would be able to advise you. You could either reply to this comment or reach out using the contact form.

      Thanks.

      Delete
  3. Hi Pradeep
    Iam doing load all subfile in that iam having selection option
    when selection I on one particular record it will go to the next screen
    that logic i want

    ReplyDelete
    Replies
    1. Hi Durga,

      I understand, logic for processing the option selection should be similar to the example link I have shared in the previous comment. I'm pasting the subroutine for your quick reference.

      // ------------------------------------------------------------------------
      // Process Subfile Options
      // ------------------------------------------------------------------------
      BegSr SrProcessOptions ;
      ReadC PPSFL01 ;
      Dow Not %Eof(TESTSUBFIL) ;
      If SOpt = '1' ;
      EXFMT ;
      EndIf ;
      ReadC PPSFL01 ;
      EndDo ;
      EndSr;

      This is a sample, you can try something similar, You can also try using SrValidateOptions which is intended for validating options before processing.

      Let me know if it doesn't help you.

      Thanks.

      Delete

Post a Comment

Popular posts from this blog

All about READ in RPGLE & Why we use it with SETLL/SETGT?

READ READ is one of the most used Opcodes in RPGLE. As the name suggests main purpose of this Opcode is to read a record from Database file. What are the different READ Opcodes? To list, Below are the five Opcodes.  READ - Read a Record READC - Read Next Changed Record READE - Read Equal Key Record READP - Read Prior Record READPE - Read Prior Equal Record We will see more about each of these later in this article. Before that, We will see a bit about SETLL/SETGT .  SETLL (Set Lower Limit) SETLL accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Corresponding Record (or Next Record if exact match isn't found).  SETGT (Set Greater Than) SETGT accepts Key Fields or Relative Record Number (RRN) as Search Arguments and positions the file at the Next Record (Greater Than the Key value). Syntax: SETLL SEARCH-ARGUMENTS/KEYFIELDS FILENAME SETGT  SEARCH-ARGUMENTS/KEYFIELDS FILENAME One of the below can be passed as Search Arguments. Key Fiel

What we need to know about CHAIN (RPGLE) & How is it different from READ?

CHAIN READ & CHAIN, These are one of the most used (& useful) Opcodes by any RPG developer. These Opcodes are used to read a record from file. So, What's the difference between CHAIN & READ?   CHAIN operation retrieves a record based on the Key specified. It's more like Retrieving Random record from a Database file based on the Key fields.  READ operation reads the record currently pointed to from a Database file. There are multiple Opcodes that start with READ and all are used to read a record but with slight difference. We will see more about different Opcodes and How they are different from each other (and CHAIN) in another article. Few differences to note.  CHAIN requires Key fields to read a record where as READ would read the record currently pointed to (SETLL or SETGT are used to point a Record).  If there are multiple records with the same Key data, CHAIN would return the same record every time. READE can be used to read all the records with the specified Ke

Extract a portion of a Date/Time/Timestamp in RPGLE - IBM i

%SUBDT Extracting Year, Month, Day, Hour, Minutes, Seconds or Milli seconds of a given Date/Time/Timestamp is required most of the times.  This can be extracted easily by using %SUBDT. BIF name looks more similar to %SUBST which is used to extract a portion of string by passing from and two positions of the original string. Instead, We would need to pass a value (i.e., Date, Time or Timestamp ) and Unit (i.e., *YEARS, *MONTHS, *DAYS, *HOURS, *MINUTES, *SECONDS or *MSECONDS) to %SUBDT.  Valid unit should be passed for the type of the value passed. Below are the valid values for each type. Date - *DAYS, *MONTHS, *YEARS Time - *HOURS, *MINUTES, *SECONDS Timestamp - *DAYS, *MONTHS, *YEARS, *HOURS, *MINUTES, *SECONDS, *MSECONDS Syntax: %SUBDT(value : unit { : digits { : decpos} }) Value and Unit are the mandatory arguments.  Digits and Decimal positions are optional and can only be used with *SECONDS for Timestamp. We can either pass the full form for the unit or use the short form. Below i