View previous topic :: View next topic
|
Author |
Message |
mf_karthik
New User
Joined: 26 Jul 2005 Posts: 55
|
|
|
|
can anybody explain subscript and index clearly with some examples plz?
i searched the forum already |
|
Back to top |
|
|
laxmi
New User
Joined: 24 May 2005 Posts: 9
|
|
|
|
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 |
|
|
fixdoubts
New User
Joined: 21 Oct 2005 Posts: 54
|
|
|
|
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 |
|
|
ShreekanthVB
New User
Joined: 16 Nov 2005 Posts: 1 Location: Bangalore
|
|
|
|
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 |
|
|
tam
New User
Joined: 02 Nov 2005 Posts: 12 Location: zz
|
|
|
|
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 |
|
|
sungang77
New User
Joined: 03 Nov 2005 Posts: 46 Location: Shanghai, China
|
|
Back to top |
|
|
|