Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declaratives

Status
Not open for further replies.

crackerjack109

Programmer
Jun 27, 2002
7
US
Can someone provide an example of using the declarative statement to track down bad data problems? I have a program that uses many, many input files and I would like a rtn that would at a minimum tell me which file had the problem.

I hope this is clear enough for someone to comment on.

Thanks

Crackerjack109
 
Each file-control entry can include a FILE STATUS clause that designates a 2-character file-status data item declared elsewhere in the program as the receptacle for that file’s I-O status code. The leftmost character position of the file-status data item is Status
Key 1. The rightmost character position of the file-status data item is Status Key 2.

Whenever a program executes a CLOSE, DELETE, LOCKFILE, OPEN, READ, REWRITE, START, UNLOCKFILE, UNLOCKRECORD, or WRITE statement for a file that has a FILE STATUS clause, the COBOL run-time routines record the I-O status code in the specified file-status data item. The storage operation occurs prior to the execution of any applicable USE procedure or any applicable imperative statement
associated with the input-output statement (in AT END, NOT AT END, INVALID KEY, or NOT INVALID KEY phrases).

The I-O status code indicates the success or failure of the input-output statement, and (if failure), the reason for the failure. Check your COBOL manual for the meanings of each Status Key value.

Example:
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT IN-FILE-1
ASSIGN TO “NAMEFILE1"
FILE STATUS IS FILE-STATUS.
SELECT IN-FILE-2
ASSIGN TO “NAMEFILE2"
FILE STATUS IS FILE-STATUS.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 FILE-STATUS PIC X(02).
88 NO-ERRORS VALUE “00”.
88 END-OF-FILE VALUE “10”.
ETC…

PROCEDURE DIVISION.
DECLARATIVES.
IN-FILE-1 SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON IN-FILE-1.
PARA-1.
IF NOT END-OF-FILE
SET FILE-1-ERROR TO TRUE
END-IF.
IN-FILE-2 SECTION.
USE AFTER STANDARD ERROR PROCEDURE ON IN-FILE-2.
PARA-2.
IF NOT END-OF-FILE
SET FILE-2-ERROR TO TRUE
END-IF.

...
END DECLARATIVES.

 
Thanks for the quick response. I have use the file-status codes before but never with the declaratives section.

The main thing I am trying to find out in using the declaratives section is a way to avoid coding the 'USE AFTER STANDARD ERROR PROCEDURE ON file-name' for each file I am using. This project uses over 60 input files and I would like to come up with something a little more condensed and efficient. Any ideas? And thanks again.

Crackerjack109
 
Change the use phrase to catch any file:
USE AFTER STANDARD ERROR PROCEDURE ON I-O.

 
Actually
Code:
USE AFTER STANDARD ERROR PROCEDURE ON I-O
will execute only on errors that occur on files open (or in the process of being opened) in I-O mode.

There is also:
Code:
USE AFTER STANDARD ERROR PROCEDURE ON INPUT
USE AFTER STANDARD ERROR PROCEDURE ON OUTPUT
USE AFTER STANDARD ERROR PROCEDURE ON EXTEND
for files open, or being opened, in those modes.

One other technique would be to define all you error codes in a group as follows:
Code:
01  my-file-error-codes  value all "00".
    02  file-1-error-code   pic XX.    
    02  file-2-error-code   pic XX.
    02  file-3-error-code   pic XX.
...
    02  file-60-error-code   pic XX.
01  redefines my-file-error-codes.
    02  file-error-code pic XX occurs 60 
                        indexed by ERROR-INX.
        88  file-status-okay value "00".
This would allow one common routine to scan all the file status codes to quickly determine the culprit.

Of course, each section in the DELARATIVES may just PERFORM a common error handling procedure if that fits your needs. So you could have:
Code:
INPUT-ERROR SECTION
    USE AFTER STANDARD ERROR PROCEDURE ON INPUT.
A.  PERFORM VARYING ERROR-INX FROM 1 BY 1
              UNTIL ERROR-INX > 60
        IF FILE-STATUS-OKAY (ERROR-INX)
            CONTINUE
        ELSE
            <handle the error here>
        END-IF
    END-PERFORM.

I-O-ERROR SECTION
    USE AFTER STANDARD ERROR PROCEDURE ON I-O.
A.  PERFORM INPUT-ERROR.

OUTPUT-ERROR SECTION
    USE AFTER STANDARD ERROR PROCEDURE ON OUTPUT.
A.  PERFORM INPUT-ERROR.
I would expect your production code to be a bit more complex, and also a bit more rugged (using 78 levels instead of hard coding OCCURS values, for example).
Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top