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

where we need to use subscripting and where Indexing


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
richa.setia

New User


Joined: 23 Mar 2005
Posts: 10
Location: Noida

PostPosted: Wed May 11, 2005 6:31 pm
Reply with quote

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
View user's profile Send private message
Ashutosh Shrinet

New User


Joined: 22 Aug 2004
Posts: 10
Location: New Delhi

PostPosted: Thu May 12, 2005 5:19 pm
Reply with quote

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
View user's profile Send private message
ashutosh719

New User


Joined: 06 Apr 2005
Posts: 12

PostPosted: Sat May 14, 2005 10:47 am
Reply with quote

Also, index is preferred one...due to enhanced execution speed...
refer stern/stern for more...

thanks.
Back to top
View user's profile Send private message
narasimharao_koganti

New User


Joined: 26 Apr 2005
Posts: 11
Location: pune

PostPosted: Tue May 17, 2005 9:48 pm
Reply with quote

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
View user's profile Send private message
vasanthanc

New User


Joined: 01 Apr 2005
Posts: 58

PostPosted: Thu May 19, 2005 11:17 am
Reply with quote

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
View user's profile Send private message
swaran_msc

New User


Joined: 19 May 2005
Posts: 5
Location: Bangalore

PostPosted: Thu May 19, 2005 12:05 pm
Reply with quote

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
View user's profile Send private message
Mohan.r

New User


Joined: 07 Mar 2005
Posts: 2

PostPosted: Thu May 19, 2005 12:36 pm
Reply with quote

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
View user's profile Send private message
pa1chandak
Currently Banned

New User


Joined: 31 Jan 2006
Posts: 55

PostPosted: Thu Feb 02, 2006 1:31 pm
Reply with quote

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
View user's profile Send private message
kshalini

New User


Joined: 20 Feb 2007
Posts: 8
Location: Banglore

PostPosted: Mon Mar 12, 2007 5:49 pm
Reply with quote

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
View user's profile Send private message
kshalini

New User


Joined: 20 Feb 2007
Posts: 8
Location: Banglore

PostPosted: Mon Mar 12, 2007 5:52 pm
Reply with quote

value will be difnitely same but what i want to know is the exact difference with example
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Mon Mar 12, 2007 9:53 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Mar 13, 2007 12:59 am
Reply with quote

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
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts array indexing PL/I & Assembler 4
No new posts DB2 indexing DB2 5
No new posts Indexing in db2 with expressions DB2 4
No new posts Indexing issue DB2 1
No new posts FIELD(1:4): compilation is indexing t... COBOL Programming 7
Search our Forums:

Back to Top