# How to SUM the Fields in SORT

Author Message
Deepakgoyal2005

New User

Joined: 22 Mar 2007
Posts: 57
Location: India

 Posted: Tue Jun 24, 2008 10:02 am Please help on how to sum the fields corresponding to same value in a particular column. Example: Input is - 1111111111111111 100 1111111111111111 200 2222222222222222 600 Output required is - 1111111111111111 300 2222222222222222 600
dick scherrer

Moderator Emeritus

Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

 Posted: Tue Jun 24, 2008 11:53 am Hello, When you have a question, start a new topic rather than posting a reply to some 2-year-old topic. To do what you want, use "SUM FIELDS=(s,l,t)" where s=start pos, l=lth, and t=type.
Frank Yaeger

DFSORT Developer

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

Posted: Tue Jun 24, 2008 8:14 pm

Here's a DFSORT job that will do what you asked for:

 Code: //S1    EXEC  PGM=ICEMAN            //SYSOUT    DD  SYSOUT=*            //SORTIN DD *                        1111111111111111 100                1111111111111111 200                2222222222222222 600                /* //SORTOUT DD SYSOUT=*                //SYSIN    DD    *                    OPTION ZDPRINT                      SORT FIELDS=(1,16,CH,A)              SUM FIELDS=(18,3,ZD)              /*
Deepakgoyal2005

New User

Joined: 22 Mar 2007
Posts: 57
Location: India

Posted: Wed Jun 25, 2008 8:35 pm

Suppose i have an input like -
 Code: 1111111111 AAAA 100            BBBB 200            HHHH 300 2222222222 AAAA 100            BBBB 100 3333333333 AAAA 100

Required output is -
 Code: 1111111111 AAAA 600 2222222222 AAAA 200 3333333333 AAAA 100

The code in the previous reply do not works for this changed requirement.
Can i have a solution for it.
Skolusu

Senior Member

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

Posted: Wed Jun 25, 2008 9:14 pm

Deepakgoyal2005,

The following DFSORT/ICETOOL JCL will give you the desired results

 Code: //STEP0100 EXEC PGM=ICETOOL                                        //TOOLMSG  DD SYSOUT=*                                            //DFSMSG   DD SYSOUT=*                                            //IN       DD *                                                    1111111111 AAAA 100                                                           BBBB 200                                                           HHHH 300                                                2222222222 AAAA 100                                                           BBBB 100                                                3333333333 AAAA 100                                                //OUT      DD SYSOUT=*                                            //TOOLIN   DD *                                                      SPLICE FROM(IN) TO(OUT) ON(81,8,CH) KEEPNODUPS WITHALL -          WITH(1,80) KEEPBASE USING(CTL1)                                  //CTL1CNTL DD *                                                      INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),                IFTHEN=(WHEN=(1,10,CH,GT,C' '),OVERLAY=(81:SEQNUM,8,ZD,1,15)),    IFTHEN=(WHEN=NONE,OVERLAY=(89:SEQNUM,8,ZD,                                 81:81,8,ZD,SUB,89,8,ZD,M11,LENGTH=8))                                                                                      SORT FIELDS=COPY                                                  OUTFIL FNAMES=OUT,BUILD=(80X),                                    REMOVECC,NODETAIL,                                                SECTIONS=(89,10,                                                  TRAILER3=(89,15,X,TOT=(17,3,ZD,M10,LENGTH=8)))                  /*

The output from this job is

 Code: 1111111111 AAAA      600 2222222222 AAAA      200 3333333333 AAAA      100
Deepakgoyal2005

New User

Joined: 22 Mar 2007
Posts: 57
Location: India

 Posted: Fri Jun 27, 2008 8:29 pm The above Code is giving SOC7. I had tried with some modifications but haven't got the solution.
Skolusu

Senior Member

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

Posted: Fri Jun 27, 2008 9:10 pm

 Deepakgoyal2005 wrote: The above Code is giving SOC7. I had tried with some modifications but haven't got the solution.

Well unless you show me the right input or layout of the file or the control cards you used , how do you expect us to help you?

I showed you an example based on the sample input you have shown.

