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

Sum FIELDS with decimal


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Fri Aug 01, 2008 5:07 pm
Reply with quote

Hi,
Can we sum fields with decimals?
The input file is like...

(column 3) (column 68)
003042193 0000009.08
003042193 0000009.08
003042193 0000009.08
007505628 0000001.73
007505628 0000001.73
007505628 0000001.73

I need to sum the amount fields which starts from 68th column and is of 10 digits including decimal. How do we do it?

I'm getting S0C7 if i use the control card mentioned below.
SORT FIELDS=(3,9,CH,A)
SUM FIELDS=(68,10,ZD)

Please comment.
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Fri Aug 01, 2008 6:52 pm
Reply with quote

You need to move the digits to a work-field, dropping the decimal. Then SUM the work-field and edit, if required to reinstate the decimal, to output field.

Where do you want to put the result of the SUM ?

Regards,
Garry
Back to top
View user's profile Send private message
karthikr44

Active User


Joined: 25 Aug 2007
Posts: 235
Location: Chennai

PostPosted: Fri Aug 01, 2008 6:54 pm
Reply with quote

Hi,

You can use FL format for floating point numbers. That itself
u can use only 4, 8, or 16 bytes. i.e. u can use

SUM FIELDS=(11,16,FL)

But not

SUM FIELDS=(11,15,FL)

Regards
R KARTHIK
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Fri Aug 01, 2008 7:00 pm
Reply with quote

Quote:
You can use FL format for floating point numbers.


Perhaps, but that's not what the O/P asked for. Floating-point is a totally different kettle of fish to what is described.

Garry.
Back to top
View user's profile Send private message
karthikr44

Active User


Joined: 25 Aug 2007
Posts: 235
Location: Chennai

PostPosted: Fri Aug 01, 2008 7:04 pm
Reply with quote

Hi,

I posted because the reason for SOC7 abend is he is using ZD format
for numbers like 0002.3

Regards
R KARTHIK
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Fri Aug 01, 2008 7:08 pm
Reply with quote

Hi,

Yes, he is. but treating the numbers like 0002.3 as floating point won't solve his problem - he'd have to first change the format of the data to floating point.

Regards,
Garry.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


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

PostPosted: Fri Aug 01, 2008 8:56 pm
Reply with quote

Karthik,

FL is floating point format for numbers with a characteristic and fraction. It has nothing to do with values like 'ddddddd.dd' that the OP is asking about - you could have looked up FL format at:

publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ICE1CA20/C.1?DT=20060615185603

lanand_hps,

You can use the technique discussed in the "Sum a number with a decimal point" Smart DFSORT Trick at:

www.ibm.com/support/docview.wss?rs=114&uid=isg3T7000094
Back to top
View user's profile Send private message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Fri Aug 01, 2008 10:34 pm
Reply with quote

Thanks Frank.
I had created a jcl with two steps to sum the digits with decimal points. First step to remove decimal and treat that as a ZD. Second step to inser the decimal point in the appropriate postion.
FL didnot work.
But one more clarification.
Under what scenarios can we use PD?
For test purpose, i had 3 records in my postion with a packed decimal from 20th postion till 25th.

SORT FIELDS=(107,9,CH,A)
SUM FIELDS=(20,5,PD)

It is resulting in S0C7. Any details?
I checked the input file and it had proper values.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Aug 01, 2008 10:41 pm
Reply with quote

lanand_hps wrote:
Thanks Frank.
I had created a jcl with two steps to sum the digits with decimal points. First step to remove decimal and treat that as a ZD. Second step to inser the decimal point in the appropriate postion.
FL didnot work.
But one more clarification.
Under what scenarios can we use PD?
For test purpose, i had 3 records in my postion with a packed decimal from 20th postion till 25th.

SORT FIELDS=(107,9,CH,A)
SUM FIELDS=(20,5,PD)

It is resulting in S0C7. Any details?
I checked the input file and it had proper values.


Show us the hex display of the records.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


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

PostPosted: Fri Aug 01, 2008 10:47 pm
Reply with quote

lanand_hps,

You can only use PD for valid packed decimal data which has the following form in hex:

dd...ds

where d is a digit (0-9) and s is a sign (usually C or F for + or D for -).

For example:

12345C is the PD equivalent of +12345
00030D is the PD equivalent of -30

If you try to SUM with PD for values that are NOT PD, you will get an 0C7 ABEND.

Note that PD values do NOT contain a decimal point internally.

