Skip to main content

Problem:

When accessing Micro Focus files it is always good practice to check the file status returned after each I/O operation.

Resolution:

It is possible to create a general COBOL copybook that can be reused in all programs.  The following is an example of just such a copybook:

       01  (tag)-fstat.

           03  (tag)-fs-values.

               05  (tag)-fs-key1         pic x(1).

               05  (tag)-fs-key2         pic x(1).

               05  (tag)-fs-key2-bin   redefines

                   (tag)-fs-key2           pic 9(2) comp-x.

           03  (tag)-fs-error             redefines

               (tag)-fs-values            pic x(2).

      * -- File status codes.

       78  fs-no-error                    value "00".

       78  fs-duplicate-key            value "02".

       78  fs-file-not-found            value "05".

       78  fs-end-of-file                 value "10".

       78  fs-record-not-found      value "23".

The above copybook can be found attached to this knowledgebase article (FSTAT-WS.CPY).

To utilise the copybook we would add the following to your programs:

     select ... assign ...

          ...

          file status is file1-fstat.

     select ... assign ...

          ...

          file status is file2-fstat.

     working-storage section.

     copy "FSTAT-WS.CPY"

          replacing ==(tag)== by ==file1==.

     copy "FSTAT-WS.CPY"

          replacing ==(tag)== by ==file2==.

It is now possible to access the appropriate file status for each file in the program.  There are also some 78 (constants) values that can be used as part of the logic processing.

Attachments:

FSTAT-WS.CPY

Old KB# 1239