Abend u4038 将值从 1 个变量移动到另一个具有不同图片子句的变量时出错

Abend u4038 Error when moving a value from 1 variable to another variable with different picture clause

我正在尝试使用 cobol 编写程序,当我尝试 运行 该程序时,它总是显示 Abend s0000 u4038,我知道问题出在哪里,但我不知道如何解决它

所以我有一个变量

01 Ws-data.
   05 ws-branch-no   pic 9(04).

01 Ws-data2.     
   05 branch-no      pic 9(07) comp-3.


Procedure division.

Move branch-no to ws-branch-no.
Display ws-branch-no.

stop run.

好吧,所以 branch-no 中的值为“0000021”,当我尝试移动到 ws-branch-no 时它异常结束 u4038

The contents of data item WS-BRANCH-NO at the time of reference by statement number 1 on line 11742 failed the NUMERIC class test or contained a value larger than the PICTURE clause as detected by the
NUMCHECK compiler option.

我想是因为branch-no的值是0000021,而我在ws-branch-no设置的picture子句只有pic 9(04)。但关键是我希望 ws-branch-no 值在移动到 ws-branch-no 时变为 0021。

有人可以帮忙吗?谢谢

well i know whats the problem , but i dont know how to fix it i think that because the value in branch-no is 0000021 and the picture clause i set in ws-branch-no is only pic 9(04).

不,这不是问题(至少我非常确定您使用的系统没有那么坏)。 NUMCHECK 选项只会在以下情况下触发:

  • 原始数据不是数字(它是打包的所以可能包含未打包的数据?)
  • 原始数据太大(如0010021)

我建议添加一个简单的检查:

  IF branch-no NOT NUMERIC
     DISPLAY 'SHOULD NEVER HAPPEN: ' branch-no ' - ' ws-data2
  END-IF.
  IF branch-no > 9999
     DISPLAY 'TOO BIG :            ' branch-no ' - ' ws-data2
  END-IF
  MOVE branch-no TO ws-branch-no
  DISPLAY ws-branch-no.