Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why is ELSE giving me a warning?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi,
I keep getting a warning when I compile with this code:
001254 VALIDATE-DAY-MAX.
001255 IF VALID-MONTHS-P
001256 IF 30-DAY-MONTH-P AND ST-PURCHASE-DAY <= 30
001258 OR 31-DAY-MONTH-P AND ST-PURCHASE-DAY <= 31
001260 OR FEBRUARY-P AND ST-PURCHASE-DAY <= 29
001262 ELSE
001263 MOVE DAY-P-MSG TO ERROR-MSG
001264 PERFORM WRITE-ERROR-LINE
001265 END-IF
001274 END-IF.

However, the program DOES compile and it gives the results needed. It just gives a warning(at line 001262). I don't really need a fix(if you've some bug about actually answering), but I would like to know if someone can spot the flaw with this?

Thanks for any input!!!
 
Hi,
I presume the warning is to alert you to the fact that you are not specifying any action to take before the else statement. It would be clearer to code this :

001254 VALIDATE-DAY-MAX.
001255 IF VALID-MONTHS-P
001256 IF 30-DAY-MONTH-P AND ST-PURCHASE-DAY > 30
001258 OR 31-DAY-MONTH-P AND ST-PURCHASE-DAY > 31
001260 OR FEBRUARY-P AND ST-PURCHASE-DAY > 29
001263 MOVE DAY-P-MSG TO ERROR-MSG
001264 PERFORM WRITE-ERROR-LINE.

Also, your logic for February treats every year as a leap year. Hope this helps.
 
Hi Koko,

Clive is right, but CONTINUE is the preferred useage these days.

With the coming of scope delimiters (end-if, etc.), CONTINUE allows you to exit the nested stmt while &quot;continuing&quot; the outer stmt(s).

NEXT SENTENCE forces you to exit the entire structure, to the stmt following the (.).

Regards, Jack.
 
All,

why does it give a warning anyway? I expected that the use of scope delimiters (as in this case) would make this construction sufficiently clear?

Regards,
Ronald.
 
Hi,

the construction is clear only the compiler expects you define a statement between the if and the else.

IF ....
**** WARNING, NO STATEMENT *****
ELSE
....

So I agree with the continue statement. It is also possible to define the condition of the ELSE part by coding:

IF NOT (
.... here the old condition, whatever it was ....
)

Regards,

Crox

 
RonaldB,

It is not 'it gives a warning anyway' I'm afraid. The use of the scope delimiters is NOT a substitute for the required construct: IF condition, imperative.

You can use all sorts of delimiters you wish to use, but unless you say what needs to be done if your condition is met, then you are NOT stating everything clearly enough. Your statements, especially conditional statements should always boil down to valid LOGIC statements.

IF you want the compiler to refrain from issuing a warning, OTHERWISE I rest my case, PERIOD.
 
No need to Worry about it , why because u don't have any action in between if and else so it obviously gives u warning message.
if cond
else
action
end-if
this is what ur doing there , if u want ur code with out any warning then change it to
if not cond
action
end-if
Kishore Kumar K
Covansys India
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top