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

Using different index for a cobol indexed table


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

New User


Joined: 07 Dec 2010
Posts: 16
Location: Bangalore

PostPosted: Fri Dec 13, 2013 12:10 am
Reply with quote

Hi all,
Could you please let me know what will happen if, we use an index variable which is declared as index to a table, to a different indexed table?

For eg: Table-1 is having Index-1
Table-2 is having Index-2

SET INDEX-1 TO 3
MOVE 'ABCD' TO TABLE-2(INDEX-1)

Will TABLE-2(3) have value 'ABCD' ?

Checked the manuals, also searched in google, but not able to find out a conclusive thread.

Sorry, if it is a very basic question. In that case please tell me where I can get my answer.

Thanks,
Heeraj R
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Fri Dec 13, 2013 12:37 am
Reply with quote

For clarity purposes, I would think you would want to use separate indexes for separate tables. Rules about indexes and index data items are in the Language Reference Manual.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Dec 13, 2013 12:40 am
Reply with quote

Does TABLE-2 have a different index (IE: INDEX-2)? Even though it may be "legal" to do this, I've always used an intermediate binary-fullword.

EG:

Code:

03  WS-FWORD PIC 9(08) BINARY.
*
SET  WS-FWORD TO INDEX-1.
SET  INDEX-2  TO WS-FWORD.

Give it a try....
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Dec 13, 2013 12:57 am
Reply with quote

The answer to your question is ... IT DEPENDS.

Specifically, how long is each element of table 1 and how long is each element of table 2? If the elements are the same length, then the answer to your question is yes. If the elements are not the same length, then the answer to your question is no. Indexes are displacements into the table and hence are NOT the same as subscripts, particularly if the elements are different lengths.

It may be worth spending the time to understand this code and output:
Code:
     05  WS-FIELDS-1             PIC X(10) VALUE 'ABCDEFGHIJ'.
     05  WS-TABLE-1              REDEFINES WS-FIELDS-1
                                 OCCURS 5
                                 INDEXED BY WI-1.
         10  WS-T1-VALUES        PIC X(02).
     05  WS-FIELDS-2             PIC X(10) VALUE 'ZYXWVUTSRQ'.
     05  WS-TABLE-2              REDEFINES WS-FIELDS-2
                                 OCCURS 10
                                 INDEXED BY WI-2.
         10  WS-T2-VALUES        PIC X(01).
*
 PROCEDURE DIVISION.
 0000-MAIN-PARA.

     SET WI-1                    TO  3.
     SET WI-2                    TO  7.
     DISPLAY ' 1 2 3 4 5     1234567890'.
     DISPLAY WS-FIELDS-1 '     ' WS-FIELDS-2.
     DISPLAY ' ' .
     DISPLAY '1:1 ' WS-T1-VALUES (WI-1).
     DISPLAY '1:2 ' WS-T1-VALUES (WI-2).
     DISPLAY '2:1 ' WS-T2-VALUES (WI-1).
     DISPLAY '2:2 ' WS-T2-VALUES (WI-2).
and output of
Code:
  1 2 3 4 5     1234567890
 ABCDEFGHIJ     ZYXWVUTSRQ

 1:1 EF
 1:2 GH
 2:1 V
 2:2 T
Back to top
View user's profile Send private message
Heeraj

New User


Joined: 07 Dec 2010
Posts: 16
Location: Bangalore

PostPosted: Fri Dec 13, 2013 8:10 am
Reply with quote

Thanks all, I got the concept now. icon_smile.gif
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Dec 13, 2013 1:00 pm
Reply with quote

didn't google very hard/good I guess.
My google "cobol index and subscripts" top 2 :
* ibmmainframes.com/post-23045.html
Quote:
The subscripts represent the occurance number of an element where as
indexes denote the displacement of the element from the beginning.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Dec 13, 2013 1:19 pm
Reply with quote

Enterprise COBOL has an IBM Language Extension which allows the use of an index for subscripting other than on the table for which the index is defined.

As Robert has said, if you do this for tables with different element lengths, you probably won't get what you may expect.

Ordinarily, as Bill has said, don't do it directly, as it will confuse.

There are some uses for the technique,
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 Load new table with Old unload - DB2 DB2 6
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 Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top