问题
EVALUATE MyValue
WHEN 1
DISPLAY "My value is 1"
WHEN 2
DISPLAY "My value is 2"
WHEN OTHER
* Actually I don't need to do anything
END-EVALUATE
I think to have read somewhere that a COBOL application will crash for an EVALUATE
where the WHEN
clauses do not cover the value of the evaluated variable, if there is no WHEN OTHER
statement present. So, in order to avoid the crash, I wanted to add this empty WHEN OTHER
.
Under which circumstances is this necessary, and if so, is this approach correct?
回答1:
Under which circumstances is this necessary ...
Under no circumstances with every COBOL environment I know of (might be "some"); and isn't necessary for any COBOL 85/2002/2014/future compiler.
... and if so, is this approach correct?
No, actually COBOL 85/2002/2014/future-compliant compiler will raise an error because of a missing imperative statement (there are some compilers allowing this as "extension" [I'd say it is a bug], some at least warn, some stay silent).
If there are some "really strange reasons" to always include the WHEN OTHER
: use the (nearly no-op) statement CONTINUE
as "statement".
来源:https://stackoverflow.com/questions/60816954/cobols-evaluate-how-to-have-an-empty-when-other-clause