Read a flat file and write alternate records into another fi



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Read a flat file and write alternate records into another fi

Postby sivareddy123 » Wed Feb 04, 2015 6:32 pm

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 .
sivareddy123
 
Posts: 3
Joined: Wed Feb 04, 2015 6:23 pm
Has thanked: 0 time
Been thanked: 0 time

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

Postby BillyBoyo » Wed Feb 04, 2015 7:48 pm

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
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post