Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 684
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: 6968
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 File Aid tool to compare numeric data balaji81_k Compuware & Other Tools 2 Tue Sep 26, 2017 3:35 am
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts Return a Non Numeric value from REXX Learncoholic CLIST & REXX 3 Fri Sep 01, 2017 8:33 pm
No new posts editting the file by inserting zeros ... pramodrsingh DFSORT/ICETOOL 9 Mon Aug 21, 2017 5:58 pm
No new posts Select numeric portion from CHAR data... balaji81_k DB2 6 Sat Aug 19, 2017 1:51 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us