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
 

 

String to decimal conversion in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
ramco_sita

New User


Joined: 25 Jun 2007
Posts: 40
Location: chennai

PostPosted: Thu Sep 13, 2007 10:50 am    Post subject: String to decimal conversion in cobol
Reply with quote

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

kbmkris

Active User


Joined: 24 Jun 2006
Posts: 101

PostPosted: Thu Sep 13, 2007 11:27 am    Post subject: Reply to: String to decimal conversion in cobol
Reply with quote

Hi,

It is sufficient if you just move the string to a numeric variable.

Code:

77 WS-A         PIC X(5) VALUE '119.94'.
77 WS-B         PIC 9(3)V9(2) VALUE ZEROS.
....
....
MOVE WS-A TO WS-B.
...
...



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

Active User


Joined: 24 Jun 2006
Posts: 101

PostPosted: Thu Sep 13, 2007 11:39 am    Post subject:
Reply with quote

Hi,

I apologize that the above one is not working properly when the number contains decimals.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 686
Location: Earth

PostPosted: Thu Sep 13, 2007 12:17 pm    Post subject:
Reply with quote

FUNCTION NUMVAL will do what you are trying to achieve here..
Back to top
View user's profile Send private message
amrita.chatterjee

New User


Joined: 27 Apr 2006
Posts: 48
Location: Bangalore, India

PostPosted: Thu Sep 13, 2007 2:33 pm    Post subject: Reply to: String to decimal conversion in cobol
Reply with quote

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

New User


Joined: 30 Oct 2006
Posts: 76

PostPosted: Thu Sep 13, 2007 3:38 pm    Post subject:
Reply with quote

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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Sep 13, 2007 8:07 pm    Post subject:
Reply with quote

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 zoned-decimal pieces gets the proper value into a packed or zoned decimal field with an implied decimal.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Sep 13, 2007 8:19 pm    Post subject:
Reply with quote

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
end-if
end-perform
move zeros to N(1:J)
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 -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm
No new posts Search utility(3.14) using JCl and Cobol RKS3 COBOL Programming 12 Sat Jun 10, 2017 10:24 pm
No new posts COBOL DB2 program - zIIP eligible vasanthz COBOL Programming 7 Wed May 31, 2017 5:12 am
No new posts Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm


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