View previous topic :: View next topic
|
Author |
Message |
sreejeshcs
New User
Joined: 28 May 2007 Posts: 31 Location: Pune
|
|
|
|
Hi,
I have to do the following.
My current Data:
0000000000000020A0000000000014590}
using the above data in Copybook:
Code: |
AMT-USD DISPLAY 0000000000000020A
17/SNUM 2.01
AMT-LCL DISPLAY 0000000000014590}
17/SNUM -1459.00 |
Expected output:
Code: |
AMT-USD DISPLAY 0000000000000020A
17/SNUM 0
AMT-LCL DISPLAY 0000000000014590}
17/SNUM -1434.88 |
Formula is
Code: |
AMT-LCL = AMT-LCL + (AMT-USD * 12) |
Code'd |
|
Back to top |
|
|
sreejeshcs
New User
Joined: 28 May 2007 Posts: 31 Location: Pune
|
|
|
|
One correction:
Expected output:
Code: |
AMT-USD DISPLAY 0000000000000020A
17/SNUM 0
AMT-LCL DISPLAY 0000000000014348Q
17/SNUM -1434.88 |
Code'd |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
DFSORT arithmetics does not take into account the decimal digits....
You will have to normalize Yourself to the proper number of decimal places
and ....
here is a snippet for the ARITHMETICS
Code: |
000003 //*
000004 //ICE EXEC PGM=SORT
000005 //SYSPRINT DD SYSOUT=*
000006 //SYSOUT DD SYSOUT=*
000007 //SORTIN DD *
000008 000000020A000014590}
000009 //SORTOUT DD SYSOUT=*
000010 //SYMNAMES DD *
000011 USD,01,10,ZD
000012 LCL,11,10,ZD
000013 TMP,21,10,ZD
000014 //SYSIN DD *
000015 OPTION COPY
000016 INREC OVERLAY=(21:USD,MUL,+12,TO=ZD,LENGTH=10,
000017 31:LCL,ADD,TMP,TO=ZD,LENGTH=10) |
the result
Code: |
********************************* TOP OF DATA **********************************
000000020A000014590}0000002412000014348Q
******************************** BOTTOM OF DATA ******************************** |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
LCL looks like Local Currency, USD looks like US Dollars. How could you add them together, or are they just badly-named? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
there is some kind of <conversion> multiplication by 12... |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes, there is a multiply, but it is a constant, not something that can be an exchange rate. Like a montly interest amount expressed for a year. We see :-) |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
also the displays are not consistent
the hex says 2.01
the display says 0
who will ever know ?
the TS should be able to elucubrate himself from the snippet posted |
|
Back to top |
|
|
sreejeshcs
New User
Joined: 28 May 2007 Posts: 31 Location: Pune
|
|
|
|
Is it possible to multiply with +12.9469 ? |
|
Back to top |
|
|
sreejeshcs
New User
Joined: 28 May 2007 Posts: 31 Location: Pune
|
|
|
|
I am getting the below Error.
Code: |
SYSIN :
OPTION COPY
INREC OVERLAY=(48:31,17,ZD,MUL,+12.9469,TO=ZD,LENGTH=17)
*
WER268A INREC STATEMENT : SYNTAX ERROR |
Code'd |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Well, I guess it wasn't 12 months in a year then :-)
It must be a quick thing to just hit the manual and see how constants can be defined, and how not.
EDIT: So, by now you've got the answer No. As enrico already pointed out to you, fields in Sort don't have decimals. Note (now that we know you have decimals) that Sort does not do "rounding", but truncates.
To continue on your Sort route you'll need to do all the "alignment" of decimal places through calculations of whole numbers, including allowing sufficient "significance" for intermediate values, then do you own "rounding" if needed.
If you are sorting the file anyway, it would be less error-prone to use a Cobol "EXIT" to do the calculation there. E15 or E35. Consult your manual. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
as I said before ...
<SORT> any flavor does not know about decimal digits(places)
You need to normalize to the max number of decimal digits
( probably a couple more to provide for rounding issues )
since the TS uses SYNCSORT the topic should be moved where it belongs . |
|
Back to top |
|
|
sreejeshcs
New User
Joined: 28 May 2007 Posts: 31 Location: Pune
|
|
|
|
I have added 12946I to the I/P file
New layout:
0000000000002378N0000000000000000{12946I
OPTION COPY
INREC OVERLAY=(18:1,17,ZD,MUL,35,06,ZD,TO=ZD,LENGTH=17)
Result:
0000000000002378N0000000307942016N12946I
next Sort to correct the decimal places.
INREC OVERLAY=(18:18,17,ZD,DIV,+10000,TO=ZD,LENGTH=17)
Result is:
0000000000002378N0000000000030794K
Any hope to round the result to 2 decimals? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you want to do it in Sort, you have to code the rounding yourself. You have four decimals on one, two decimals on the other. Get the user (to get the accountant responsible) to show you how they want it rounded, then code it from there. |
|
Back to top |
|
|
sreejeshcs
New User
Joined: 28 May 2007 Posts: 31 Location: Pune
|
|
|
|
How can I code the rounding logic? any example? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Once you have it confirmed what is wanted, it is just a question of testing the byte(s) which will be "rounded" to fit with what is desired.
Ie, if digit after required decimal is "5" or higher, add one to required decimal.
Can't be more exact until you know what is wanted for "rounding". |
|
Back to top |
|
|
|