COBOL outputting a blank file instead of expected output

Viewed 334

Hey guys I've been scratching my head over this all day to no avail. I'm running a COBOl program that should take input from one file and output it to another if it meets some conditions. This is the PROCEDURE DIVISION.

 PROCEDURE DIVISION.
      *
       A000-START.
           OPEN INPUT CUST-RECS.
           OPEN OUTPUT ACCT-RPT.
           PERFORM A000-WRITE-FIRST.
           PERFORM READ-NEXT-RECORD.
      *    PERFORM WRITE-RECORD.
           CLOSE ACCT-RPT.
           CLOSE CUST-RECS.
           STOP RUN.
      *
       A000-WRITE-FIRST.
           DISPLAY "WRITE-FIRST".
           MOVE 2 TO REC-COUNT.
           WRITE PRT-REP-DONE FROM HEADER-1.
           WRITE PRT-REP-DONE FROM HEADER-2.
           WRITE PRT-REP-DONE FROM HEADER-3.
           WRITE PRT-REP-DONE FROM HEADER-4.
      *
       READ-NEXT-RECORD.
           PERFORM READ-RECORD
              PERFORM UNTIL LASTREC = 'Y'
              PERFORM WRITE-RECORD
              PERFORM READ-RECORD
              END-PERFORM.
      *
       WRITE-RECORD.
           DISPLAY "WRITE-RECORD called" FIRST-NAME.
           MOVE SPACES TO PRT-REP-DONE.
           MOVE REC-COUNT TO PRT-RECS.
           MOVE FIRST-NAME TO PRT-NAME-FST.
           MOVE LAST-NAME TO PRT-NAME-LST.
           MOVE BALANCE TO PRT-BALANCE.
           WRITE PRT-REP-DONE.
           CLOSE ACCT-RPT.
       
       READ-RECORD.
           READ CUST-RECS
           AT END MOVE 'Y' TO LASTREC

           IF (FUNCTION NUMVAL-C(BALANCE) IS > 8500000)
              THEN
                 DISPLAY "BALANCE: " BALANCE
                 ADD 1 TO REC-COUNT
                 PERFORM WRITE-RECORD
           END-IF
           END-READ.

In my output file I just get 1 blank line. And a ABEND code of SB14. I was able to get some output before but now nothing.

2 Answers

SB14 is an issue with close. SB14 can be found here This abend indicates there is the accompanying messace IEC217I

enter image description here

With regard to the code, it looks like you're closing the output file ACCT-RPT WRITE-RECORD which is probably your output file.

   WRITE-RECORD.
       DISPLAY "WRITE-RECORD called" FIRST-NAME.
       MOVE SPACES TO PRT-REP-DONE.
       MOVE REC-COUNT TO PRT-RECS.
       MOVE FIRST-NAME TO PRT-NAME-FST.
       MOVE LAST-NAME TO PRT-NAME-LST.
       MOVE BALANCE TO PRT-BALANCE.
       WRITE PRT-REP-DONE.
       CLOSE ACCT-RPT.

My guess is its whining about closing the file twice.

I'm no COBOL man, but your code looks very incorrect to me. WRITE-RECORD is called from READ-NEXT-RECORD, as well as from READ-RECORD. But that is not the main problem.

The reason there is only one record in the output is the CLOSE ACCT-RPT in WRITE-RECORD. Closing and reopening a dataset will overwrite previous content every time the data set is reopened (unless you have DISP=MOD on the DD statement).

You seem to be writing to a PDS member, and all the closing and reopening finally uses all the space which leads to the B14 ABEND.

Rethink your logic.

Related