View previous topic :: View next topic
|
Author |
Message |
akashs
New User
Joined: 24 Nov 2005 Posts: 49 Location: chennai
|
|
|
|
Hi,
There is a input sequential file.I need to get 1st,3rd,5th....Only odd number of records to the output file.How to do it a COBOL program.
thanks,
Akash |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
what kind of logic flow have you developed? |
|
Back to top |
|
|
akashs
New User
Joined: 24 Nov 2005 Posts: 49 Location: chennai
|
|
|
|
Hi,
It was asked in one interview.Please tell me possible solution
regards,
Akash |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
How would you do it if you were the COBOL program?
Code: |
Read input record
Add one to count
Is count odd?
No, go to read
Yes, write input record to output
Go to read |
This could also be done with a simple sort where input has a seqnum of one digit, starting at zero and incremented by five. Omit the fives for odds and omit the zeros for evens. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Quote: |
This could also be done with a simple sort where input has a seqnum of one digit, starting at zero and incremented by five. Omit the fives for odds and omit the zeros for evens. |
There is other simple alternative to this:
Code: |
//SORTIN DD DSN= . . . input FB/80
//ODD DD SYSOUT=*
//*
//EVEN DD SYSOUT=*
//*
//SYSIN DD *
SORT FIELDS=COPY
OUTFIL FNAMES=(ODD,EVEN),SPLIT
/* |
|
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Here's some pseudo code for a COBOL solution:
Code: |
read ip
chk for eof - yes, error and out
no, perform until ipeof
write op
read ip
eof? Yes, set ipeof, exit perform
No, read ip, eof? Yes, set ipeof
end-perform
close, etc |
|
|
Back to top |
|
|
|