Skip alternate records

I have a seq file with 1000 records and I need to skip alternate records and write into a output file using cobol How can I do it

Showing Answers 1 - 15 of 15 Answers

wanilkumar

  • Oct 6th, 2011
 

very simple. Just define a boolean switch in your working storage and keep flipping the switch after every time you write the output record and make sure to verify the switch before you write the record.

  Was this answer useful?  Yes

Santu

  • Nov 10th, 2011
 

use 2 read and 1 write statements in the loop

  Was this answer useful?  Yes

Use Counter

Code
  1. Read input file

  2.  If not End-of-file

  3.   Add 1 to ws-counter

  4.   If ws-counter = 2

  5.      write record to output file

  6.      move 0 to ws-counter

  7.   end-if

  8.  end-if

  9. end-read

  Was this answer useful?  Yes

RohitPd

  • Dec 12th, 2011
 

It writes the first record and then skips a record and then writes the third record again, so basically were here writing the odd numbered records .i.e. when divided by 2 and the remainder is not equal to 0 then we write the output file.

Code
  1. Working-Storage

  2. n    PIC 9(09) value  1.

  3. m   PIC 9(09) value  zeroes.

  4. r    PIC 9(09) value  zeroes.

  5.  

  6. read input file

  7. divide n by 2 giving m and r as remainder

  8. if r!=0

  9.    write output file

  10.    add 1 to n

  11. end-if.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions