Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Confusion b/w index and subscript

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
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    Post subject: Confusion b/w index and subscript
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: 8154
Location: East Dubuque, Illinois, USA

PostPosted: Thu Aug 31, 2017 8:02 am    Post subject: Reply to: Confusion b/w index and subscript
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    Post subject: Reply to: Confusion b/w index and subscript
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: 8154
Location: East Dubuque, Illinois, USA

PostPosted: Thu Aug 31, 2017 12:12 pm    Post subject: Reply to: Confusion b/w index and subscript
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

Active User


Joined: 29 Apr 2008
Posts: 175
Location: Maryland

PostPosted: Thu Aug 31, 2017 7:09 pm    Post subject:
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: 397
Location: USA

PostPosted: Thu Aug 31, 2017 8:02 pm    Post subject: Reply to: Confusion b/w index and subscript
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

Senior Member


Joined: 21 Sep 2010
Posts: 1788
Location: NY,USA

PostPosted: Thu Aug 31, 2017 11:34 pm    Post subject:
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    Post subject: Reply to: Confusion b/w index and subscript
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    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am
No new posts setting new limit Key values for inde... srilata83 DB2 1 Fri Feb 10, 2017 9:24 pm
No new posts Order BY AND Index Nileshkul DB2 2 Sat Dec 31, 2016 6:33 pm
No new posts Several errors during building altern... Andi1982 JCL & VSAM 11 Wed Jul 06, 2016 7:39 pm
No new posts Drop building Alternate Index for a p... bhavin.mehta JCL & VSAM 6 Mon Jul 04, 2016 3:47 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us