INITIALIZE 在 PIC X 和 PIC S9 COMP 变量上给出垃圾值

INITIALIZE gives garbage value on PIC X and PIC S9 COMP variables

初始化以下变量时:

01  BATCH-REC.
       03  BATCH-VERSION             PIC X(2).
       03  BATCH-FIELDS              PIC X(682).
       03  BATCH-REC-01 REDEFINES BATCH-FIELDS.
           05  B01-OH-DTL-REC.
               07  B01-PE-ID         PIC X(12).
               07  B01-PMT-DISC-TERMS PIC S9(4) COMP.
               07  B01-PMT-DISC-AMT  PIC S9(18) COMP.

使用命令

INITIALIZE BATCH-REC.

变量B01-PMT-DISC-TERMS初始化为值+08224,B01-PMT-DISC-AMT初始化为+314885530818453536。 可能是什么原因?初始化后将空白 space 移动到这些变量是个好主意吗?我不想更改 BATCH-REC 代码以在其上添加默认值。

INITIALIZE 语句不会初始化重新定义的字段。如果要初始化重新定义的字段,则必须以某种方式标识它们。例如,

INITIALIZE BATCH-VERSION BATCH-REC-01

这会将基本字段初始化为 SPACESZEROS,具体取决于它们的 PICTUREBATCH-FIELDS不会被初始化。


在这种情况下,下面的第 3 项适用。来自 INITIALIZE 的 2002 年标准:

5) The receiving-operand in each implicit MOVE or SET statement is determined by applying the following steps in order:

a) First, the following data items are excluded as receiving-operands:

  1. Any identifiers that are not valid receiving operands of a MOVE statement, except data items of category data-pointer, object-reference, or program-pointer.
  2. If the FILLER phrase is not specified, elementary data items with an explicit or implicit FILLER clause.
  3. Any elementary data item subordinate to identifier-1 whose data description entry contains a REDEFINES or RENAMES clause or is subordinate to a data item whose data description entry contains a REDEFINES clause. However, identifier-1 may itself have a REDEFINES clause or be subordinate to a data item with a REDEFINES clause.

在这种情况下,我认为您会发现您的 INITIALIZE 语句确实将您的 PIC X 数据初始化为空格。 B01-PMT-DISC-TERMS 的值为 x'2020',B01-PMT-DISC-AMT 的值为 x'2020202020202020',前导数字被截断,这可能是由于报告的值被限制为18位图片子句

无论如何,我同意@RickSmith 的观点并相信他对您问题的解决方案是正确的。