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
 

 

How to read a decimal variable in Cobol ?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to read a decimal variable in Cobol ?
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    Post subject:
Reply with quote

Hi,

Please read this link. Might be helpful.

http://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    Post subject:
Reply with quote

rgupta71 wrote:
Hi,

Please read this link. Might be helpful.

http://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    Post subject:
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Wed Sep 14, 2011 7:24 pm    Post subject: Reply to: How to read a decimal variable in Cobol ?
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Sep 14, 2011 8:02 pm    Post subject: Reply to: How to read a decimal variable in Cobol ?
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

Site Director


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

PostPosted: Wed Sep 14, 2011 8:11 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri Oct 28, 2011 5:27 am    Post subject:
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    Post subject: Reply to: How to read a decimal variable in Cobol ?
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    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
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am
No new posts Comparing Decimal and CHAR columns rakesh17684 DB2 7 Thu Oct 20, 2016 2:33 am


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