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

problem with compute


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
neelima.sinha

New User


Joined: 14 Sep 2007
Posts: 30
Location: Bangalore

PostPosted: Fri May 21, 2010 3:53 pm
Reply with quote

I have input value

03 NS-PTP-DAY-1 PIC S9(2)V9(2)
SIGN LEADING SEPARATE.

ANOTHER I/P IS

05 JLPTP-PTP-DAY-1 PIC S9(2)V9(1) USAGE COMP-3.


I need to sum the two values and have result in following format.

WW-SUM-PTP-DAY-1 PIC S9(2)V9 COMP-3 VALUE ZERO.


suppose NS-PTP-DAY-1 = +15.23
JLPTP-PTP-DAY-1 = +10.22 I NEED TO DO

WW-SUM-PTP-DAY-1 = NS-PTP-DAY-1 + JLPTP-PTP-DAY-1


How can i do this. I am getting S0C7. Where am i wrong
Back to top
View user's profile Send private message
icemanroh

New User


Joined: 23 Aug 2008
Posts: 25
Location: Mumbai

PostPosted: Fri May 21, 2010 4:09 pm
Reply with quote

Move NS-PTP-DAY-1 into a Working storage variable which shud have the same PIC clause of the output variable (In ur case its WW-SUM-PTP-DAY-1)

for e.g.

Code:
05 WS-NS-PTP-DAY-1 PIC S9(2)V9(1) USAGE COMP-3.


So in the code:

Code:
MOVE NS-PTP-DAY-1 TO WS-NS-PTP-DAY-1
COMPUTE WW-SUM-PTP-DAY-1 = WS-NS-PTP-DAY-1 + JLPTP-PTP-DAY-1.


Also pls try to do Numeric checks for all the fields before adding them.

Let me know if this works.
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: Fri May 21, 2010 4:42 pm
Reply with quote

The S0C7 abend means one of your data fields does not contain valid numeric data. You can avoid this by
Code:
IF  NS-PTP-DAY-1 NUMERIC
AND JLPTP-PTP-DAY-1 NUMERIC
    COMPUTE WW-SUM-PTP-DAY-1 = NS-PTP-DAY-1 + JLPTP-PTP-DAY-1
ELSE
    do whatever you want to flag the error
END-IF
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: Fri May 21, 2010 8:35 pm
Reply with quote

Hello,

NUMVAL is very handy if it is guaranteed that the fields will be numeric (i.e. created by an already tested program). NUMVAL is not good for "user input" because if the data is not numeric, the code abends. . .

As much of my "input" data originates on Win-based and UNIX systems, NUMVAL is heavily used.

I keep hoping for an extension to NUMVAL that would intercept the abend and set some "variable" if the value was not numeric. . . Then we could have the ease of use of NUMVAL and protection from the abend icon_smile.gif
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 Map Vols and Problem Dataset All Other Mainframe Topics 2
No new posts z/vm installation problem All Other Mainframe Topics 0
No new posts Job scheduling problem. JCL & VSAM 9
No new posts Problem with IFTHEN=(WHEN=GROUP,BEGIN... DFSORT/ICETOOL 5
No new posts Need to add field to copybook, proble... COBOL Programming 14
Search our Forums:

Back to Top