Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to get odd number of records

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
View previous topic :: :: View next topic  
Author Message
akashs

New User


Joined: 24 Nov 2005
Posts: 49
Location: chennai

PostPosted: Sun May 03, 2009 6:19 pm    Post subject: How to get odd number of records
Reply with quote

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
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6970
Location: porcelain throne

PostPosted: Sun May 03, 2009 6:23 pm    Post subject:
Reply with quote

what kind of logic flow have you developed?
Back to top
View user's profile Send private message
akashs

New User


Joined: 24 Nov 2005
Posts: 49
Location: chennai

PostPosted: Sun May 03, 2009 6:36 pm    Post subject:
Reply with quote

Hi,

It was asked in one interview.Please tell me possible solution

regards,
Akash
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Sun May 03, 2009 6:49 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon May 04, 2009 2:37 pm    Post subject:
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri May 08, 2009 7:03 am    Post subject:
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Inefficient BUILD - VB records paddin... Daniel Prosser SYNCSORT 7 Thu Dec 14, 2017 3:52 pm
No new posts ISSUE IN copying Sequential file reco... thesumitk JCL & VSAM 2 Wed Dec 13, 2017 3:07 pm
No new posts Merging 2 records at multiple rows wi... Bijesh DFSORT/ICETOOL 2 Wed Dec 06, 2017 1:50 am
No new posts Increment number for every group of r... srajendran2 DFSORT/ICETOOL 7 Thu Nov 09, 2017 10:31 pm
No new posts Matching and unmatched records!! Vignesh Sid SYNCSORT 3 Thu Nov 09, 2017 11:22 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us