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

Regarding percent to value convertion


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ram_vizag

Active User


Joined: 21 Aug 2008
Posts: 112
Location: hyd

PostPosted: Thu Dec 12, 2013 1:52 pm
Reply with quote

Hi,

I have a value in pic x(5)(percent value ex: 13.33) which come as input from cics and should be update into the table with pic S9(1)V9(5) comp-3

I should divide the 13.33 by 100 and update value into table.
first i have to move the percent to s9(2)v99) and divided and updated in table

is the following works?????? pleas suggest i cant test roght now the code....
Code:

01 ws-percent       pic x(05) value 13.33.----this i'll get from cics which is declared as x(05) in the map.
01 WS-BUS-COMMISSION.                                         
   05 WS-BUS-HUNDRED         PIC 9(03)  VALUE 100.             
   05 WS-BUS-COMM-PERCENT    PIC S9(2)V99 USAGE COMP-3.       
   05 WS-BUS-PERCENT-VALUE   PIC S9(1)V9(5) USAGE COMP-3.     

MOVE WS-PERCENT    TO WS-BUS-COMM-PERCENT
DIVIDE  WS-HUNDRED INTO    WS-BUS-COMM-PERCENT
                   GIVING  WS-BUS-PERCENT-VALUE



PLEASE SUGGEST WHETHER THE ABOVE IS CORRECT???
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Dec 12, 2013 2:58 pm
Reply with quote

Suggest you to try it when you find time and post your findings or problems or error you had got

Hint : Your code wont work as you expect
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Dec 12, 2013 3:35 pm
Reply with quote

Also

Can WS-PERCENT hold value like 1.333 or .1333?
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Thu Dec 12, 2013 3:56 pm
Reply with quote

Quote:
PLEASE SUGGEST WHETHER THE ABOVE IS CORRECT???

Why the CAPITALS? Very rude.

Why post in DB2 when it is a COBOL query that you have?

Why don't you get a COBOL compiler to run on your private machine then you could try such things at home.
Back to top
View user's profile Send private message
ram_vizag

Active User


Joined: 21 Aug 2008
Posts: 112
Location: hyd

PostPosted: Thu Dec 12, 2013 5:06 pm
Reply with quote

Pandora-Box wrote:
Also

Can WS-PERCENT hold value like 1.333 or .1333?



yes it can hold the value....i'm tryuing but not getting exactly need not divide here for this conversion simple have to declate the destination variable as to get populated as( 0.1234)
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Dec 12, 2013 5:51 pm
Reply with quote

What you need to do is something like below

Move x(5) to 9(5) without '.'
Reverse x(5)
Based on position of '.' in reverse of x(5) you need to divide by 10^(position -1)
so if x(5) has .1333
You need to store 01333 in 9(5) and divide by 10^4 ( 4 is becasue reverse of x(5) 3331. '.' in 5th position)
Divide the above result by 100
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Thu Dec 12, 2013 6:34 pm
Reply with quote

No DB2 involved!

and google COBOL Intrinsic FUNCTION NUMVAL()
Back to top
View user's profile Send private message
ram_vizag

Active User


Joined: 21 Aug 2008
Posts: 112
Location: hyd

PostPosted: Sun Dec 15, 2013 12:48 am
Reply with quote

Pandora-Box wrote:
What you need to do is something like below

Move x(5) to 9(5) without '.'
Reverse x(5)
Based on position of '.' in reverse of x(5) you need to divide by 10^(position -1)
so if x(5) has .1333
You need to store 01333 in 9(5) and divide by 10^4 ( 4 is becasue reverse of x(5) 3331. '.' in 5th position)
Divide the above result by 100


thanks Pandora,

i Have redefined the x(05) ---12.34 and conveterd to 99.99 and further converted,calculated to 9.99999====from this data type can i move to s9(3) comp-3 which is db2 field...currently i cant test...pls let me know...whether my idea is correct???
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Sun Dec 15, 2013 1:07 am
Reply with quote

If you ultimately need 9.9999

why convett to 99.99
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Sun Dec 15, 2013 1:47 am
Reply with quote

Introduced with COBOL/370 (some 18-20 years ago) and unofficially defined as "Deditting", it allows the movement of an edited field-value (redefined as PIC 99.99) to a PIC 9 unedited field, such as PIC 99V99.

Once you move it to the unedited field, then you can restart from scratch.

Prior to COBOL/370, this type of data-movement was not allowed.

HTH....
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts IBM DCW (data convertion workbench) IBM Tools 0
No new posts TIMESTAMP convertion from UTC to EST/... DB2 2
No new posts convertion of load to cobol source code COBOL Programming 5
No new posts Quotation Convertion in Sort JCL & VSAM 6
No new posts String convertion COBOL Programming 4
Search our Forums:

Back to Top