Page 1 of 1

COBOL INDEX and subscript question and JCL's KEEP vs CATLG.

Posted: Mon Nov 16, 2015 5:03 pm
by Sunil G
1. In a COBOL table there are 20 records.How are they stored I don't know. But I want to display the 9th element from the table. Given case1: table has the index. Case2: table has the subscript.

2. What is difference between KEEP and CATLG in DISP in JCL?

These are the two questions I need help with. Please share your valuable thought on them.

Re: COBOL INDEX and subscript question and JCL's KEEP vs CATLG.

Posted: Mon Nov 16, 2015 5:48 pm
by Akatsukami
In the first case, there is no difference.

In the second case: in a non-SMS-managed system, KEEP will keep the data set but not make an entry for it in the catalog, so that it must thereafter have its volser used in the JCL to specify its location. In a SMS-managed system, there is no difference.

Re: COBOL INDEX and subscript question and JCL's KEEP vs CATLG.

Posted: Mon Nov 16, 2015 7:08 pm
by Robert Sample
With index, you code

Code: Select all

MOVE 9 TO index-variable
while with subscript you code

Code: Select all

SET subscript-variable TO 9
The actual table reference looks exactly the same.

Re: COBOL INDEX and subscript question and JCL's KEEP vs CATLG.

Posted: Mon Nov 16, 2015 9:45 pm
by William Collins
COBOL allows exactly one method to access data in a table with OCCURS, and that is called Subscripting. (OK, you can reference-modify to reference data in a table, but that's not much use if your data is not simple "character" data).

A subscript can be a literal, an index or a data-item-used-as-a-subscript.

Things get confusing, because we tend to refer to that last one as "a subscript".

"A subscript" you have to define yourself. That leaves the programmer the possibility of defining it "inefficiently".

An index is defined by the compiler, and is always the equivalent of PIC 9(9) COMP-5.

An index can only be amended by a SET, SEARCH or PERFORM. "A subscript" can be amended by... anything which can amend a data-item. So it can also be REDEFINESed.

Once you get those two things out of the way, there is no difference to the result, although with either a programmer can make the code run slower than need be.