RPG(LE) 中的条件编译
我是否可以根据程序中是否定义了变量来包含一段代码,或者预处理器完全无法访问此信息,只能访问编译条件? 即我正在寻找类似的东西:
/IF DEFINED(myVariable)
D myOtherVariable S like(myVariable)
/ELSE
D myOtherVariable S 20A
/ENDIF
这个 link似乎表明这是不可能的。 如果是这样,有人知道另一种方法来实现这一目标吗?
Can I include a section of code based on whether a variable is defined in my program, or is the preprocessor completely unable to access this information, only compilation conditions? I.e. I'm after something like:
/IF DEFINED(myVariable)
D myOtherVariable S like(myVariable)
/ELSE
D myOtherVariable S 20A
/ENDIF
This link appear to suggest it is not possible. If so does anyone know of another way to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果有的话,这将是一个很好的功能,但不幸的是,今天它已经不能这样工作了。 DEFINED 后面括号中的值必须是定义的条件名称,而不是变量名称。 使其发挥作用的方法是,每当您在任何程序或副本中定义特定变量时,都使用 /DEFINE 指令。 这是否是推荐的做法,完全取决于这些情况的使用情况。
您问题中提供的链接是正确的,我同意结论。
It would be a nice feature to have, but unfortunately, it doesn't work that way today. The value in parenthesis after DEFINED must be a defined condition name, not a variable name. The way to make it work is to have a /DEFINE directive whenever you define that specific variable in any of programs or copybooks. It all depends on usage for these situations as far as whether or not this is a recommended practice.
The link provided in your question is spot-on and I agree with the conclusions.
作为附加提示,请使用有关此主题的 C 编程书籍,而不是 IBM RPGLE 书籍。 IBM 书籍描述了指令可以做什么。 C 书籍描述了如何在现实世界的程序(例如Linux 开源程序)中使用它。 遵循这种风格可以让其他程序员更容易阅读你的 RPG 源代码。
As an additional hint, use C programming books for this subject, not the IBM RPGLE books. The IBM books describe what can be done with directives. The C books describe how it is used in real world programs (e.g. Linux open source programs). Following that style makes your RPG sources much more readable for other programmers.