Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

To get 1st two occurance of records

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Fri Feb 06, 2009 12:04 pm    Post subject: To get 1st two occurance of records
Reply with quote

Hi,

I have to create a cobol code to get 1st two occurance of same records and to bypass the other occcurances of same record.

e.g we have rec as

rupesh1 abc def
rupesh1 ghi jkl
rupesh1 mno pqr

ram1 stu vwx yza
ram1 bcd efg hij
ram1 klm nop qrs
ram1 tuv wxy zab
------
-----
---

my o/p should be
rupesh1 abc def
rupesh1 ghi jkl
ram1 stu vwx yza
ram1 bcd efg hij

Also let me know how can i do it using sort
Regards,
rupesh gupta
Back to top
View user's profile Send private message

sai_sridar_s

New User


Joined: 14 Nov 2006
Posts: 6

PostPosted: Fri Feb 06, 2009 12:30 pm    Post subject: Reply to: To get 1st two occurance of records
Reply with quote

hi,

u can do using ICETOOL

//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=... input file
//OUT DD DSN=... output file
//TOOLIN DD *
SELECT FROM(IN) TO(OUT) ON(1,7,CH) FIRST(2)
//*

Refer Smart DFSORT Tricks

other wise you can have a counter for key field and skip if is greater than two and agian initialize the counter to check for other key occurence in your cobol pgm.

Hope this helps..
Back to top
View user's profile Send private message
naveengec

New User


Joined: 24 Mar 2007
Posts: 35
Location: pune

PostPosted: Fri Feb 06, 2009 12:35 pm    Post subject: Perfect sai
Reply with quote

i tried it....its working..... please let me know in case if there is any other way to do it..
Back to top
View user's profile Send private message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Fri Feb 06, 2009 12:37 pm    Post subject: Reply to: To get 1st two occurance of records
Reply with quote

thanks sai its working for me ...
regards,
rupesh gupta
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Fri Feb 06, 2009 12:38 pm    Post subject: Reply to: To get 1st two occurance of records
Reply with quote

Hi,

You need use a simple logic in cobol code to handle this.
1) Sort your input on the key( all duplicate key should be aligned together)
2) Read the 1st rec and move it into an array of 2 and also maintain a counter of key
3) Read the next rec
4) check if the key is same then again move it into the array , increment the counter, and finally write it into the o/p file.
5) Keep on reading the recs until you get a new key. If you get a new key, reset the counter to '1' again and move it to the array .......( start repeating the previous steps 2 - 5).

Now, If you have dfsort in your system. Things could become much more easier.

//TOOLIN DD *
SELECT FROM(IN) TO(OUT) ON(1,10,CH) FIRST(2) USING(CTL1)
//CTL1CNTL DD *
SORT FIELDS=(1,10,CH,A)

This works very well.
Thanks,
-Kapil.
Back to top
View user's profile Send private message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Fri Feb 06, 2009 1:58 pm    Post subject: Reply to: To get 1st two occurance of records
Reply with quote

thanks kapil .. i will try both ways.

regards.
rupesh gupta
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2284
Location: @my desk

PostPosted: Fri Feb 06, 2009 8:03 pm    Post subject:
Reply with quote

Kapil,

I dont think you need that CTL1 card.
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 -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am
No new posts TSO or command line utility to genera... kishpra JCL & VSAM 3 Thu Mar 09, 2017 1:11 am
No new posts Extract set of records matching on ac... bhaskar_kanteti DFSORT/ICETOOL 3 Mon Mar 06, 2017 7:19 am
No new posts Inserting records based on conditions vickey_dw DFSORT/ICETOOL 9 Wed Feb 22, 2017 1:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us