View previous topic :: View next topic
|
Author |
Message |
richa.setia
New User
Joined: 23 Mar 2005 Posts: 10 Location: Noida
|
|
|
|
Can anybody give the scenarios where we need to use subscripting and where we nede to use Indexing? Also the difference between the two. |
|
Back to top |
|
|
Ashutosh Shrinet
New User
Joined: 22 Aug 2004 Posts: 10 Location: New Delhi
|
|
|
|
Hi, Richa
this is the basic differnce between subscript and index,Subscript refers to the array occurrence while index is the displacement (in no of bytes) from the beginning of the array. An index can only be modified using PERFORM, SEARCH & SET. Need to have index for a table in order to use SEARCH, SEARCH ALL. |
|
Back to top |
|
|
ashutosh719
New User
Joined: 06 Apr 2005 Posts: 12
|
|
|
|
Also, index is preferred one...due to enhanced execution speed...
refer stern/stern for more...
thanks. |
|
Back to top |
|
|
narasimharao_koganti
New User
Joined: 26 Apr 2005 Posts: 11 Location: pune
|
|
|
|
hi,
index is used for faster access. when the table size is large it is better to go for the index. because index represents the displacement position starting of the array.
the primary difference between index and subscript is, index represents the displacement position, where as subscript represents the occurance position of the element. |
|
Back to top |
|
|
vasanthanc
New User
Joined: 01 Apr 2005 Posts: 58
|
|
|
|
thats right. As subscript represents the occurance position, when ever an array element is referred, to retrieve the value, displacement position will be calculated internally and this will take some time as it includes multiplication and in case the array size is large, there will be much time difference. So its better to go for index in case of large arrays |
|
Back to top |
|
|
swaran_msc
New User
Joined: 19 May 2005 Posts: 5 Location: Bangalore
|
|
|
|
Yeah... What they said is correct. Also we have no need to declare the index variables in W-S Section whereas declaration is required for Subscript.
Thanks...
Corrections are Welcome |
|
Back to top |
|
|
Mohan.r
New User
Joined: 07 Mar 2005 Posts: 2
|
|
|
|
hi,
subscript is advisable to use when u have to point few number of records say 50.
If u have large number of records it is wise one should use index.
In Index concept, data will be pointed internally in binary format that is why it will not take time to point it out. where as it n't the same with subscript, internally it has to convert into binary form and then start pointing to the record and results in time-consuming.
I prefer to use index always. |
|
Back to top |
|
|
pa1chandak Currently Banned New User
Joined: 31 Jan 2006 Posts: 55
|
|
|
|
INDEXING IS BINARY SEARCH
AND SUBSCRIPT IS SERIAL SEARCH
IF I AM WRONG SOMEWHERE PLEASE CORRECT ME
THANK YOU
DO SEND ME THE REPLY
PAWAN
09822546416
// THE ONE I LOVE , I SHALL NEVER BLAME // |
|
Back to top |
|
|
kshalini
New User
Joined: 20 Feb 2007 Posts: 8 Location: Banglore
|
|
|
|
Please give elaborate example.
What I can undestand that since Index is defined while delaring an array when we refer a particular array occurence index access is faster because the memory is assigned for an array.
But when referred by subscripts the seach time is more because m/f has to search for teh exact location.
e.g:
01 NAMES.
05 NAME-TBL OCCURS 3 INDEXED BY T.
10 MY-NAME PIC X(10).
SET T TO 1
PERFORM VARYING T FROM 1 BY 1 UNTIL T=3
MOVE 'TONY' TO NAME-TBL(T)
END-PERFORM.
MOVE 2 TO WS-SUB.
DISPLAY 'NAME-TBL(WS-SUB)'NAME-TBL(WS-SUB).
SET T TO 1.
DISPLAY 'NAME-TBL(T)'NAME-TBL(T).
I am getting the same value in both of them
NAME-TBL(WS-SUB)TONY
NAME-TBL(T)TONY
So please elaborate whether the main difference lies in the access time as because when array is defined a fixed memory location is defined by index but for subscript it takes longer time to arraive at the exact location |
|
Back to top |
|
|
kshalini
New User
Joined: 20 Feb 2007 Posts: 8 Location: Banglore
|
|
|
|
value will be difnitely same but what i want to know is the exact difference with example |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Please search the forum and the Fine Manual.
The topic has been in the forum several times.
From
Quote: |
INDEXING IS BINARY SEARCH
AND SUBSCRIPT IS SERIAL SEARCH |
Not necessarily. Indexes may be used for a serial search. Subscripts may point directly at an entry with no serialization needed. Before SEARCH and SEARCH ALL were included in the language specification, binary searches were implemented using subscripts. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
kshalini wrote: |
So please elaborate whether the main difference lies in the access time as because when array is defined a fixed memory location is defined by index but for subscript it takes longer time to arraive at the exact location |
I don't think so....
In effect, the calculation for each is done a different times
Indexes are computed to the displacement when they are set or incremented.
Subscripts can be incremented up or down with little regard but the moment a subscripted element (with a variable subscript) is referenced, calculation time. Subscripted elements with literal subscripts are calculated at compile time.
The size of the table has no bearing on which is better, the usage is more the concern.
BTW, I don't think you can
PERFORM VARYING T FROM 1 BY 1 UNTIL T=3
if T is an index..... |
|
Back to top |
|
|
|