Page 1 of 1

Read a flat file and write alternate records into another fi

PostPosted: Wed Feb 04, 2015 6:32 pm
by sivareddy123
Read a file and write alternate (one after another) records in another file .Can you please provide me the logic in COBOL ?

Thanks in advance for your reply .

Re: Read a flat file and write alternate records into anothe

PostPosted: Wed Feb 04, 2015 7:48 pm
by BillyBoyo
I assume you're OK with reading a file.

Now you need to "flip a switch", which tells you when to write, and when not.

01  FILLER.
    05  FILLER                       PIC X.
          88  LAST-RECORD-WRITTEN    VALUE "Y".
          88  LAST-RECORD-NOT-WRITTEN
                                     VALUE "N".


After you successfully OPEN the output file:

    SET LAST-RECORD-NOT-WRITTEN TO TRUE


In your loop to read to end-of-file:

    IF LAST-RECORD-WRITTEN
        SET LAST-RECORD-NOT-WRITTEN
                                TO TRUE
    ELSE
        PERFORM                 WRITE-OUT-THE-INPUT
        SET LAST-RECORD-WRITTEN TO TRUE
    END-IF