Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
ramco_sita

New User

Joined: 25 Jun 2007
Posts: 40
Location: chennai

 Posted: Thu Sep 13, 2007 10:50 am    Post subject: String to decimal conversion in cobol 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 ..

kbmkris

Active User

Joined: 24 Jun 2006
Posts: 101

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

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.
kbmkris

Active User

Joined: 24 Jun 2006
Posts: 101

 Posted: Thu Sep 13, 2007 11:39 am    Post subject: Hi, I apologize that the above one is not working properly when the number contains decimals.
agkshirsagar

Active Member

Joined: 27 Feb 2007
Posts: 686
Location: Earth

 Posted: Thu Sep 13, 2007 12:17 pm    Post subject: FUNCTION NUMVAL will do what you are trying to achieve here..
amrita.chatterjee

New User

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

 Posted: Thu Sep 13, 2007 2:33 pm    Post subject: Reply to: String to decimal conversion in cobol 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.
sandeep1dimri

New User

Joined: 30 Oct 2006
Posts: 76

Posted: Thu Sep 13, 2007 3:38 pm    Post subject:

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
dick scherrer

Site Director

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

 Posted: Thu Sep 13, 2007 8:07 pm    Post subject: 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.
CICS Guy

Senior Member

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

 Posted: Thu Sep 13, 2007 8:19 pm    Post subject: 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)
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics line 52: Name or string > 250 char... Ashishpanpaliya CLIST & REXX 5 Sat Oct 14, 2017 2:29 am IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm Extend the decimal values in DIVISION Balaryan DFSORT/ICETOOL 3 Thu Oct 05, 2017 4:05 pm Assembler Macro Copybook converted to... Ziquilix PL/I & Assembler 4 Tue Sep 26, 2017 3:07 am Search for a string in many PDS KARTHIGADEVI CLIST & REXX 5 Fri Sep 08, 2017 2:32 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us