Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
harsh singh

New User

Joined: 11 Dec 2007
Posts: 26
Location: INDIA

 Posted: Tue Nov 08, 2011 1:33 pm    Post subject: Adding decimal feild in Cobol 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

Robert Sample

Global Moderator

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

Posted: Tue Nov 08, 2011 1:42 pm    Post subject:

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.
harsh singh

New User

Joined: 11 Dec 2007
Posts: 26
Location: INDIA

 Posted: Tue Nov 08, 2011 2:18 pm    Post subject: 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
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

Posted: Tue Nov 08, 2011 2:34 pm    Post subject:

 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.
Robert Sample

Global Moderator

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

Posted: Tue Nov 08, 2011 2:39 pm    Post subject:

 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.
Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

 Posted: Tue Nov 08, 2011 3:08 pm    Post subject: Reply to: Adding decimal feild in Cobol You could try this recent topic.
dick scherrer

Site Director

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

Posted: Tue Nov 08, 2011 8:18 pm    Post subject:

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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics batch cobol/db2 paragraph fall thru a... alois eisshofer COBOL Programming 5 Wed Mar 14, 2018 12:21 am write multiple lines in PS file in cobol Balu5491 COBOL Programming 7 Wed Mar 07, 2018 10:27 am How to group and sum the decimal value sakrat DFSORT/ICETOOL 2 Tue Mar 06, 2018 9:13 pm COBOL declaration for table Poha Eater DB2 2 Mon Feb 26, 2018 6:58 pm A couple of Interview Questions on Co... viplavmodi36 Mainframe Interview Questions 5 Fri Feb 23, 2018 6:21 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us