Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to add and multiply 2 fileds using SORT or ICE TOOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
View previous topic :: :: View next topic  
Author Message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 26
Location: Pune

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

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
View user's profile Send private message

sreejeshcs

New User


Joined: 28 May 2007
Posts: 26
Location: Pune

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

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

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

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Mon Oct 29, 2012 3:42 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Oct 29, 2012 3:44 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE
Reply with quote

there is some kind of <conversion> multiplication by 12...
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Mon Oct 29, 2012 3:51 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Oct 29, 2012 3:57 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE
Reply with quote

also the displays are not consistent

the hex says 2.01
the display says 0

who will ever know ? icon_wink.gif

the TS should be able to elucubrate himself from the snippet posted
Back to top
View user's profile Send private message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 26
Location: Pune

PostPosted: Mon Oct 29, 2012 6:33 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE
Reply with quote

Is it possible to multiply with +12.9469 ?
Back to top
View user's profile Send private message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 26
Location: Pune

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

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Mon Oct 29, 2012 6:59 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Mon Oct 29, 2012 7:15 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE
Reply with quote

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
View user's profile Send private message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 26
Location: Pune

PostPosted: Mon Oct 29, 2012 7:38 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Mon Oct 29, 2012 8:01 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE
Reply with quote

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
View user's profile Send private message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 26
Location: Pune

PostPosted: Mon Oct 29, 2012 8:53 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE
Reply with quote

How can I code the rounding logic? any example?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7225

PostPosted: Mon Oct 29, 2012 9:03 pm    Post subject: Reply to: How to add and multiply 2 fileds using SORT or ICE
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts How to delete second instance from Fl... Gunapala CN DFSORT/ICETOOL 6 Tue Oct 18, 2016 11:42 pm
No new posts abend sort based on count records in ... anatol DFSORT/ICETOOL 5 Mon Oct 17, 2016 10:10 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us