View previous topic :: :: View next topic

Author 
Message 
ramco_sita
New User
Joined: 25 Jun 2007 Posts: 40 Location: chennai




I would like to know in cobol how we can move a string variable value (1199.99) to decimal variable 9(4)v9(2).
We pass this to commarea as a string and then we need to move it to the integer .
looking forward for a solution .. 

Back to top 




kbmkris
Active User
Joined: 24 Jun 2006 Posts: 101




Hi,
It is sufficient if you just move the string to a numeric variable.
Code: 
77 WSA PIC X(5) VALUE '119.94'.
77 WSB PIC 9(3)V9(2) VALUE ZEROS.
....
....
MOVE WSA TO WSB.
...
...

As long as your string variable contains only numeric, you can move that directly. But if the length of the number in the string doesn't match with that of the numeric variable then truncation happens when the destination variable is of small length.
Please correct me if I am wrong. 

Back to top 


kbmkris
Active User
Joined: 24 Jun 2006 Posts: 101




Hi,
I apologize that the above one is not working properly when the number contains decimals. 

Back to top 


agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 686 Location: Earth




FUNCTION NUMVAL will do what you are trying to achieve here.. 

Back to top 


amrita.chatterjee
New User
Joined: 27 Apr 2006 Posts: 48 Location: Bangalore, India




Another solution, u just split the total number into two parts. One integer and another decimal, & then move it to numeric part.
Steps: Use DELIMITED BY . into STR1 & STR2.
So if the string is 1234.55 then STR1 will contain 1234
STR2 will contain 55
Then define variable like
STR1 to NUM1(9(04)
STR2 to NUM2(9(02)
then u can merge it. May be this a very large process.
If i'm wrong then please correct me. 

Back to top 


sandeep1dimri
New User
Joined: 30 Oct 2006 Posts: 76




Hi ,
you can use this approach also
suppose var1= ' 89.89'
replace the spaces of var1 by zeros
Code: 
Inspect var1 replace all ' ' by 0 
then
move Var1 to variable 9(4)v9(2)
Thanks
sandeep 

Back to top 


dick scherrer
Site Director
Joined: 23 Nov 2006 Posts: 19270 Location: Inside the Matrix




Hello,
If you unstring the field with the actual '.' into 2 PIC X variables that are redefined as zoned decimal, it makes things very easy when the "pennies" part of the amount is defined as v99. Simply adding the 2 zoneddecimal pieces gets the proper value into a packed or zoned decimal field with an implied decimal. 

Back to top 


CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2150 Location: At my coffee table




Ignoring the sign and decimal point alignment,......
E x(??) value '(1199.99)'
N 9(??)
I comp
J comp
move length of E ro I
move length of N to J
perform varying I by 1 until I = zero
if E(I:1) numeric
move E(I:1) to N(J:1)
subtract 1 from J
endif
endperform
move zeros to N(1:J) 

Back to top 


