retriving alternate records



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

Re: retriving alternate records

Postby Robert Sample » Tue Sep 20, 2011 6:51 pm

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: Re: retriving alternate records

 

Re: retriving alternate records

Postby Ed Goodman » Tue Sep 20, 2011 7:09 pm

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.
Ed Goodman
 
Posts: 342
Joined: Thu Feb 24, 2011 12:05 am
Has thanked: 3 times
Been thanked: 17 times

Re: retriving alternate records

Postby dick scherrer » Tue Sep 20, 2011 11:52 pm

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. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: retriving alternate records

Postby janardhanan_j » Thu Oct 27, 2011 6:35 pm

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...
janardhanan_j
 
Posts: 1
Joined: Thu Oct 27, 2011 6:29 pm
Has thanked: 0 time
Been thanked: 0 time

Re: retriving alternate records

Postby BillyBoyo » Thu Oct 27, 2011 7:10 pm

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

Re: retriving alternate records

Postby dick scherrer » Fri Nov 25, 2011 11:31 am

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.
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Previous

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post