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

Difference bw Subscript and Index in COBOL


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

New User


Joined: 26 Jul 2005
Posts: 55

PostPosted: Thu Nov 17, 2005 8:11 am
Reply with quote

can anybody explain subscript and index clearly with some examples plz?
i searched the forum already
Back to top
View user's profile Send private message
laxmi

New User


Joined: 24 May 2005
Posts: 9

PostPosted: Thu Nov 17, 2005 9:42 am
Reply with quote

hi,

subscript : it indicates the no of occurences of the table and it is a normal cobol variable
index : it indicates the offset from the begining of the table and by using the three cobol verbs (set ,serch,perform)we will do the operations on the index variable .we cannot display the index variable like normal cobol variable .we will not declare the index variable in the working storage section.
Back to top
View user's profile Send private message
fixdoubts

New User


Joined: 21 Oct 2005
Posts: 54

PostPosted: Thu Nov 17, 2005 10:39 am
Reply with quote

Apart from difference as lakmi as mentioned.

The difference occurs in the internal representations.

The subscripts represent the occurance number of an element where as
indexes denote the displacement of the element from the beginning.

Like if the we hava a PIC as 9(4)

the subscript for 2nd element is 2 and for Index its 4.

Due to which the indexs result in more efficient object code than
the subscript.

Pls correct if am wrong.

Regards,
Back to top
View user's profile Send private message
ShreekanthVB

New User


Joined: 16 Nov 2005
Posts: 1
Location: Bangalore

PostPosted: Thu Nov 17, 2005 10:43 am
Reply with quote

INDEX
You can create an index either with a particular table (using OCCURS INDEXED BY) or
separately (using USAGE IS INDEX).
For example:
05 TABLE-ITEM PIC X(8)
OCCURS 10 INDEXED BY INX-A.
The compiler calculates the value contained in the index as the occurrence number
(subscript) minus 1, multiplied by the length of the table element. Therefore, for
the fifth occurrence of TABLE-ITEM, the binary value contained in INX-A is (5 - 1) * 8,
or 32.

Subscript
If you use USAGE IS INDEX to create an index, you can use the index data item with
any table. For example:
77 INX-B USAGE IS INDEX.
. . .
PERFORM VARYING INX-B FROM 1 BY 1 UNTIL INX-B > 10
DISPLAY TABLE-ITEM (INX-B)
. . .
END-PERFORM.
INX-B is used to traverse table TABLE-ITEM above, but could be used to traverse
other tables also.
You can increment or decrement an index-name by an unsigned numeric literal.
The literal is considered to be an occurrence number. It is converted to an index
value before being added to or subtracted from the index-name.
Initialize the index-name with a SET, PERFORM VARYING, or SEARCH ALL statement.
You can then also use it in SEARCH or relational condition statements. To change the
value, use a PERFORM, SEARCH, or SET statement.
Use the SET statement to assign to an index the value that you stored in the index
data item defined by USAGE IS INDEX. For example, when you load records into a
variable-length table, you can store the index value of the last record read in a data
item defined as USAGE IS INDEX. Then you can test for the end of the table by
comparing the current index value with the index value of the last record. This
technique is useful when you look through or process the table.
Because you are comparing a physical displacement, you can use index data items
only in SEARCH and SET statements or for comparisons with indexes or other index
data items. You cannot use index data items as subscripts or indexes.

Subscript
In a two-dimensional table, the two subscripts correspond to the row and column
numbers. In a three-dimensional table, the three subscripts correspond to the
depth, row, and column numbers.
Back to top
View user's profile Send private message
tam

New User


Joined: 02 Nov 2005
Posts: 12
Location: zz

PostPosted: Thu Nov 17, 2005 2:34 pm
Reply with quote

Subscript represents occurrence of the Table Entry. Subscript can be represented explicitly and implicitly. Explicitly means thru occurrence of the table entry; implicitly means thru a data name. That data name should be defined as an independent item in the Working Storage Section. The most efficient definition of Subscript is Full-Word binary.

An Index is assigned to specific table thru INDEXED BY clause. Internally is represented by Index Register which is Full-Word binary. Specific index name can be used to reference a field from the table to which that index is assigned to index represents displacement value of the table entry from the beginning of the table.

Index represent displacement value of the table entry from the beginning of the table, subscript - occurrence of the table entry. To calculate the displacement of the table entry from its beginning when subscript is used takes 16 additional instructions from the system because of that the usage of the index is more efficient.
Back to top
View user's profile Send private message
sungang77

New User


Joined: 03 Nov 2005
Posts: 46
Location: Shanghai, China

PostPosted: Mon Nov 21, 2005 3:27 pm
Reply with quote

Use indexing rather than subscripting.
Although the compiler can eliminate duplicate indexes and subscripts, the original reference to a table element is more efficient with indexes than with subscripts, even if the subscripts are BINARY. 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.
There's more content in the following URL:
http://publibz.boulder.ibm.com/bookmgr_OS390/libraryserver/zosv1r7/index.html?BOOKS/igy3pg30/8.1.4?BOOKMARK=TRUE&SHELF=IGY3SH30.bks&DT=20050628164603&CASE=zosv1r70.bkc&FS=TRUE&TB=SCRIPT&PATH=/bookmgr_OS390/libraryserver/zosv1r7/
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 Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top