if-statementdebuggingcobolhp-nonstop

Cobol not entering if, although condition is true


I'm working on a Cobol application that is deployed on HP Nonstop. Debugging on the platform I came across the following situation:

IF LABELED-VALUE OF IN-VARIABLE-1 OF PARENT-1 OF GRAND-PARENT THEN
  MOVE IN-VARIABLE-2 OF PARENT-2 OF GRAND-PARENT TO OUT-VARIABLE
ELSE
  MOVE IN-VARIABLE-1 OF PARENT-1 OF GRAND-PARENT TO OUT-VARIABLE
END-IF

The fields are defined like this:

01 GRAND-PARENT
  03 PARENT-1.
    05 IN-VARIABLE-1                  PIC 9(3).
      88 LABELED-VALUE                VALUE 000.
  03 PARENT-2.
    05 IN-VARIABLE-2                  PIC 9(3).
    
01 OUT-VARIABLE                       PIC 9(3).

When I evaluate the expression LABELED-VALUE OF IN-VARIABLE-1 OF PARENT OF GRAND-PARENT my debugger tells me that the expression is TRUE. The value of IN-VARIABLE-1 OF PARENT OF GRAND-PARENT is 0. Consequently OUT-VARIABLE should have the respective value. But this is not the case; it has always the value IN-VARIABLE-1 and the logic always enters the ELSE.
Here you can see the situation in my debugger after the execution of the code: Here you can see the situation in my debugger after the execution of the code.

What I've tried so far:

I am not a Cobol expert, though I thought that a simple IF could be manageable, but no avail. Could someone please help me out?

UPDATE:
In my debugger I can edit the values of the fields. If I overwrite the existing value 000 of IN-VARIABLE-1 OF PARENT-1 OF GRAND-PARENT again with 0 or 000 before the if, then the code works correctly. WTF?


Solution

  • The problem was actually about how IN-VARIABLE-1 OF PARENT-1 OF GRAND-PARENT is initialized. In my case most probably, it is uninitialized. In that case it is possible to fix the condition this way:

    IF LABELED-VALUE OF IN-VARIABLE-1 OF PARENT-1 OF GRAND-PARENT OR
       IN-VARIABLE-1 OF PARENT-1 OF GRAND-PARENT EQUAL LOW-VALUES
    THEN
      MOVE IN-VARIABLE-2 OF PARENT-2 OF GRAND-PARENT TO OUT-VARIABLE
    ELSE
      MOVE IN-VARIABLE-1 OF PARENT-1 OF GRAND-PARENT TO OUT-VARIABLE
    END-IF