MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Extract Records

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
vijay
Beginner


Joined: 09 May 2003
Posts: 131
Topics: 64

PostPosted: Mon May 10, 2004 12:34 pm    Post subject: Extract Records Reply with quote

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 ...........


Thanks,
Vijay
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Mon May 10, 2004 12:56 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12377
Topics: 75
Location: San Jose

PostPosted: Mon May 10, 2004 1:14 pm    Post subject: Reply with quote

Vijay,

The following easytrieve will give you the desired results.

Code:

//STEP0100 EXEC PGM=EZTPA00                           
//STEPLIB  DD DSN=EASYTREV.LOADLIB,         
//            DISP=SHR                                 
//SYSPRINT DD SYSOUT=*                                 
//SYSOUT   DD SYSOUT=*                                 
//SYSSNAP  DD SYSOUT=*                                 
//SYSUDUMP DD SYSOUT=*                                 
//FILEIN   DD *                                       
AB 1000 ...........                                   
AB 4000 ...........                                   
AB 9000 ...........(OTHER FEILDS IN THE FILE)         
BC 1000 ...........                                   
CD 9000 ...........                                   
CD 9000 ...........                                   
//FILEOUT  DD SYSOUT=*,LRECL=80,RECFM=FB               
//SYSIN    DD *                                       
  FILE FILEIN                                         
       IN-KEY              001 002 A                   
       IN-QTY              004 004 N 0                 
                                                       
  FILE FILEOUT FB (0 0)                               
                                                       
  FILE TOT FB (0 0) VIRTUAL RETAIN                     
       TOT-KEY        01  02 A                         
       TOT-TALLY      03  10 P  0                     
       TOT-QTY        13  10 P  0                     
                                                       
                                                       
  JOB INPUT (FILEIN KEY (IN-KEY))                       
                                                       
   PRINT RPT                                           
   REPORT RPT SUMMARY SUMFILE TOT                       
   SEQUENCE IN-KEY                                     
   CONTROL IN-KEY                                       
   LINE IN-KEY IN-QTY                                   
                                                       
  JOB INPUT (TOT    KEY (TOT-KEY)    +                 
             FILEIN KEY (IN-KEY))                       
   IF MATCHED                                           
      IF TOT-QTY > 1000                                 
         PUT FILEOUT FROM FILEIN                       
      END-IF                                           
   END-IF                                               
/*                                                     


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group