Thursday, December 4, 2008

Subscript and Index

What is the difference between a subscript and an index?

An index is defined with it's associated table using the INDEXED BY phrase. It is a storage area generated by the compiler. It is a register item that exists outside the program's working storage. It is 4 bytes in length. You can’tdisplay an index. The SET statement sets up and down an index,PERFORM VARYING.

A subscript is a positive integer defined in working-storage. It's best to defineit as S9(4) COMP. A subscript is changed using ADD, SUBTRACT, MOVE orPERFORM VARYING like any other numeric working storage variable.

For more cobol queries, click here

Max no. of dimensions in a cobol array ?

For Cobol 3 is the max where as for Cobol-II 7 is the max.

What is array bounds checking ?

My program has an array defined to have 10 items. Due to a bug , I find that even if he program access the 11th item in the array, the program does not abend. What’s wrong with it?

Must use the compiler option SSRANGE, if u want array bounds checking.Default is NOSSRANGE.

For detailed description of these compiler options. Please refer to the following link COBOL Compiler options

Can we convert index to subscript and vice versa?

Yes, with SET statement. Example: SET INX TO SUB.

How can we change the value of index?

Verbs used to updated value of an index.

SET INX TO VALUE
SET INX UP/DOWN BY VALUE
PERFORM/VARYING.

Wednesday, December 3, 2008

How can we pass a table in cobol linkage section ?

If you were passing a table via linkage, which is preferable - a subscript or an index?

Bingo!!!- you haven't been paying attention! It's not possible to pass an index via linkage. The index is not part of the calling programs working storage( index is a register) . Those of us who've made this mistake, appreciate the lesson more than others.