Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Sum a field Value for a condition

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
Author Message
Niha Rai

New User


Joined: 27 Apr 2008
Posts: 1
Location: India

PostPosted: Mon Apr 28, 2008 10:22 am    Post subject: Sum a field Value for a condition
Reply with quote

I have a file with following records:
F1 F2 F3
A 50.00 001
B 42.00 002
A 51.00 002
A 23.00 004
B 27.00 004
C 59.00 001

I want that the output should sum the field F2 when F1 is same and F3 = 002 or 004, so the output should contain

A 50.00 001
A 74.00 002
B 69.00 002
C 59.00 001

Please suggest a sort card using PGM=SORT
Back to top
View user's profile Send private message
References
PostPosted: Mon Apr 28, 2008 10:22 am    Post subject: Re: Sum a field Value for a condition Reply with quote

Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 3798
Location: San Jose, CA

PostPosted: Mon Apr 28, 2008 9:39 pm    Post subject:
Reply with quote

You can use a DFSORT job like this:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=...  input file (FB/11)
//SORTOUT DD DSN=...  output file (FB/11)
//SYSIN    DD    *
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(12:1,1,13:SEQNUM,8,ZD)),
        IFTHEN=(WHEN=(9,3,SS,EQ,C'002,004'),OVERLAY=(13:8C'0'))
  SORT FIELDS=(12,9,CH,A)
  OUTFIL REMOVECC,NODETAIL,
    BUILD=(1,11),
    SECTIONS=(12,9,
      TRAILER3=(1,1,3:TOT=(3,5,UFF,EDIT=(TT.TT)),9:9,3))
/*
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1