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
 

 

Adding decimal feild in Cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Adding decimal feild in Cobol
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: 7935
Location: Bellevue, IA

PostPosted: Tue Nov 08, 2011 1:42 pm    Post subject:
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7254

PostPosted: Tue Nov 08, 2011 2:34 pm    Post subject:
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: 7935
Location: Bellevue, IA

PostPosted: Tue Nov 08, 2011 2:39 pm    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7254

PostPosted: Tue Nov 08, 2011 3:08 pm    Post subject: Reply to: Adding decimal feild in Cobol
Reply with quote

You could try this recent topic.
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: Tue Nov 08, 2011 8:18 pm    Post subject:
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    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. Full Time COBOL Software Development ... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:24 am
This topic is locked: you cannot edit posts or make replies. COBOL Software Development Lead at Fi... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:21 am
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm
No new posts Need Suggestion on COBOL program vickey_dw COBOL Programming 5 Thu Jan 05, 2017 10:55 pm


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