COBOL - Group home

Debug Tool support for COBOL 5.1: Tables/Arrays

  

Improvements for listing the contents and attributes of COBOL tables (arrays)


This blog points out some of the improvements you'll see compared to debugging earlier versions of Enterprise COBOL. I'll describe a number of changes that you'll see when working with COBOL tables (arrays) in Debug Tool. Some of these changes provide more consistent and streamlined output of the table information or contents, and other changes provide better support for COBOL language rules when working with tables.

 

The LIST Command Output

Using the following simple table as an example, I'll show you what the COBOL V4.2 LIST output looks like compared to the COBOL V5.1 output, and then I'll describe the differences.

1 R1. 
5 ARR1 OCCURS 2 TIMES.
10 X PIC 99 USAGE BINARY.
10 Y PIC 99 USAGE BINARY.

COBOL V4.2 output:

 LIST ARR1 ; 
SUB(1) of 03 BLOG:>X of 02 BLOG:>ARR1 = 00001
SUB(2) of 03 BLOG:>X of 02 BLOG:>ARR1 = 00003
SUB(1) of 03 BLOG:>Y of 02 BLOG:>ARR1 = 00002
SUB(2) of 03 BLOG:>Y of 02 BLOG:>ARR1 = 00004

COBOL V5.1 output:

 LIST ARR1 ; 
10 X of 05 ARR1(1) = 00001
10 Y of 05 ARR1(1) = 00002
10 X of 05 ARR1(2) = 00003
10 Y of 05 ARR1(2) = 00004

Description of the differences:

  1. In V5.1, the block qualifier "BLOG:>" has been dropped, making the output cleaner and easier to read.
     
  2. In V5.1, the subscript is shown at the end of the element name instead of at the beginning using "SUB(n)". This is consistent with how COBOL subscripting is done, and is how you would reference the array element in other Debug Tool commands. For example, "LIST X of ARR1(1)" or "MOVE X of ARR1(1) to VAR1".
     
  3. In V5.1, the elements are displayed in sequence, showing all values for a given element before showing the values for the next element. In this example, fields X and Y are shown for element 1 before fields X and Y for element 2. This reflects how the array is actually arranged in memory if you were to look at the storage it occupies.
     
  4. In V5.1, the level numbers are exactly what was used in the COBOL source, they have not been renumbered as they were in V4.2. This makes it easier to correlate what you see in the command output with what you see in the source where the data items are actually defined.

 

The DESCRIBE ATTRIBUTES Command Output

COBOL V4.2 output:

DESCRIBE ATTRIBUTES ARR1 ; 
ATTRIBUTES for ARR1
Its length is 8
Its address is 263C2210
02 BLOG:>ARR1 AN-GR OCCURS 2
03 BLOG:>X 99
SUB(1) COMP
SUB(2) COMP
03 BLOG:>Y 99
SUB(1) COMP
SUB(2) COMP

COBOL V5.1 output:        

DESCRIBE ATTRIBUTES ARR1 ;
ATTRIBUTES for ARR1
Its length is 8
Its address is 263CD140
05 ARR1 OCCURS 2
10 X 99 COMP
10 Y 99 COMP

Description of the differences:

  1. The differences described above for the LIST command are also applicable here e.g. no block qualifiers, and level numbers exactly as they appear in the source.
     
  2. In addition, a major difference is that the type information for the table elements is listed only once in V5.1, whereas in V4.2 it is repeated for every element in the table. The output in V4.2 was redundant since every element has the same type, and if a table had many elements it produced a large amount of unnecessary output. The V5.1 output is much more compact, with no loss of information, and is much closer to what the original table definition looks like in the COBOL source.

 

There are several other changes in Debug Tool's support for COBOL tables which I will describe in a future blog entry rather than try to describe everything all in one post.

Debug Tool's support for tables provides better usability and support for COBOL language rules

I'll be using the following table and data items in my examples below:

1 R1. 
5 ARR1 OCCURS 2 TIMES DEPENDING ON ARR1SZ INDEXED BY IX1.
10 X PIC 99 USAGE BINARY.
10 Y PIC 99 USAGE BINARY.
88 TENS VALUE 10 20 30 40 50 60 70 80 90.
5 SBIN1 PIC s99 USAGE BINARY.
5 SBIN2 PIC s9v9 USAGE BINARY.

77 IXDI1 USAGE IS INDEX.
77 ARR1SZ PIC 9 USAGE BINARY VALUE 2.

Using Subscripts, Index Names, and Index Data Items

Relative Subscripting

In COBOL, relative subscripting is done using either a data name or an index name, and adding or subtracting an integer literal. The V4.2 Debug Tool support allows relative subscripting using a data name but not an index name. V5.1 allows both. Here is an example, where IX1 is an index name:

V4.2 output:

LIST ARR1 ( IX1 + 1 ) ; 
IX1 contains incompatible data type.

V5.1 output:

LIST ARR1 ( IX1 + 1 ) ; 
10 X of 05 ARR1(2) = 00001
10 Y of 05 ARR1(2) = 00004

 

Index Data Items are not allowed as subscripts

