Cobol not entering if, although condition is true

395 views Asked by At

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:

  • Adapt the condition of the IF to check for the specific value, like IF IN-VARIABLE-1 OF PARENT OF GRAND-PARENT EQUAL ZERO THEN (ZERO is in fact the value of LABELED-VALUE)
  • It happens with my debugger that it displays an old version of the code but displays the execution line indicator for the most current version. This can result in the indicator being displayed in front of the wrong line. In order to avoid this I've made a change to a comment, recompiled, restarted the serverclass and reattached to the process. Doing so I in fact have obtained the most recent version of the source and I can therefore exclude this problem.

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?

1

There are 1 answers

0
Benjamin Zach On BEST ANSWER

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