COBOL's EVALUATE: How to have an empty WHEN OTHER clause?

故事扮演 提交于 2020-03-25 16:12:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!