Page 2 of 2

Re: retriving alternate records

PostPosted: Tue Sep 20, 2011 6:51 pm
by Robert Sample
Since your program controls which records are written -- YOU WRITE THE LOGIC! This forum is not intended to teach you COBOL; you'll need to find other resources (online or not) to teach you. When you have problems, we will help get your logic and code straightened out but unless you're willing to pay whatever the going rate is, you're not going to be getting code here.

Re: retriving alternate records

PostPosted: Tue Sep 20, 2011 7:09 pm
by Ed Goodman
You are asking too much, sorry. I'm a big softie and even I think you've crossed the line here.

You need to write a program that reads ALL the records, then writes out every other record. If you are really unable to figure that out in COBOL, then us posting some code probably won't help you.

If you are really that stuck, I'd suggest you try writing a program that reads all the records and writes all the records. Once you have that, try to figure out how to make it not write every second record. Sometimes, doing things in small steps helps to figure them out.

Re: retriving alternate records

PostPosted: Tue Sep 20, 2011 11:52 pm
by dick scherrer
Hello,

can you tell me the logic to read all the records but write only the odd records to a new file.
Most of us can - but that is not why the forum is here. We are here to help you learn, not provide coded solutions for your homework or whatever.

You need to show what you have tried and where there are problems or questions. If you cannot get the code going, post in English how you see this happening (hint - this is not a difficult exercise, so do not make it difficult).

Is this your first cobol program?

As suggested, write a program that reads and writes all of the records. Then we can talk about how to alternate. . .

Re: retriving alternate records

PostPosted: Thu Oct 27, 2011 6:35 pm
by janardhanan_j
What you can do is just initialise a counter.. and increment the counter for each record read.
When the count is odd i.e. when the rem is not zero when divided by 2, write those records on to the output file..

The output will have the records 1,3,5 and so on...

Re: retriving alternate records

PostPosted: Thu Oct 27, 2011 7:10 pm
by BillyBoyo
01  W-WRITE-ODDNO-RECORD-FLAG PIC X VALUE "Y".
    88  W-WORF-RECORD-IS-ODDNO VALUE "Y".
    88  W-WORF-RECORD-NOT-ODDNO VALUE "N".
    88  W-WORF-WRITE-NEXT VALUE "Y".
    88  W-WORF-DONT-WRITE-NEXT VALUE "N".

priming read

loop until end-of-file

IF W-WORF-RECORD-IS-ODDNO
    do stuff to write record, check status etc
    SET W-WORF-DONT-WRITE-NEXT TO TRUE
ELSE
    SET W-WORF-WRITE-NEXT TO TRUE
END-IF

read input
continue loop


This way is less stress on the maintainer (my opinion) and less stress on the machine (moving and testing characters is less CPU-intensive than arithmetic/testing numbers).

TS is long-gone, but someone else might read this. A flag with a value to show what happens "next" is a common solution in various situations.

Re: retriving alternate records

PostPosted: Fri Nov 25, 2011 11:31 am
by dick scherrer
Hello and welcome to the forum,

While this approach might be ok for some introductory class exercise, it is a "style" best avoided. Sites who review code to be promoted will likely not permit promotion of this.