我们有一个 COBOL 程序,其中我们将值填充到 COBOL 内部表中,然后搜索该表以找出某个值。在此搜索之前,我们初始化表索引变量。
SET PAF-IDX TO 1.
谁能澄清一下,如果在 COBOL 中允许初始化索引变量,就像这样。
INITIALIZE PAF-IDX.
不,你为什么要“初始化”它?
这来自 IBM Enterprise Cobol 手册:
identifier-1
Receiving areas.
identifier-1 must reference one of the following:
v An alphanumeric group item
v A national group item
v An elementary data item of one of the following categories:
Alphabetic
Alphanumeric
Alphanumeric-edited
DBCS
External floating-point
Internal floating-point
National
National-edited
Numeric
Numeric-edited
v A special register that is valid as a receiving operand in a MOVE
statement with identifer-2 or literal-1 as the sending operand.
When identifier-1 re
编辑:
OpenCobol Programmer's Guide 专门记录了它:
The list of data items eligible to be set to new values by this statement is:
Every elementary item specified as identifier-1 ..., PLUS...
Every elementary item defined subordinate to every group item specified as dentifier-1
..., with the following exceptions:
USAGE INDEX items are excluded.
Items with a REDEFINES as part of their definition are excluded; this means that
tems subordinate to them are excluded as well.
Cobol 标准草案不太明确,但这些项目在 INITIALIZE 中使用时通过生成 SET 而不是 MOVE 进行处理:DATA-POINTER、FUNCTION-POINTER、OBJECT-REFERENCE 或 PROGRAM-POINTER。
编辑:
看到 OpenCobol 引用并不像我想的那样“具体”:在 IBM Cobol 中,目前,没有任何东西不能通过成为 MOVE 的目标来进行操作可以被初始化。这与当前的 OpenCobol 相同。草稿 Cobol 列出了一些例外情况,但既不包括 INDEXED BY(不是表本身的一部分,而是编译器自己定义存储的单独项目)也不包括 USAGE INDEX。