View previous topic :: View next topic
|
Author |
Message |
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
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 |
|
|
sai_sridar_s
New User
Joined: 14 Nov 2006 Posts: 5
|
|
|
|
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 |
|
|
naveengec
New User
Joined: 24 Mar 2007 Posts: 35 Location: pune
|
|
|
|
i tried it....its working..... please let me know in case if there is any other way to do it.. |
|
Back to top |
|
|
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
thanks sai its working for me ...
regards,
rupesh gupta |
|
Back to top |
|
|
hikaps14
Active User
Joined: 02 Sep 2005 Posts: 189 Location: Noida
|
|
|
|
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 |
|
|
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
thanks kapil .. i will try both ways.
regards.
rupesh gupta |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Kapil,
I dont think you need that CTL1 card. |
|
Back to top |
|
|
|