IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Summing records conditional statements.


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
chillmo

New User


Joined: 31 Aug 2017
Posts: 30
Location: USA

PostPosted: Wed May 15, 2019 2:12 am
Reply with quote

Hello world.

I'm trying to sum records with amounts in different positions based on the first character of the file. Can this be accomplished in SyncSort?

Input file:
134569999 <- need to sum position starting in 6 for length of 4
134568888 <- need to sum position starting in 6 for length of 4
299993332654 <- need to sum position starting in 9 for length of 4
299995448734 <- need to sum position starting in 9 for length of 4

Output file:
1 - $188.87
2 - $113.88

Also, is there a way to change the output file to reflect a more meaningful description, e.g., instead of 1 it can display "Total Charges" or instead of 2, it can display "Total Waived Charges".

Any assistance would be greatly appreciated.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Wed May 15, 2019 9:56 pm
Reply with quote

chillmo wrote:
I'm trying to sum records with amounts in different positions based on the first character of the file. Can this be accomplished in SyncSort?

Input file:
134569999 <- need to sum position starting in 6 for length of 4
134568888 <- need to sum position starting in 6 for length of 4
299993332654 <- need to sum position starting in 9 for length of 4
299995448734 <- need to sum position starting in 9 for length of 4

1. If "you are trying something" then where are any results of your attempts???

2. Your "description" of input file (e.g., dataset) doesn't clarify what you really want to do.

3. How come that from 4 input positions you produced 5 output digits, plus decimal point, plus dollar sign?
Back to top
View user's profile Send private message
chillmo

New User


Joined: 31 Aug 2017
Posts: 30
Location: USA

PostPosted: Wed May 15, 2019 10:32 pm
Reply with quote

sergeyken,

I'm trying to sum amounts in position 6 for the first two records and sum amounts in position 9 for the next two records (since they have the same character in position 1). And, would like it formatted to include a dollar sign and decimal point.

Thanks for taking the time to assist me.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Wed May 15, 2019 11:01 pm
Reply with quote

I have to repeat the same (the last note):

1. If "you are trying something" then where are any results of your attempts???

2. Your "description" of input file (e.g., dataset) doesn't clarify what you really want to do.
Back to top
View user's profile Send private message
chillmo

New User


Joined: 31 Aug 2017
Posts: 30
Location: USA

PostPosted: Wed May 15, 2019 11:48 pm
Reply with quote

NOT sure I understand you......I can't get this to work, so i don't hane any results, which is why I'm on the site. Secondly, i'm trying to sum the total amount of "Direct Charges" and "Waived Charges"....does this help you?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu May 16, 2019 1:05 am
Reply with quote

Quote:
I can't get this to work, so i don't hane any results,
Are you getting a JCL error? Are you not getting a JCL error but not getting any output? Are you getting SYNCSORT (WER) messages in your output? What, precisely, are you doing and what results are you getting?

If you have not yet even attempted to code and test yourself, be aware that this is a HELP forum, NOT a WRITE-THE-CODE-FOR-YOU forum. When you start posting job output and error messages, you'll get vastly better help. Until then, there's nothing more that we can do for you (this is a forum for professionals, who are supposed to know how to write sort utility statements and get output). You may be better off on Beginners and Students Forum although you will still need to code and run something to get meaningful feedback.
Back to top
View user's profile Send private message
chillmo

New User


Joined: 31 Aug 2017
Posts: 30
Location: USA

PostPosted: Thu May 16, 2019 2:00 am
Reply with quote

Ok, thanks for the honest feedback. This is my first attempt on this website as I usually find the answers to what I need. Furthermore, below is my code, which works but doesn't give me the results I expect (see above).

Code:

 //SORTCHMO EXEC PGM=SORT                 
 //SYSPRINT DD SYSOUT=*                                       
 //SYSUDUMP DD SYSOUT=0                                       
 //SORTMSG  DD SYSOUT=*                                       
 //SYSOUT   DD SYSOUT=*                                       
 //SORTIN   DD DISP=SHR,DSN=INPUT             
 //SORTOUT  DD DSN=OUTPUT,                 
 //            DISP=(,CATLG,DELETE),                           
 //            SPACE=(CYL,(5,5),RLSE)                         
 //SYSIN DD *                                                 
   INCLUDE COND=(2,4,ZD,EQ,98)                               
   SORT FIELDS=(1,1,CH,A)                                     
   OUTREC IFTHEN=(WHEN=(1,1,CH,EQ,C'2'),                       
        OVERLAY=(1:C'WAIVED CHARGE TOTAL: ',2X,25:6,4,42X)),
          IFTHEN=(WHEN=(1,1,CH,EQ,C'3'),                       
        OVERLAY=(1:C'SERVICE CHARGE TOTAL: ',2X,25:9,4,42X))
   SUM  FIELDS=(25,4,ZD)   
