View previous topic :: View next topic
|
Author |
Message |
harsh singh
New User
Joined: 11 Dec 2007 Posts: 26 Location: INDIA
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
harsh singh
New User
Joined: 11 Dec 2007 Posts: 26 Location: INDIA
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You could try this recent topic. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|