1

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?

Benjamin Zach
  • 1,452
  • 2
  • 18
  • 38
  • 1
    (1) Are you sure that `IN-VARIABLE-2` has a value that is distinct from `IN-VARIABLE-1`? It doesn't have a `VALUE` clause, so its initial value is unclear. (2) Depending on the context of the entire program, you may not need to use qualification (the `OF` syntax). `IF LABELED-VALUE THEN` may be sufficient. – David Gorsline Sep 17 '20 at 13:32
  • @DavidGorsline, 1: yes I'm sure it has a distinct value. 2: But it is not wrong to use the ```OF```s, right? – Benjamin Zach Sep 17 '20 at 13:49
  • If you DISPLAY IN-VARIABLE-1 what does it show? – NicC Sep 17 '20 at 14:33
  • Due to me not having access to the console in which runs the code on the platform, I cannot do any ```DISPLAY```. But my debugger tells me that ```IN-VARIABLE-1``` has a value of ```000```, thus ```LABELED-VALUE OF IN-VARIABLE-1 OF PARENT-1 OF GRAND-PARENT``` is ```TRUE```. By the way: ```IN-VARIABLE-2``` has a value of 978 – Benjamin Zach Sep 17 '20 at 15:46
  • 1
    It's not wrong to use `OF`, it's just a trifle obscure. So it's a wild hunch on my part that it's causing the debugger to give you the wrong answer. – David Gorsline Sep 17 '20 at 19:01
  • What is a hunch? But I don't think it's the debugger displaying wrong values, because although I can't do ```DISPLAY``` I obtain a result after the Cobol code is executed and this result is conform with what we see from the debugger – Benjamin Zach Sep 18 '20 at 06:51
  • LABELED-VALUE is a CONDITION not a variable. CONDITION names have to be unique within a program so trying to associate it with a structure is a waste of time (and, possibly, wrong (I have never seen a manual/book that says that you can qualify a level 88 name)). The correct usage syntax is IF LABELED-VALUE THEN... – NicC Sep 19 '20 at 11:18
  • 1
    @NicC it is totally valid and perfect for a condition name to be qualified - if there are multiple condition-names with the same name (only possible in different "structures") then you need to qualify them, the same rules that exist for "normal" variables apply here, too. – Simon Sobisch Sep 19 '20 at 12:55

1 Answers1

0

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
Benjamin Zach
  • 1,452
  • 2
  • 18
  • 38