View previous topic :: View next topic
|
Author |
Message |
lanand_hps
New User
Joined: 05 Dec 2007 Posts: 82 Location: chennai
|
|
|
|
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 |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
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 |
|
|
karthikr44
Active User
Joined: 25 Aug 2007 Posts: 235 Location: Chennai
|
|
|
|
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 |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
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 |
|
|
karthikr44
Active User
Joined: 25 Aug 2007 Posts: 235 Location: Chennai
|
|
|
|
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 |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
Back to top |
|
|
lanand_hps
New User
Joined: 05 Dec 2007 Posts: 82 Location: chennai
|
|
|
|
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
lanand_hps
New User
Joined: 05 Dec 2007 Posts: 82 Location: chennai
|
|
|
|
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 |
|
|
lanand_hps
New User
Joined: 05 Dec 2007 Posts: 82 Location: chennai
|
|
|
|
Sorry guys..
It is of 6 digits..as Frank pointed out.. 20th to 25th column.
One more doubt. ((Please spare me )
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 .. Kindly give your comments.. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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. |
is invalid syntax. It will result in an error message. |
|
Back to top |
|
|
lanand_hps
New User
Joined: 05 Dec 2007 Posts: 82 Location: chennai
|
|
|
|
Thanks a lot Frank .! |
|
Back to top |
|
|
ksouren007
New User
Joined: 30 Jun 2010 Posts: 85 Location: Toronto, ON
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
Back to top |
|
|
|