View previous topic :: View next topic
|
Author |
Message |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
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 |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
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 |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Thank you all. |
|
Back to top |
|
|
|