Search code examples
cobol

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


Im trying to write a program using cobol, when i try to run the program it always display the Abend s0000 u4038, well i know whats the problem , but i dont know how to fix it

So i have a variable

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.

okay like that , so the value in branch-no is '0000021' , when i try to move to ws-branch-no it got abend 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.

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). but the point is i want the ws-branch-no value become 0021 when it moved to the ws-branch-no.

can anyone help? Thankyou


Solution

  • 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).

    No, this isn't the problem (at lest I'm very sure that the system you use is not that broken). The NUMCHECK option will only be triggered if:

    • the original data is not numeric (its is packed so maybe contains unpacked data?)
    • the original data is too big (like 0010021)

    I suggest to add a simple check:

      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.