IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

To get 1st two occurance of records


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 5

PostPosted: Fri Feb 06, 2009 12:30 pm
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
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
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
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
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: 2481
Location: @my desk

PostPosted: Fri Feb 06, 2009 8:03 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Join multiple records using splice DFSORT/ICETOOL 5
No new posts EZT program to build a flat file with... All Other Mainframe Topics 9
Search our Forums:

Back to Top