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

Adding decimal feild in Cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
harsh singh

New User


Joined: 11 Dec 2007
Posts: 26
Location: INDIA

PostPosted: Tue Nov 08, 2011 1:33 pm
Reply with quote

Hi,
I need to add two decimal feild

01 A Pic S9(9)V9(4) say 21.90
01 B Pic S9(9)V9(4) say 21.98

IN Procedure Division i am giving :-

COMPUTE A = A + B

But I am encountering SOC-7.. I have verified that there is no data error.
some how i am missing as i am not able to recall , please advise
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Nov 08, 2011 1:42 pm
Reply with quote

If A and B are 21.90 and 21.98 as you posted, the decimal point will cause a S0C7 abend. The values should be 0000000219000 and 0000000219800 respectively. The V in a COBOL PICTURE clause means IMPLIED decimal point -- there is no actual decimal point in the data -- ever.

Quote:
But I am encountering SOC-7.. I have verified that there is no data error.
The computer tells you there is a data error. You have "verified" that there is no data error. I believe the computer much more than you -- either you do not understand how the data should be represented or you do not understand how the data actually is stored in the computer. The computer does not lie to you -- if your program got a S0C7 abend, then by definition you have a data error.
Back to top
View user's profile Send private message
harsh singh

New User


Joined: 11 Dec 2007
Posts: 26
Location: INDIA

PostPosted: Tue Nov 08, 2011 2:18 pm
Reply with quote

Thanks Robert

This is a new code so you mean that using inspect i need to calcuate leading spaces and then move to data so it becomes in right order and then i should go for computaion
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: Tue Nov 08, 2011 2:34 pm
Reply with quote

harsh singh wrote:
Thanks Robert

This is a new code so you mean that using inspect i need to calcuate leading spaces and then move to data so it becomes in right order and then i should go for computaion


If you have data which is not numeric, then define it in a PIC X(n) field. Depending on the values the data can have, you can assemble the correct parts for a number (if all the data is fixed) or you can use the intrinsic function NUMVAL/NUMVALC.

You seem to be talking of data which is a long way from how you want it (two decimals missing), but still, if fixed format, you can do it with some redefines and move.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Nov 08, 2011 2:39 pm
Reply with quote

Quote:
This is a new code so you mean that using inspect i need to calcuate leading spaces and then move to data so it becomes in right order and then i should go for computaion
Not at all. I said you are telling us that the computer is wrong in generating the S0C7 abend -- whereas the computer is MUCH more likely to be right than you are. If you are getting A and B from a file or other external source, you could define them as PIC X(??) and use FUNCTION NUMVAL to retrieve the numeric value -- or you could use INSPECT -- or you could use reference modification. But in any case, it appears you have some work to do on the code to correct the cause of the data error.
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: Tue Nov 08, 2011 3:08 pm
Reply with quote

You could try this recent topic.
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: Tue Nov 08, 2011 8:18 pm
Reply with quote

Hello,

Back to the beginning of this topic:
Quote:
I need to add two decimal feild

01 A Pic S9(9)V9(4) say 21.90
01 B Pic S9(9)V9(4) say 21.98
A field with an implied decimal cannot contain an actual decimal-point.

In addition to reading the info provided by others, you should spend some time in the COBOL Language Reference (link to "IBM Manuals" at the top of the page) and learn how data may be stored in the various numeric data definitions.
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 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
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top