1. What is the LRECL and RECFM of the files.
2. What is the pos and format of the key to be considered?
3. What is the pos and format of the field to be summed?
Deepakgoyal2005

New User

Joined: 22 Mar 2007
Posts: 57
Location: India

Posted: Fri Jun 27, 2008 9:20 pm

 Code: //STEP010 EXEC PGM=ICETOOL                                        //SYSOUT   DD SYSOUT=*                                            //TOOLMSG  DD SYSOUT=*                                            //DFSMSG   DD SYSOUT=*                                            //IN       DD *                                                  1111111111 AAAA 100                                                         BBBB 200                                                         HHHH 300                                              2222222222 AAAA 100                                                         BBBB 100                                              3333333333 AAAA 100                                              //OUT      DD DSN=DEAR.DEEPAK.DUMMY.FILE,                        //            DISP=(NEW,CATLG,DELETE),                            //            SPACE=(CYL,(01,01),RLSE),                          //            DCB=(SYS1.DSCB,LRECL=80,RECFM=FB)                  //TOOLIN   DD *                                                    SPLICE FROM(IN) TO(OUT) ON(81,8,CH) KEEPNODUPS WITHALL -          WITH(1,80) KEEPBASE USING(CTL1)                                //CTL1CNTL DD *                                                    INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),                IFTHEN=(WHEN=(1,10,CH,GT,C' '),OVERLAY=(81:SEQNUM,8,ZD,1,15)),   IFTHEN=(WHEN=NONE,OVERLAY=(89:SEQNUM,8,ZD,                                 81:81,8,ZD,SUB,89,8,ZD,M11,LENGTH=8))                                                   SORT FIELDS=COPY                                OUTFIL FNAMES=OUT,BUILD=(80X),                  REMOVECC,NODETAIL,                              SECTIONS=(89,10,                                TRAILER3=(89,15,X,TOT=(17,3,ZD,M10,LENGTH=8))) /*

The above code was my input which gave me SOC7.
Let me know if i had missed any information.
Skolusu

Senior Member

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

 Posted: Fri Jun 27, 2008 9:27 pm Deepakgoyal2005, You sure you ran the JOB as is? I get a return code of zero with the job. You mentioned that you made changes to the job, what did you change? Show me the error messages you are getting. post the contents of DFSMSG DD
Deepakgoyal2005

New User

Joined: 22 Mar 2007
Posts: 57
Location: India

Posted: Fri Jun 27, 2008 9:38 pm

yes i ran the job as is.

The msg i got is -
" 09.02.29 JOB31590 \$HASP165 DEARSUM ENDED AT HFNRDC01 - ABENDED S0C7 U0000 CN(INTERNAL) "

