Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
sreejeshcs

New User

Joined: 28 May 2007
Posts: 31
Location: Pune

Posted: Mon Oct 29, 2012 2:54 pm    Post subject: How to add and multiply 2 fileds using SORT or ICE TOOL

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

sreejeshcs

New User

Joined: 28 May 2007
Posts: 31
Location: Pune

Posted: Mon Oct 29, 2012 3:04 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE

One correction:
Expected output:
 Code: AMT-USD           DISPLAY 0000000000000020A                            17/SNUM 0                        AMT-LCL           DISPLAY 0000000000014348Q                   17/SNUM -1434.88

Code'd
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10562
Location: italy

Posted: Mon Oct 29, 2012 3:26 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE

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 ********************************
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

 Posted: Mon Oct 29, 2012 3:42 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE LCL looks like Local Currency, USD looks like US Dollars. How could you add them together, or are they just badly-named?
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10562
Location: italy

 Posted: Mon Oct 29, 2012 3:44 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE there is some kind of multiplication by 12...
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

 Posted: Mon Oct 29, 2012 3:51 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE 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 :-)
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10562
Location: italy

 Posted: Mon Oct 29, 2012 3:57 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE 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
sreejeshcs

New User

Joined: 28 May 2007
Posts: 31
Location: Pune

 Posted: Mon Oct 29, 2012 6:33 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE Is it possible to multiply with +12.9469 ?
sreejeshcs

New User

Joined: 28 May 2007
Posts: 31
Location: Pune

Posted: Mon Oct 29, 2012 6:34 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE

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
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

 Posted: Mon Oct 29, 2012 6:59 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE 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.
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10562
Location: italy

 Posted: Mon Oct 29, 2012 7:15 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE as I said before ... 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 .
sreejeshcs

New User

Joined: 28 May 2007
Posts: 31
Location: Pune

 Posted: Mon Oct 29, 2012 7:38 pm    Post subject: 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?
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

 Posted: Mon Oct 29, 2012 8:01 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE 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.
sreejeshcs

New User

Joined: 28 May 2007
Posts: 31
Location: Pune

 Posted: Mon Oct 29, 2012 8:53 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE How can I code the rounding logic? any example?
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

 Posted: Mon Oct 29, 2012 9:03 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE 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".
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Build SQL query using SORT balaji81_k DFSORT/ICETOOL 0 Mon Feb 18, 2019 9:56 am Build Dynamic Sort output and limit '... balaji81_k DFSORT/ICETOOL 2 Sat Feb 02, 2019 4:40 am PARAMETER 'F1' IS UNIDENTIFIED error ... Poha Eater DFSORT/ICETOOL 14 Fri Feb 01, 2019 2:39 pm SORT INNER JOIN [F1] OUT OF SEQ ERROR balaji81_k DFSORT/ICETOOL 8 Wed Jan 30, 2019 3:21 am Dates compare on specific dates using... balaji81_k DFSORT/ICETOOL 2 Thu Jan 24, 2019 12:03 am

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us