Stack Exchange
COBOL outputting a blank file instead of expected output
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.

According to the description of sb14, either there is no space in the output PDS or there is no space in the Directory. Have a look at the output file, If it is a PDS, I would suggest compressing it. If you are using a PDS as output, it needs to be compressed regularly to reclaim unused space. See https://ibmmainframes.com/about23872.html

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

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.

Thank you man. I- I don't even know how I missed that. Thank you a ton.

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.
