IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Confusion b/w index and subscript


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Deepak kumar25

New User


Joined: 25 Aug 2017
Posts: 3
Location: india

PostPosted: Thu Aug 31, 2017 6:50 am
Reply with quote

Hi Everyone,

Recently, I faced a interview in which panel they asked me why we use subscript and index to access table. Then i answered index is faster than subscript and she said if index is faster than subscript then why we use subscript. I answered when we use subscript in our program to access table then it internally converted to index to access data that is why indexing is more preferred than subscript.

Folks,Please give your views on this topic.

Thanks
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Aug 31, 2017 8:02 am
Reply with quote

A subscript is declared in WORKING-STORAGE whereas an index exists outside of WORKING-STORAGE. A subscript can be in a DISPLAY statement while an index cannot. Normal arithmetic verbs such as ADD, SUBTRACT, COMPUTE can be used with subscripts whereas an index can only be modified through SET, PERFORM, SEARCH. Yes, subscripts are slower but if you need to debug your program being able to DISPLAY the value is handy.
Back to top
View user's profile Send private message
Deepak kumar25

New User


Joined: 25 Aug 2017
Posts: 3
Location: india

PostPosted: Thu Aug 31, 2017 9:11 am
Reply with quote

Thanks Robert for your quick response.
But she was asking that when we have subscript in cobol then what is need of index.
Yes, I do agree that subscript is occurrence and index is displacement from begning.
But why we have both in cobol to access table.
Folks, Please give me suggestions on it.

Thanks
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Aug 31, 2017 12:12 pm
Reply with quote

You are not clear. Are you asking about one particular table in COBOL being accessed with a subscript already and why have an index on it? Or are you asking why, in general, does COBOL support both subscripts and indexes?

For one particular table in COBOL, accessed by subscripts already, you may still need an index on the table if you are using a binary search (SEARCH ALL) on that table.

For the general case of COBOL supporting both, that is how the language is defined -- it allows both subscripts and indexes. As long as you understand the differences and why subscripts and indexes are not completely interchangeable, you can use either for any particular table you code in your program.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Thu Aug 31, 2017 7:09 pm
Reply with quote

Wrong forum category, or the question must be more specific.

The question (and given answers) are related exclusively to COBOL.

In the field of the whole "Mainframe Interview Questions" the answer might be seriously different from that. The terms "subscript", and "index" would have different meaning in different environments.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Thu Aug 31, 2017 8:02 pm
Reply with quote

Read:
Quote:
The value of an index has the element size factored into it, whereas the value of a subscript must be multiplied by the element size when the subscript is used. The index already contains the displacement from the start of the table, and this value does not have to be calculated at run time. However, subscripting might be easier to understand and maintain.


at: http://ibmmainframes.com/about58458.html

.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3053
Location: NYC,USA

PostPosted: Thu Aug 31, 2017 11:34 pm
Reply with quote

This is very much of Beginners question and has answered several times in past and you would only know if you do your own research instead of blindly posting it on the Expert forum.

Google "difference between index and subscript cobol site:ibmmainframes.com" and your learning is right there.
Back to top
View user's profile Send private message
Deepak kumar25

New User


Joined: 25 Aug 2017
Posts: 3
Location: india

PostPosted: Fri Sep 01, 2017 11:34 am
Reply with quote

@Rohit

Thanks for your kind reply. hats off..
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Cobol file using index COBOL Programming 2
No new posts Finding faulty logic Subscript out of... COBOL Programming 5
No new posts DL/I status code AK for GU call using... IMS DB/DC 1
No new posts Add column to existing records using ... JCL & VSAM 2
No new posts choice of clustering index DB2 3
Search our Forums:

Back to Top