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

How to read a decimal variable in Cobol ?


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

New User


Joined: 15 Dec 2008
Posts: 33
Location: Chennai

PostPosted: Wed Sep 14, 2011 4:39 pm
Reply with quote

How to read a decimal variable in Cobol ?

I have some reports to read. Those reports will have values like

-1010.24

I tried reading this value like PIC S9(4)V9(2).

When tried like this the job is not running fine. I guess it is not accepting with the dots. How can i read this variable ?
Back to top
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Wed Sep 14, 2011 5:19 pm
Reply with quote

Hi,

Please read this link. Might be helpful.

www.3480-3590-data-conversion.com/article-reading-cobol-layouts-4.html


In my opinion,

you can use, SIGN IS LEADING SEPARATE.

Thanks !
Back to top
View user's profile Send private message
preethan
Warnings : 1

New User


Joined: 15 Dec 2008
Posts: 33
Location: Chennai

PostPosted: Wed Sep 14, 2011 5:54 pm
Reply with quote

rgupta71 wrote:
Hi,

Please read this link. Might be helpful.

www.3480-3590-data-conversion.com/article-reading-cobol-layouts-4.html


In my opinion,

you can use, SIGN IS LEADING SEPARATE.

Thanks !


I tried running this.. it is still not working fine.. icon_cry.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Sep 14, 2011 6:33 pm
Reply with quote

too bad
Back to top
View user's profile Send private message
preethan
Warnings : 1

New User


Joined: 15 Dec 2008
Posts: 33
Location: Chennai

PostPosted: Wed Sep 14, 2011 6:57 pm
Reply with quote

dbzTHEdinosauer wrote:
too bad


Can some one help me in this ??

For time being I have planned to read the numbers before the decimal point and the numbers after the decimal point in two different variables and divide the latter with 100 and add it with the former one. If a negative sign is there i will multiply it by -1.

It is not a good programming at all. Please help if anyone knows a better way.
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: Wed Sep 14, 2011 7:24 pm
Reply with quote

Search the fourm/look in the manuals for the intrinsic function NUMVAL and see if you can get that to work.
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: Wed Sep 14, 2011 8:02 pm
Reply with quote

If your COBOL version/release is a minimum of COBOL/370 (early 1990's) -

Code:

03  WS-EDIT-VALUE PIC -9(04).99 VALUE -1010.24.

03  WS-DISPLAY PIC S9(04)V99.

03  WS-PACKED PIC S9(05)V99 COMP-3.

MOVE WS-EDIT-VALUE TO WS-DISPLAY.
MOVE WS-DISPLAY TO WS-PACKED.

The value in WS-DISPLAY equals X'F1F0F1F0F2D4' (The X'D4' (C'M') indicates a negative value (the X'D' zone-nibble), also known as an overpunch). Character value ===> C'10102M'.

If you then moved WS-DISPLAY to WS-PACKED, the result would be X'0000000101024D' (negative 101024).

Mr. Bill
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Sep 14, 2011 8:11 pm
Reply with quote

Hello,

Quote:
When tried like this the job is not running fine.
Quote:
Can some one help me in this ??
As you have been a member for nearly 3 years, i'm sure you've seen us tell people they should NOT post "it didn't work". . . All this is is a waste of everyone's time.

You need to post what happened so someone here has a chance to help from the beginning. . .
Back to top
View user's profile Send private message
cyrus.e.cabrera

New User


Joined: 25 Jul 2011
Posts: 14
Location: Philippines

PostPosted: Thu Oct 27, 2011 11:02 am
Reply with quote

move the value of "that" variable to a printing variable.

to display 123456789 to 123,456,789

try pic zzz,zzz,zz9.

and the rest needs to be searched. icon_biggrin.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Oct 28, 2011 5:27 am
Reply with quote

Hello,

Please post only things that have been tested. . .

This will not handle the leading minus (-). . .
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Oct 30, 2011 7:57 pm
Reply with quote

Hi Preethan,

If you're reading report data, try using the field definitions of the pgm that created the report in your pgm(they s/b numeric edited).

After they're read into the edited fields, move them to a work field large enough and with enough decimal places to accommodate the largest of them. They're now ready for arithmetic operations.

This is the safest approach. If you can't/won't use the originating report's defs, you can create your own.
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top