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

All sort of Mainframes Interview Questions.
Post Reply
Sunil G
New Member
Posts: 1
Joined: Fri Dec 12, 2014 1:09 pm

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

Post 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.
User avatar
Akatsukami
Global Moderator
Global Moderator
Posts: 122
Joined: Tue Oct 20, 2015 3:20 am
Location: Bloomington, IL
Contact:

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

Post 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.
"I come to the conclusion that, men loving according to their own will and fearing according to that of the prince, a wise prince should establish himself on that which is in his own control and not in that of others." -- Niccolò Machiavelli
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1891
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

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

Post 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.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

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

Post 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.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Interview Questions.”