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 

SUM function in JCL

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


Joined: 22 Dec 2002
Posts: 64
Topics: 28
Location: Chennai

PostPosted: Mon Apr 10, 2006 7:23 pm    Post subject: SUM function in JCL Reply with quote

Please let me know how to do the SUM function in JCL. I have both positive and negative values are there in my input.

I am using the following statement for doing the sum.
Code:

SORT FIELDS=(24,16,CH,A,68,5,CH,A,112,4,CH,A,118,2,CH,A)
OUTREC FIELDS=(1:112,4,5:118,2,7:24,16,23:68,5,28:225,12,ZD,
EDIT=(STTTTTTTTTTT),SIGNS=(+,-,,))
SUM FIELDS=(225,12),FORMAT=ZD

Alwyas i am getting the output as positive amount

eg: -1000 + 500 = 1500

I am not getting the sum as -500 (suppose to be).

Please let me know what is wrong in my above statement.


Regards,
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Apr 10, 2006 9:24 pm    Post subject: Reply with quote

Ranjish,

You cannot sum the display numeric items using ZD format. You either need to convert them to PD format or have the sign on the last nibble of zd format.

If you have latest version of DFSORT then you can use SFF/FS format to get the desired results.

Signed zoned decimal numbers have sign on the last nibble like as shown below.

ex:

Code:

**********************************************************************
*      1 - A          -1 - J     EXAMPLES:  NUMBER    REPRESENTATION *
*      2 - B          -2 - K                  10        00000001{    *
*      3 - C          -3 - L                 105        00000010E    *
*      4 - D          -4 - M                   0        00000000{    *
*      5 - E          -5 - N                -234        00000023M    *
*      6 - F          -6 - O                 -30        00000003}    *
*      7 - G          -7 - P                                         *
*      8 - H          -8 - Q                                         *
*      9 - I          -9 - R                                         *
*      0 - {          -0 - }                                         *
**********************************************************************


That is how the signed zoned decimal are reprenstated. Check this link which shows about summing such numbers

http://mvsforums.com/helpboards/viewtopic.php?t=5686&highlight=numeric

Another option is convert the floating sign numbers into packed decimal fields using and Summing on them

try this


Code:

INREC FIELDS=(001,224,
              225,12,FS,PD,LENGTH=8)
 
SORT FIELDS=(024,16,CH,A,
             068,05,CH,A,
             112,04,CH,A,
             118,2,CH,A)

SUM FIELDS=(225,8),FORMAT=PD

OUTREC FIELDS=(01:112,04,
               05:118,02,
               07:024,16,
               23:068,05,
               28:225,8,ZD,EDIT=(STTTTTTTTTTT),SIGNS=(+,-,,))




Hope this helps...

Cheers

Kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Ranjish
Beginner


Joined: 22 Dec 2002
Posts: 64
Topics: 28
Location: Chennai

PostPosted: Tue Apr 11, 2006 2:52 am    Post subject: Reply with quote

Kolusu,

When i used the below code for doing the SUM, I am getting a S0C7 exception.

Code:

//SYSIN    DD  *
 INREC FIELDS=(001,224,
               225,12,FS,PD,LENGTH=8)

 SORT FIELDS=(024,16,CH,A,
              068,05,CH,A,
              112,04,CH,A,
              118,2,CH,A)
 SUM FIELDS=(225,8),FORMAT=PD
 OUTREC FIELDS=(01:112,04,
                05:118,02,
                07:024,16,
                23:068,05,
                28:225,8,ZD,EDIT=(STTTTTTTTTTT),SIGNS=(+,-,,))
/*


My input file field value is like this

BB-NET-UNITS
12/AN
(225-236)
************

Code:

 00000046000
-00000084000



Please help me to identify what is wrong here?

Thanks.
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Tue Apr 11, 2006 3:52 am    Post subject: Reply with quote

Ranjish,

Check your outrec statement. You had converted your input amount from FS format to PD (Packed Decimal) format at location 225 but in OUTREC you refer it as ZD (Zoned Decimal)

Change this code
Code:

28:225,8,ZD,EDIT=(STTTTTTTTTTT),SIGNS=(+,-,,))


To
Code:

28:225,8,PD,EDIT=(STTTTTTTTTTT),SIGNS=(+,-,,))


Hope this helps,

Thanks,
Phantom
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: Tue Apr 11, 2006 10:17 am    Post subject: Reply with quote

Here's another way to do it with DFSORT:

Code:

//S2    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD DSN=...  input file
//SORTOUT DD DSN=...  output file
//SYSIN    DD    *
* Create one contiguous key at end of record for SECTIONS.
  INREC OVERLAY=(237:24,16,68,5,112,4,118,2)
* Sort on the contiguous key.
  SORT FIELDS=(237,27,CH,A)
  OUTFIL REMOVECC,NODETAIL,
* Ensure output length is 39.
   BUILD=(39X),
* Use contiguous key as break field.
   SECTIONS=(237,27,
* Use TOT with SFF to get total.
     TRAILER3=(01:112,04,
       05:118,02,
       07:024,16,
       23:068,05,
       28:TOT=(225,12,SFF,EDIT=(STTTTTTTTTTT),SIGNS=(+,-,,))))
/*

_________________
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
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities 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