View previous topic :: View next topic
|
Author |
Message |
Deepak kumar25
New User
Joined: 25 Aug 2017 Posts: 3 Location: india
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Deepak kumar25
New User
Joined: 25 Aug 2017 Posts: 3 Location: india
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2145 Location: USA
|
|
|
|
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 |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
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 |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
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 |
|
|
Deepak kumar25
New User
Joined: 25 Aug 2017 Posts: 3 Location: india
|
|
|
|
@Rohit
Thanks for your kind reply. hats off.. |
|
Back to top |
|
|
|