Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Index or Subscript?

Status
Not open for further replies.

ihatecobol

Programmer
Oct 30, 2000
6
0
0
US
Can anyone give me a "textbook like" explaination of the difference between a index and a subscript?
 


Difference in form in which they are stored.

Subscript is ordinary variable(declared as data item in working-storage) and stored as separate ASCII digits.
Needs to be converted to binary when used so slower processing.

Index only declared as part of the OCCURS clause, they don't have PIC clause. Index stored directly in binary form, so no conversion required and processing faster.

 
I have more information on this. Hopefully this will be textbook-like enough as I teach COBOL at technical college.

The difference between subscripts and indexes is in their internal storage.

Subscripts are regular data items and can be of any type including display, packed decimal, and binary. They are defined with a PIC clause and they can be manipulated with any COBOL statement that can perform operations on numeric data. If you looked at one of these items internally, it would look like the number you would expect it to be.

Indexes are specialized data items that are only used only for accessing table items. They are defined with an INDEXED BY clause or with a USAGE IS INDEX and they must be manipulated with the SET statement rather than any of the regular COBOL statements that are used to perform operations on numeric data items. If you looked at an index internally, it would not look like its numeric value, but rather it would be a displacement from the beginning address of the table associated with the index.

Two final observations, indexes are always stored in binary and they are even faster than a subscript that is also stored in binary because of the displacement issue mentioned in the preceding paragraph. The displacement can be a problem, because you cannot share indexes between two tables - each would have to have its own index and you would have to SET one to the other to get them to match up.

The reason that a programmer might choose to use a subscript over an index in spite of this is the availability of addressing two different tables with the same subscript or for the mathematical manipulation. Betty Scherber
Brainbench MVP for COBOL II
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top