Browse Definitions :

Read all the records in the subfile 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 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** Check for a blank record
     C     FIELD1        IFNE      *BLANKS
     C** Perform logic
     C                   ENDIF
     C** Get ready to read the next record
     C                   ADD       1             @RRN
     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? member Blair Hamren has a quick and easy technique.
  • Display more than one subfile on the same screen
    A 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 members jumped in with suggestions.


Dig Deeper on Business Software

  • compliance risk

    Compliance risk is an organization's potential exposure to legal penalties, financial forfeiture and material loss, resulting ...

  • information governance

    Information governance is a holistic approach to managing corporate information by implementing processes, roles, controls and ...

  • enterprise document management (EDM)

    Enterprise document management (EDM) is a strategy for overseeing an organization's paper and electronic documents so they can be...

  • block cipher

    A block cipher is a method of encrypting data in blocks to produce ciphertext using a cryptographic key and algorithm.

  • hacker

    A hacker is an individual who uses computer, networking or other skills to overcome a technical problem.

  • Extensible Authentication Protocol (EAP)

    The Extensible Authentication Protocol (EAP) is a protocol for wireless networks that expands the authentication methods used by ...

  • risk mitigation

    Risk mitigation is a strategy to prepare for and lessen the effects of threats faced by a business.

  • call tree

    A call tree is a layered hierarchical communication model that is used to notify specific individuals of an event and coordinate ...

  • Disaster Recovery as a Service (DRaaS)

    Disaster recovery as a service (DRaaS) is the replication and hosting of physical or virtual servers by a third party to provide ...

  • cloud storage

    Cloud storage is a service model in which data is transmitted and stored on remote storage systems, where it is maintained, ...

  • cloud testing

    Cloud testing is the process of using the cloud computing resources of a third-party service provider to test software ...

  • storage virtualization

    Storage virtualization is the pooling of physical storage from multiple storage devices into what appears to be a single storage ...