BCS COBOL Sequential IO


COBOL programming is far from dead.  With the latest innovations and the addition of object-oriented COBOL the COBOL dialect can take its place among the industry leaders in software creation.

Here is an example of a COBOL mainline.

program-id. mprog as "mprog".
 
       environment division.
       configuration section.
 
       data division.
       working-storage section.
       01 rb pic x(80).
       01 fsw pic x.
 
       procedure division.
      *      perform 0010-create-records.
             perform 0020-8080-repo.
 
           goback.
 
       0010-create-records.
           call "IO01b".
           move "Rec One" to rb
           call "IO01d" using rb.
           move "Rec Two" to rb
           call "IO01d" using rb.
           move "Rec Three" to rb
           call "IO01d" using rb.
           move "Rec Four" to rb
           call "IO01d" using rb.
           move "Rec Five" to rb
           call "IO01d" using rb.
           call "IO01e".
 
       0020-8080-repo.
           call "IO01a" using fsw.
           call "IO02b".
           perform 0030-repro until fsw = "x".
           call "IO01e".
           call "IO02e".
 
       0030-repro.
           call "IO01c" using rb fsw;
           if fsw = ' '
               call "IO02d" using rb.
 
       end program mprog.

You may notice the mainline is comprised of perform and call statements. This approach emphasizes concise re usability of COBOL.

The first subroutine is listed below.

IDENTIFICATION DIVISION.
       PROGRAM-ID. "IO01".
       AUTHOR.  Arch Brooks.
      * Example program to show how to utilize PS IO
 
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT Seq-File ASSIGN TO "SEQ.DAT"
       		ORGANIZATION IS LINE SEQUENTIAL.
 
       DATA DIVISION.
       FILE SECTION.
       FD Seq-File.
       01 SeeqRec.
          05  filler  pic x(80).
 
       Linkage Section.
       01  buf-area pic x(80).
       01  eofsw pic x.
 
       PROCEDURE DIVISION.
 
       entry "IO01a" using eofsw.
           open input Seq-File.
           move " " to eofsw.
           goback.
 
       entry "IO01b".
           open output Seq-File.
           goback.
 
       entry "IO01c" using buf-area eofsw.
           read Seq-File into buf-area at end move "x" to eofsw.
           goback.
 
       entry "IO01d" using buf-area.
           Write SeeqRec from Buf-Area.
           goback.
 
       entry "IO01e".
           close Seq-File.
           goback.

The final subroutine is listed below.

IDENTIFICATION DIVISION.
       PROGRAM-ID. "IO02".
       AUTHOR.  Arch Brooks.
      * Example program to show how to utilize PS IO
 
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT Seq-File ASSIGN TO "RAT.DAT"
       		ORGANIZATION IS LINE SEQUENTIAL.
 
       DATA DIVISION.
       FILE SECTION.
       FD Seq-File.
       01 SeeqRec.
          05  filler  pic x(80).
 
       Linkage Section.
       01  buf-area pic x(80).
       01  eofsw pic x.
 
       PROCEDURE DIVISION.
 
       entry "IO02a" using eofsw.
           open input Seq-File.
           move " " to eofsw.
           goback.
 
       entry "IO02b".
           open output Seq-File.
           goback.
 
       entry "IO02c" using buf-area eofsw.
           read Seq-File into buf-area at end move "x" to eofsw.
           goback.
 
       entry "IO02d" using buf-area.
           Write SeeqRec from Buf-Area.
           goback.
 
       entry "IO02e".
           close Seq-File.
           goback.

Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

Leave a Reply