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

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


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sreejeshcs

New User


Joined: 28 May 2007
Posts: 31
Location: Pune

PostPosted: Mon Oct 29, 2012 2:54 pm
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: 31
Location: Pune

PostPosted: Mon Oct 29, 2012 3:04 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Oct 29, 2012 3:26 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Oct 29, 2012 3:42 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Oct 29, 2012 3:44 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Oct 29, 2012 3:51 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Oct 29, 2012 3:57 pm
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: 31
Location: Pune

PostPosted: Mon Oct 29, 2012 6:33 pm
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: 31
Location: Pune

PostPosted: Mon Oct 29, 2012 6:34 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Oct 29, 2012 6:59 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon Oct 29, 2012 7:15 pm
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: 31
Location: Pune

PostPosted: Mon Oct 29, 2012 7:38 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Oct 29, 2012 8:01 pm
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: 31
Location: Pune

PostPosted: Mon Oct 29, 2012 8:53 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Oct 29, 2012 9:03 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
Search our Forums:

Back to Top