# [Solved]SUM based on two conditions using SYNCSORT

Author Message
sri_mf

Active User

Joined: 31 Aug 2006
Posts: 218
Location: India

Posted: Fri Jul 30, 2021 10:42 am

Hi..

My Input data is

AAAAA 11111 T 3
AAAAA 11111 T 1
AAAAA 11111 T 3
AAAAA 11111 L 3
AAAAA 11111 T 2
BBBBB BBBBB L 4
BBBBB BBBBB L 3
BBBBB BBBBB T 1
BBBBB BBBBB T 3
CCCCC CCCCC T 4
CCCCC CCCCC T 2

Now If first 5 bytes is AAAAA and from the 6th position onwards next 5 bytes is 11111 then i need to sum the data based on T or L which is there in the 13th Position.

I tried the below cards using SYNCSORT..

 Code: INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),   IFTHEN=(WHEN=(1,5,CH,EQ,C'AAAAA',AND,7,5,CH,EQ,C'11111'),                  OVERLAY=(81:8C'0'))  SORT FIELDS=(14,1,CH,A,81,8,ZD,A) OPTION ZDPRINT SUM FIELDS=(18,1,ZD) OUTREC BUILD=(1,80)

But it is not taking the second condition - AND,7,5,CH,EQ,C'11111' ( Throwing an error)
How to code multiple conditions in my case....
Joerg.Findeisen

Senior Member

Joined: 15 Aug 2015
Posts: 1295
Location: Bamberg, Germany

Posted: Fri Jul 30, 2021 10:58 am

sri_mf wrote:
Hi..

My Input data is

AAAAA 11111 T 3
AAAAA 11111 T 1
AAAAA 11111 T 3
AAAAA 11111 L 3
AAAAA 11111 T 2
BBBBB BBBBB L 4
BBBBB BBBBB L 3
BBBBB BBBBB T 1
BBBBB BBBBB T 3
CCCCC CCCCC T 4
CCCCC CCCCC T 2

Now If first 5 bytes is AAAAA and from the 6th position onwards next 5 bytes is 11111 then i need to sum the data based on T or L which is there in the 13th Position.

I tried the below cards using SYNCSORT..

 Code: INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),   IFTHEN=(WHEN=(1,5,CH,EQ,C'AAAAA',AND,7,5,CH,EQ,C'11111'),                  OVERLAY=(81:8C'0'))  SORT FIELDS=(14,1,CH,A,81,8,ZD,A) OPTION ZDPRINT SUM FIELDS=(18,1,ZD) OUTREC BUILD=(1,80)

But it is not taking the second condition - AND,7,5,CH,EQ,C'11111' ( Throwing an error)
How to code multiple conditions in my case....

Nothing is "thrown" in z/OS..

Use:
 Code: SUM FIELDS=(15,1,ZD)

And also check Position of the first SORT FIELDS=(..)
sri_mf

Active User

Joined: 31 Aug 2006
Posts: 218
Location: India

Posted: Fri Jul 30, 2021 11:35 am

 Code: AAAAA 11111  T   3 AAAAA 11111  T   1 AAAAA 11111  T   3 AAAAA 11111  L   3 AAAAA 11111  T   2 BBBBB BBBBB  L   4 BBBBB BBBBB  L   3 BBBBB BBBBB  T   1 BBBBB BBBBB  T   3 CCCCC CCCCC  T   4 CCCCC CCCCC  T   2

after 11111 there are 2 spaces and after T or L there are 3 spaces.... T or L are starting at 14th Position and the numbers 3,1,3 etc are starting at 18th position
sergeyken

Senior Member

Joined: 29 Apr 2008
Posts: 2081
Location: USA

 Posted: Fri Jul 30, 2021 8:14 pm Needs to be automatically re-routed to the Beginners Forum. Itâ€™s all getting extremely annoying.
dneufarth

Active User

Joined: 27 Apr 2005
Posts: 420
Location: Inside the SPEW (Southwest Ohio, USA)

 Posted: Fri Jul 30, 2021 8:47 pm And the SYNCSORT error message is? Or, it just doesn't produce expected results?
Rohit Umarjikar

Global Moderator

Joined: 21 Sep 2010
Posts: 3066
Location: NYC,USA

Posted: Sat Jul 31, 2021 3:10 am

 Code: //SORTIN   DD  *                                                        AAAAA 11111 T 3                                                          AAAAA 11111 T 1                                                          AAAAA 11111 T 3                                                          AAAAA 11111 L 3                                                          AAAAA 11111 T 2                                                          BBBBB BBBBB L 4                                                          BBBBB BBBBB L 3                                                          BBBBB BBBBB T 1                                                          BBBBB BBBBB T 3                                                          CCCCC CCCCC T 4                                                          CCCCC CCCCC T 2                                                          //SORTOUT   DD SYSOUT=*                                                  //SYSOUT   DD  SYSOUT=*                                                  //SYSIN     DD *                                                        //SYSIN     DD *                                                     INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD)),                         IFTHEN=(WHEN=(1,11,CH,EQ,C'AAAAA 11111'),OVERLAY=(81:8C'0'))  SORT FIELDS=(81,8,ZD,A)                                             OUTFIL REMOVECC,NODETAIL,SECTIONS=(81,8,                                    TRAILER3=(1,14,X,TOT=(15,1,ZD,EDIT=(IT)))),BUILD=(1,80)

Output:
 Code: ********************************* TOP OF DATA ********************************** AAAAA 11111 T  12                                                                BBBBB BBBBB L   4                                                                BBBBB BBBBB L   3                                                                BBBBB BBBBB T   1                                                                BBBBB BBBBB T   3                                                                CCCCC CCCCC T   4                                                                CCCCC CCCCC T   2                                                                ******************************** BOTTOM OF DATA ********************************
sri_mf

Active User

Joined: 31 Aug 2006
Posts: 218
Location: India

 Posted: Sat Jul 31, 2021 9:44 am Thank you very much Rohit.
Rohit Umarjikar

Global Moderator

Joined: 21 Sep 2010
Posts: 3066
Location: NYC,USA

 Posted: Sat Jul 31, 2021 4:37 pm Welcome Sri.
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics To Omit records based n SORT condition DFSORT/ICETOOL 6 Compare only first records of the fil... SYNCSORT 7 How to load to DB2 with column level ... DB2 6 Db2 SQL - how to switch among differe... DB2 18 To search DB2 table based on Conditio... DB2 1
Search our Forums:

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