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

checking numeric and zeros


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

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Fri Apr 09, 2010 12:57 am
Reply with quote

Hi,

I have a variable in the program validated for NUMERIC. Now, I want to add a "GT ZEROES" check to the same.

I tried the below code but ended up with compilation error.

Code:


IF W-ONLINE-DATA IS NUMERIC AND > ZEROS
    PERFORM 100-MULTIP-PARA
END-IF



I tried it below way and got NO compilation errors.

Code:


IF W-ONLINE-DATA IS NUMERIC
 AND IF W-ONLINE-DATA > ZERO
    PERFORM 100-MULTIP-PARA
END-IF



Is it right? Would you please suggest a better way of how it should be coded against the single variable.

Thanks.
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Fri Apr 09, 2010 1:01 am
Reply with quote

It would be nice to see the Working Storage for this field.

Anyway try...
Code:

IF W-ONLINE-DATA IS NUMERIC
  IF W-ONLINE-DATA > ZERO
     PERFORM 100-MULTIP-PARA
  END-IF
END-IF
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 09, 2010 1:27 am
Reply with quote

I imagine W-ONLINE-DATA is alphanumeric,
which is why you received the compiler error.

daveporcelan provided you with what I would consider the best syntax,
if the PICTURE string is of numeric type.

Since you did not bother to provide the PICTURE string,
you are not going to receive qualified help.

you should not code IF REFERENCE-NAME IS NUMERIC AND > ZERO

because the compiler does not always generate the code from left to right in a connective
- it could generate a compare for > zero to be executed first,
and if there was invalid data in the field you would receive a soc7.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Apr 09, 2010 2:33 am
Reply with quote

ramsri wrote:
Code:
IF W-ONLINE-DATA IS NUMERIC AND > ZEROS
    PERFORM 100-MULTIP-PARA
END-IF


A condition is two operands separated by a relational operator:
General relation conditions


Combined conditions are two conditions separated by a combined condition element:
Combined conditions


A slight change should make it work:
Code:
IF W-ONLINE-DATA IS NUMERIC AND
   W-ONLINE-DATA IS > ZEROS
    PERFORM 100-MULTIP-PARA
END-IF
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Fri Apr 09, 2010 2:27 pm
Reply with quote

Dick wrote:
Quote:
Since you did not bother to provide the PICTURE string,
you are not going to receive qualified help.

you should not code IF REFERENCE-NAME IS NUMERIC AND > ZERO

because the compiler does not always generate the code from left to right in a connective
- it could generate a compare for > zero to be executed first,
and if there was invalid data in the field you would receive a soc7.

With all respect, Dick, I think you are wrong here. According to the Cobol LR manual, combined conditions are evaluated basically left to right, and this is not subject to code optimisation.

But the construct used by OP is illegal and will not compile because the so called abbreviated combined condition construct can only be used where both condition elements are relation conditions, and the condition IS NUMERIC is a class condition.

Therefore, you should should use the construct as suggested by William above. When written in that order the test for numeric will be evaluated first, and if the condition is false, evaluation will end here because the result of the second condition cannot change the end result of the combined AND condition if the first is evaluated false.
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Wed Apr 14, 2010 11:41 am
Reply with quote

Thank you all.
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 Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Convert HEX to Numeric DB2 3
No new posts Find a record count/numeric is multip... COBOL Programming 1
No new posts How to display the leading zeros of a... DB2 7
No new posts REXX - Dataset checking in a do forev... CLIST & REXX 6
Search our Forums:

Back to Top