DFSMSG shows -
 Code: SYNCSORT FOR Z/OS  1.2.3.1RI   U.S. PATENTS: 4210961, 5117495   (C) 2005 SYNCSORT INC.   DATE=2008/179   TIME=09.02.29                                                  HSBC   z/OS   1.8.0                                                     PRODUCT LICENSED FOR CPU SERIAL NUMBER 53AF0, MODEL 2094 712              LICENSE/PRODUCT EXPIRATION DATE: 02 MAY 2012  CTL1CNTL :                                                                                                               INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),                    00051004                                         IFTHEN=(WHEN=(1,10,CH,GT,C' '),OVERLAY=(81:SEQNUM,8,ZD,1,15)),        00052004                                         IFTHEN=(WHEN=NONE,OVERLAY=(89:SEQNUM,8,ZD,                            00053004                                                  81:81,8,ZD,SUB,89,8,ZD,M11,LENGTH=8))                        00054004                                                                                                               00055004                                         SORT FIELDS=COPY                                                      00056004                                         OUTFIL FNAMES=OUT,BUILD=(80X),                                        00057004                                         REMOVECC,NODETAIL,                                                    00058004                                         SECTIONS=(89,10,                                                      00059004                                         TRAILER3=(89,15,X,TOT=(17,3,ZD,M10,LENGTH=8)))                        00059104                                       PARMLIST :                                                                                                             OPTION RESINV=0,ARESINV=0,MSGDDN=DFSMSG,SORTIN=IN,SORTDD=CTL1,SORTOUT=OUT,DYNALL                                       OC,CMP=CLC,NOVLSHRT,EQUALS                                                                                             SORT FIELDS=(00081,0008,CH,A)                                                                                           MODS E35=(SYNCT#35,4096,,N)

JESYSMSG shows -

 Code: IEF237I JES2 ALLOCATED TO TOOLIN                          IEF237I JES2 ALLOCATED TO CTL1CNTL                        IEA995I SYMPTOM DUMP OUTPUT                                SYSTEM COMPLETION CODE=0C7  REASON CODE=00000000           TIME=09.02.29  SEQ=11585  CPU=0000  ASID=02B1             PSW AT TIME OF ERROR  078D1000   80051A30  ILC 4  INTC 07    NO ACTIVE MODULE FOUND                                     NAME=UNKNOWN

JESMSGLG shows -
 Code: 09.02.28 JOB31590  IEF403I DEARSUM - STARTED - TIME=09.02.28                      09.02.29 JOB31590  +WER999A DEARSUM ,STEP010 ,        -  UNSUCCESSFUL SORT 0C7 S 09.02.29 JOB31590  IEA995I SYMPTOM DUMP OUTPUT  721                                 721             SYSTEM COMPLETION CODE=0C7  REASON CODE=00000000                 721              TIME=09.02.29  SEQ=11585  CPU=0000  ASID=02B1                   721              PSW AT TIME OF ERROR  078D1000   80051A30  ILC 4  INTC 07       721                NO ACTIVE MODULE FOUND                                         721                NAME=UNKNOWN
dick scherrer

Moderator Emeritus

Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

 Posted: Fri Jun 27, 2008 9:43 pm Hello, You are using Syncsort, not DFSORT.
Alissa Margulies

SYNCSORT Support

Joined: 25 Jul 2007
Posts: 496
Location: USA

 Posted: Sat Jun 28, 2008 1:57 am Deepakgoyal2005, Please contact me offline regarding the Abend0C7 you encountered. You can email me at alissa.margulies@syncsort.com. Thank you.
Skolusu

Senior Member

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

 Posted: Sat Jun 28, 2008 2:18 am Just an FYI , the JOB works fine with DFSORT's ICETOOL and produces the desired output
Arun Raj

Moderator

Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

Posted: Sun Jun 29, 2008 1:25 pm

Hello Deepak,

Please try the below sort card. It works with syncsort. Our release is Syncsort 1.2.

 Code: //SYSIN DD *                                                            INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),                          IFTHEN=(WHEN=(1,10,CH,GT,C' '),OVERLAY=(81:SEQNUM,8,ZD,1,15)),         IFTHEN=(WHEN=NONE,OVERLAY=(89:1,15,104:SEQNUM,8,ZD,                            81:81,8,ZD,SUB,104,8,ZD,M11,LENGTH=8))                  SORT FIELDS=(81,8,CH,A)                                                SUM FIELDS=(17,3,ZD)                                                  OUTREC FIELDS=(89,15,17,3,ZD,M10,LENGTH=8)                          /*

Thanks,
Arun
Alissa Margulies

SYNCSORT Support

Joined: 25 Jul 2007
Posts: 496
Location: USA

 Posted: Mon Jun 30, 2008 8:28 pm (Maintenance was sent to resolve the Abend0C7).
Deepakgoyal2005

New User

Joined: 22 Mar 2007
Posts: 57
Location: India

 Posted: Fri Jul 04, 2008 10:02 am Thanks to Arun, since the code provided by him worked with SORT utility. Arun, it would be nice of you if you could provide me a brief explanation of the code been provided by you.
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics WER999A - UNSUCCESSFUL SORT 8ED U Ab... SYNCSORT 5 COBOL Ascending and descending sort n... COBOL Programming 5 SORT deletes the SORTOUT file DFSORT/ICETOOL 8 Creating CSV file from Variable recs ... DFSORT/ICETOOL 11 Need suggestion on a sort card DFSORT/ICETOOL 10
Search our Forums:

 IBMMainframes.com is not an official and/or affiliated with IBM® in anyway Board Rules | FAQ | Downloads | Wiki | SiteMap | Contact Us