/*


Below are the results I get (it's NOT summing plus, I'm unsure how to add the mask edits to produce the dollar sign and cents):

WAIVED CHARGE TOTAL: 00000008888
WAIVED CHARGE TOTAL: 00000009999
SERVICE CHARGE TOTAL: 00000002654
SERVICE CHARGE TOTAL: 00000008734
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Thu May 16, 2019 4:30 am
Reply with quote

Use INREC instead of OUTREC and make a use of EDIT at sum.INCLUDE is wrong and why it’s there at first place ?

Think about SECTIONS.
Back to top
View user's profile Send private message
chillmo

New User


Joined: 31 Aug 2017
Posts: 30
Location: USA

PostPosted: Thu May 16, 2019 8:32 am
Reply with quote

Rohit,

Thanks for the info...I'm a step closer when I changed OUTREC to INREC; however, I changed the SUM Fields to
SUM FIELDS=(25,11,ZD,M4)
and received a WER268A error....basically stating edit masks cannot be used in a SUM statement.

Also, I need the include clause as the records I need summed have 98 starting in position 2 (but it should be length of 2 NOT 4...sorry). I'm NOT as familiar with Sections but will read the manual and research this on the internet.

Thanks!
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Thu May 16, 2019 8:37 am
Reply with quote

Look at the input records you shared to us. Where is it showing 98 in it starting at 2 ?
If you want to use include on summed value then you need to use OUTFIL and INCLUDE. This current include will be applied prior to SUM.

You can use Edit in outrec build instead of using it in SUM FIELDS.
Back to top
View user's profile Send private message
chillmo

New User


Joined: 31 Aug 2017
Posts: 30
Location: USA

PostPosted: Thu May 16, 2019 9:12 am
Reply with quote

Rohit,

Now I get a S0C7 when I added the following code (to add dollars and cents to my totals):

Code:

SORT FIELDS=(1,1,CH,A)                                           
INREC IFTHEN=(WHEN=(1,1,CH,EQ,C'2'),                             
OVERLAY=(1:C'SERVICE CHARGE TOTAL: ',2X,25:34,11,ZD,             
                                 EDIT=($III,III,III.II),42X)),   
       IFTHEN=(WHEN=(1,1,CH,EQ,C'3'),                             
OVERLAY=(1:C'GENERAL LEDGER TOTAL: ',2X,25:30,11,ZD,             
                                 EDIT=($III,III,III.II),42X))     
SUM  FIELDS=(25,11,ZD)                                           
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Thu May 16, 2019 9:15 am
Reply with quote

Instead of ZD use UFF OR SFF and you need to do that EDIT in OUTREC after SUM FIELDS and not in INREC.
INREC is only to rearrange SUM positions at same place nothing else. Do all the EDITS in OUTREC BUILD.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Thu May 16, 2019 8:57 pm
Reply with quote

Try this.
Code:
//SORTIN    DD *                                           
134569999                                                   
134568888                                                   
299993332654                                               
299995448734                                               
//SORTOUT   DD SYSOUT=*                                     
//SYSIN     DD *                                           
   OPTION COPY                                             
   INREC IFTHEN=(WHEN=(1,1,CH,EQ,C'1'),                     
       OVERLAY=(80:C'WAIVED CHARGE TOTAL : ',150:06,04)),   
         IFTHEN=(WHEN=(1,1,CH,EQ,C'2'),                     
       OVERLAY=(80:C'SERVICE CHARGE TOTAL: ',150:09,04))   
    OUTFIL REMOVECC,NODETAIL,                               
    SECTIONS=(1,1,                                         
    TRAILER3=(80,21,TOT=(150,04,ZD,EDIT=($IIIIIT.TT))))       


Output:
Code:
WAIVED CHARGE TOTAL :   $188.87
SERVICE CHARGE TOTAL:   $113.88
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Thu May 16, 2019 9:02 pm
Reply with quote

chillmo wrote:
Hello world.

I'm trying to sum records with amounts in different positions based on the first character of the file. Can this be accomplished in SyncSort?

OMG!!!

If you really need to summarize values within groups (are the records already grouped as needed? are there always only two groups in your data? Are there always only two records in each group?) - then you need to use the statement
OUTFIL …,SECTIONS=(…)

With the statement SUM you can only get a single sum of values through all your table/file/dataset, not separated by groups.

P.S.
Did you ever read ANY SORT manual in your life?

This topic looks like
Quote:
I'm trying to organize a mission to Mars with different equipment sent to the planet. Can this be accomplished in my company?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Join multiple records using splice DFSORT/ICETOOL 5
Search our Forums:

Back to Top