Posted: Mon May 10, 2004 12:34 pm Post subject: Extract Records
Hi,
I've 2 fields in the file
ID and amt.ID field can have duplicates also.If total amount for a particular ID (sum of the amount field for each record for that ID) is > 1000,I need to copy all the records for that ID to another file.Do u know the easiest way to do this?I'm thinking of trying with EZT.
Input:
ab 1000 ...........
ab 4000 ...........
ab 9000 ...........(Other feilds in the file)
bc 1000 ...........
cd 9000 ...........
cd 9000 ...........
Output:
ab 1000 ...........
ab 4000 ...........
ab 9000 ...........
cd 9000 ...........
cd 9000 ...........
Joined: 02 Dec 2002 Posts: 1618 Topics: 31 Location: San Jose
Posted: Mon May 10, 2004 12:56 pm Post subject:
Assuming that your input file has RECFM=FB and LRECL=80, and that your amount is an 8-byte ZD value starting in position 4 (I'm guessing it isn't really a 4-byte ZD value as you show since that would cause the totals to overflow), this DFSORT/ICETOOL job will do what you asked for. You'll need DFSORT R14 PTF UQ90053 (Feb, 2003) to use SPLICE.
Code:
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=... input file
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//CON DD DSN=*.T1,VOL=REF=*.T1,DISP=(OLD,PASS)
// DD DSN=*.IN,VOL=REF=*.IN,DISP=(OLD,PASS)
//OUT DD DSN=... output file
//TOOLIN DD *
* IN->T1: Extract one record for each key with a sum > 1000.
SORT FROM(IN) USING(CTL1)
* T1/IN->OUT: Extract all records for each key with a sum > 1000.
SPLICE FROM(CON) TO(OUT) ON(1,2,CH) WITHALL WITH(1,80)
//CTL1CNTL DD *
OPTION ZDPRINT
SORT FIELDS=(1,2,CH,A)
SUM FIELDS=(4,8,ZD)
OUTFIL FNAMES=T1,INCLUDE=(4,8,ZD,GT,+1000)
/*
_________________ Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum