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

Extract first 10 records which falls under a key


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sthirumalai

New User


Joined: 14 Aug 2007
Posts: 14
Location: Chennai

PostPosted: Tue Jun 21, 2011 11:17 pm
Reply with quote

Hi

I have a FB byte file of length 80 Bytes.

first 10 bytes have account number and starting from 11 to 18 we got the transaction amount.

The file is sorted on account number and transaction amount ascending.

I have to fetch first 10 transactions under each account number and I have to skip the rest of the records under the account number till the next account number is obtained.

Please note that an account number may also have less than 10 transactions. In that case I need all those records under the account number to be extracted.

Is there any way to do this using DFsort?

Thanks & Regards
Santhosh
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Tue Jun 21, 2011 11:43 pm
Reply with quote

sthirumalai,

Use this DFSORT/ICETOOL JCL

Code:

//STEP0100 EXEC PGM=ICETOOL                                 
//TOOLMSG  DD SYSOUT=*                                     
//DFSMSG   DD SYSOUT=*                                     
//IN       DD *                                             
----+----1----+----2----+----3----+----4----+----5----+----6
KEY1            01                                         
KEY1            02                                         
KEY1            03                                         
KEY1            04                                         
KEY1            05                                         
KEY1            06                                         
KEY1            07                                         
KEY1            08                                         
KEY1            09                                         
KEY1            10                                         
KEY1            11                                         
KEY1            12                                         
KEY1            13                                         
KEY1            00                                         
KEY2            12                                         
KEY2            10                                         
KEY2            00                                         
//OUT      DD SYSOUT=*                                     
//TOOLIN   DD *                                             
  SELECT FROM(IN) TO(OUT) ON(1,10,CH) FIRST(10) USING(CTL1)
//CTL1CNTL DD *                                             
  SORT FIELDS=(01,10,CH,A,                                 
               11,08,ZD,A)                                 
//*
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Tue Jun 21, 2011 11:57 pm
Reply with quote

Kolusu,
Quote:
The file is sorted on account number and transaction amount ascending.

Do we need to resort the file? Wouldn't below suffice the requirement?
Code:
//SYSIN    DD *                                             
  INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,10),PUSH=(81:SEQ=8))
  SORT FIELDS=COPY                                         
  OUTFIL INCLUDE=(81,8,ZD,LE,10),BUILD=(1,80)               
//*                                                         

OR
Code:
//SYSIN    DD *                                                   
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,10)))
  SORT FIELDS=COPY                                                 
  OUTFIL INCLUDE=(81,8,ZD,LE,10),BUILD=(1,80)                     
//*                                                               

Thanks,
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Wed Jun 22, 2011 12:05 am
Reply with quote

Sqlcode1 wrote:
Do we need to resort the file? Wouldn't below suffice the requirement?


Hmm I assumed that the sort need to be done and then pick the first 10. Well if the data is already sorted then he can simply replace CTL1CNTL with this.
Code:

//CTL1CNTL DD *                                             
  SORT FIELDS=COPY
//*


Now the question arises as to why the data is sorted in a different step when everything can be done in 1 pass.

I usually prefer SELECT for such operations instead of appending the key at the end and then having to change if there is change in the LRECL or RECFM. With SELECT operator there is no change at all.
Back to top
View user's profile Send private message
sthirumalai

New User


Joined: 14 Aug 2007
Posts: 14
Location: Chennai

PostPosted: Wed Jun 22, 2011 12:06 am
Reply with quote

Hi Kolusu/Sqlcode,

Thanks for your help

Both the solution works 100%.

Regards
Santhosh
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Need help for File Aid JCL to extract... Compuware & Other Tools 23
Search our Forums:

Back to Top