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
 

 

checking numeric and zeros

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: checking numeric and zeros
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: 662
Location: Pennsylvania

PostPosted: Fri Apr 09, 2010 1:01 am    Post subject:
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: 6967
Location: porcelain throne

PostPosted: Fri Apr 09, 2010 1:27 am    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Fri Apr 09, 2010 2:33 am    Post subject: Re: checking numeric and zeros
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    Post subject:
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    Post subject: Reply to: checking numeric and zeros
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    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
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts Checking Current date vickey_dw DFSORT/ICETOOL 1 Wed Feb 08, 2017 11:14 pm
No new posts Converting decimal to numeric using I... Balaryan DFSORT/ICETOOL 4 Thu Feb 02, 2017 11:27 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am


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