Problem solve Get help with specific problems with your technologies, process and projects.

Read all the records in the subfile

Search400.com expert John Kohan shows you how to read the subfile by employing the "CHAIN" opcode using the RRN.

Most of us develop subfiles on a regular basis, and yet they seem to give us the most trouble. Recently a Search400.com member had an issue. He wrote:

"I am creating a program with a data entry subfile that contains four fields. As the program reads each record, if there is an error the subfile gets redisplayed with the error highlighted. When I correct the record and press enter, the READC opcode reads from the next RRN where I corrected the problem, when I do the verification process and the subsequent write to the master file. I want it to start at the top of the subfile beginning with RRN 1."

Remember that a subfile can be read much like a physical file. A subfile does not have a key structure, so you can read it using the RRN (Relative Record Number). See the sample below.

     C                   Z-ADD     1             @RRN              3 0
     C     *IN50         DOUEQ*ON
     C     @RRN          CHAIN     SUBFILE                            50
     C     IN50          IFEQ OFF
     C*
     C** Check for a blank record
     C*
     C     FIELD1        IFNE      *BLANKS
     C*
     C** Perform logic
     C*
     C                   ENDIF
     C*
     C** Get ready to read the next record
     C*
     C                   ADD       1             @RRN
     C*
     C                   ENDIF
     C                   ENDDO

You can read the subfile by using the "CHAIN" opcode using the RRN. You can go into a standard "DO" loop reading the records in the subfile until you are done. Using this technique you will stop reading records when you reach the end of the subfile.

Be careful with expanded subfiles. This will read only the records that are currently loaded in the subfile. If you need to read records that were loaded due to a page down key after you chained to the subfile, you will need to process those records later.

Personally, I have found this technique much easier than using subfile keywords. The code is simple and easy to maintain.

-----------------------------------------
About the author: John Kohan is a senior programmer analyst at CT Codeworks.

More on this topic

  • Subfile 'More...' made easy
    Want to get a subfile to display "More..." or "Bottom" automatically? Search400.com member Blair Hamren has a quick and easy technique.
  • Display more than one subfile on the same screen
    A Search400.com member asked, "How can I display more than one subfile on the same screen horizontally?" Site expert John Brandt has a method that works for him each time.
  • Retrieve the top record for each subfile
    Problem: "I am writing a screen program where two subfiles are shown on the screen at the same time. I would like to retrieve the top subfile record for each subfile. I can get the lowest subfile record displayed for the subfile on the top part of the screen using the INFDS. I'm unable to get the lowest subfile record displayed for the subfile on the bottom part of the screen. Any suggestions?"

    Answer: Site expert John Brandt has an idea that involves DDS Keywords SFLRCDNBR(CURSOR *TOP) and SFLSCROLL.
  • Overlay functions on top of subfile
    "Gesbos1" has a subfile that he's designing in SDA, and he wants to include commands such as F3=Exit F6=Update F12=Cancel at the bottom of the subfile. How can he do this? Several Search400.com members jumped in with suggestions.

 

Dig Deeper on iSeries CL programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close