COBOL does not allow an index data item to be used as a subscript. This rule is enforced when debugging COBOL V5.1, but not V4.2.

Here's an example of the error message you'll get in Debug Tool with COBOL V5.1 if you try to use an index data item as a subscript:

LIST ARR2 ( IXDI1 ) ; 
An unsupported operator/operand is specified.

 

Index Names cannot be qualified using IN/OF

COBOL does not allow an index name to be qualified using IN or OF. This rule is enforced when debugging COBOL V5.1, but not V4.2.

Here's an example of the error message you'll get in Debug Tool with COBOL V5.1 if you try to qualify an index name:

SET IX1 OF ARR1 TO 1 ; 
The variable IX1 is undefined or is incorrectly qualified.

 

Index Names can only be set using integral types

When the receiver in a SET statement is an index name, COBOL only allows integral types as senders. This rule is enforced when debugging V5.1, but not V4.2.

Here is an example of the error message you'll see in Debug Tool with COBOL V5.1 if you try to SET an index name using a non-integral type:

SET IX1 TO SBIN2 ; 
IX1 contains incompatible data type.

 

Consistently showing the evaluated value of a subscript

In almost all cases, the output of Debug Tool commands for both V4.2 and V5.1 show you the evaluated value of a subscript so you can see exactly which table element is being referenced. In the following example, the subscript "SBIN1 + 1" is evaluated to the value 2, and that's the value shown in the output:

V4.2 output:

LIST Y ( SBIN1 + 1 ) ;
SUB(2) of 03 ARRAY:>Y = 00004

V5.1 output:

LIST Y ( SBIN1 + 1 ) ; 
10 Y(2) = 00004

There is one exception in V4.2 however: When you apply a subscript to a level 88 Condition Name, it does not show you the evaluated value of the subscript. Instead it simply echoes back the string you entered as the subscript.

V4.2 output:

LIST TENS ( SBIN1 + 1 ) ; 
TENS ( SBIN1 + 1 ) = FALSE

This discrepancy was corrected in V5.1 so that now the evaluated value of a subscript is always shown, even for level 88 Condition Names.

LIST TENS ( SBIN1 + 1 ) ; 
88 TENS(2) = FALSE (Y = 00004)

Out of bounds error message gives the evaluated value of the subscript

Similar to the above, when an array subscript is out of bounds, the error message emitted by Debug Tool for V4.2 does not show the evaluated value of the subscript, whereas for V5.1 it does.

V4.2 output:

LIST ARR1 ( SBIN1 + 3 ) ; 
The indices in SBIN1 are invalid.

V5.1 output:

LIST ARR1 ( SBIN1 + 3 ) ; 
Array subscript or index 4 is out of bounds.


Showing variably located data items

When the size of an ODO table is zero, V4.2 does not show any variably located data items i.e. those data items that follow the ODO table within the same record. The following shows the output from the LIST command when the size of the table is 2, and also when the size is 0:

V4.2 output:

LIST R1 ; 
00 ARRAY:>IX1 of 02 ARRAY:>ARR1 of 01 ARRAY:>R1 = 1
SUB(1) of 03 ARRAY:>X of 02 ARRAY:>ARR1 of 01 ARRAY:>R1 = 00001
SUB(2) of 03 ARRAY:>X of 02 ARRAY:>ARR1 of 01 ARRAY:>R1 = 00001
SUB(1) of 03 ARRAY:>Y of 02 ARRAY:>ARR1 of 01 ARRAY:>R1 = 00002
SUB(2) of 03 ARRAY:>Y of 02 ARRAY:>ARR1 of 01 ARRAY:>R1 = 00004
02 ARRAY:>SBIN1 of 01 ARRAY:>R1 = +00000
02 ARRAY:>SBIN2 of 01 ARRAY:>R1 = +0000.0

MOVE 0 TO ARR1SZ ;

LIST R1 ;
Incorrect value for ODO variable 01 ARRAY:>R1

With COBOL V5.1 a size of zero for the ODO table does not prevent the variably located data items from being displayed:

V5.1 output:

LIST R1 ; 
10 X of 05 ARR1 of 01 R1(1) = 00001
10 Y of 05 ARR1 of 01 R1(1) = 00002
10 X of 05 ARR1 of 01 R1(2) = 00001
10 Y of 05 ARR1 of 01 R1(2) = 00004
05 SBIN1 of 01 R1 = +00000
05 SBIN2 of 01 R1 = +0000.0

MOVE 0 TO ARR1SZ ;

LIST R1 ;
05 SBIN1 of 01 R1 = +00010
05 SBIN2 of 01 R1 = +0001.0

As you can see, even though the table ARR1 has size zero and therefore no elements to show, the LIST command still shows the values of the variably located data items that follow the table, SBIN1 and SBIN2.

Summary

To summarize, when you debug COBOL V5.1 in Debug Tool you'll notice several ways in which the support for COBOL tables has changed compared to earlier versions of Enterprise COBOL. These changes provide greater consistency, usability, and adherence to COBOL language rules, not only for the tables themselves, but also for related constructs such as Index Names and Index Data Items.