Quote:
For test purpose, i had 3 records in my postion with a packed decimal from 20th postion till 25th.

SORT FIELDS=(107,9,CH,A)
SUM FIELDS=(20,5,PD)


20-25 is 6 bytes, but you are using 20,5,PD instead of 20,6,PD. If you got an 0C7 ABEND, then the 5 bytes from 20-24 contain invalid PD data.

You can use the VERIFY operator of DFSORT's ICETOOL to display invalid PD values.
Back to top
View user's profile Send private message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Fri Aug 01, 2008 10:54 pm
Reply with quote

Hi Craq,
This is how the file is now...

Code:
                         decimal
                          ------
000001 2003941297 07353LAD    °ðVOL-HERTZW 
       FFFFFFFFFF4FFFFFDCC000098EDD6CCDEEE44
       200394129700735331400000C563085939600
--------------------------------------------
000002 2003941297 07354LAD      VOL-HERTZW 
       FFFFFFFFFF4FFFFFDCC000013EDD6CCDEEE44
       200394129700735431400007C563085939600
--------------------------------------------
Back to top
View user's profile Send private message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Fri Aug 01, 2008 11:03 pm
Reply with quote

Sorry guys..
It is of 6 digits..as Frank pointed out.. 20th to 25th column.
One more doubt. ((Please spare me icon_smile.gif )

I have read in a lot of places that
Statement 1:
SORT FIELDS=COPY
SUM FIELDS=NONE will remove the duplicates.
Statement 2:
SORT FIELDS=NONE will also avoid duplicates.

When i just tested it, the duplicates are not getting removed with the first statement and statement 2 is throwing an error.

I guess it is a very basic doubt icon_sad.gif .. Kindly give your comments..
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Aug 01, 2008 11:08 pm
Reply with quote

You either need to use 21,5,PD or 20,6,PD because the byte of the PD is in position 25 not 24.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


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

PostPosted: Fri Aug 01, 2008 11:27 pm
Reply with quote

Quote:
Sorry guys..
It is of 6 digits..as Frank pointed out.. 20th to 25th column.


When I run with your data and use 20,6,PD, it works. When I run using 20,5,PD, it gets an 0C7 ABEND as expected because the sign is invalid in that case.

Quote:
I have read in a lot of places that
Statement 1:
SORT FIELDS=COPY
SUM FIELDS=NONE will remove the duplicates.


I don't know where you read that, but it wasn't written by anyone who knew what they were talking about.

SUM FIELDS=NONE can remove duplicates with:

Code:

  SORT FIELDS=(p,m,f,s,...) or
  MERGE FIELDS=(p,m,f,s,...)


SUM FIELDS=NONE cannot remove duplicates with:

Code:

  SORT FIELDS=COPY or
  MERGE FIELDS=COPY or
  OPTION COPY


SUM FIELDS=NONE is only valid for sorting or merging, not for copying. SUM FIELDS=NONE removes records with duplicate keys. Since copy does NOT specify a key, SUM FIELDS=NONE cannot be used to remove duplicates when copying. Sort and Merge specify a key, so SUM FIELDS=NONE can be used to remove duplicates when sorting or merging.

Quote:

Statement 2:
SORT FIELDS=NONE will also avoid duplicates.


Code:

   SORT FIELDS=NONE 


is invalid syntax. It will result in an error message.
Back to top
View user's profile Send private message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Fri Aug 01, 2008 11:44 pm
Reply with quote

Thanks a lot Frank .!
Back to top
View user's profile Send private message
ksouren007

New User


Joined: 30 Jun 2010
Posts: 85
Location: Toronto, ON

PostPosted: Tue Jan 18, 2011 4:49 pm
Reply with quote

Hi Frank,

The below link is no longer working. Could you please provide an alternate link for the document?

" You can use the technique discussed in the "Sum a number with a decimal point" Smart DFSORT Trick at: "

Use [URL] BBCode for External Links
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


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

PostPosted: Wed Jan 19, 2011 12:21 am
Reply with quote

I posted that link back in 2008. It changed later to:

www.ibm.com/support/docview.wss?rs=114&uid=isg3T7000094

I've updated the link in the original post.
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Need Help with Packed Decimal Signs DFSORT/ICETOOL 4
No new posts Select a DB2 value in a specific deci... DB2 4
No new posts String has hex character need to conv... COBOL Programming 3
No new posts How to display the leading zeros of a... DB2 7
Search our Forums:

Back to Top