Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Using different index for a cobol indexed table

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Using different index for a cobol indexed table
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: 1238
Location: Richfield, MN, USA

PostPosted: Fri Dec 13, 2013 12:37 am    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Dec 13, 2013 12:40 am    Post subject: Reply to: Using different index for a cobol indexed table
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: 7913
Location: Bellevue, IA

PostPosted: Fri Dec 13, 2013 12:57 am    Post subject:
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    Post subject: Reply to: Using different index for a cobol indexed table
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: 1278
Location: Belgium

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

didn't google very hard/good I guess.
My google "cobol index and subscripts" top 2 :
* http://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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Fri Dec 13, 2013 1:19 pm    Post subject: Reply to: Using different index for a cobol indexed table
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am
No new posts Cobol list of programs being called biswajit.dattagupta COBOL Programming 5 Tue Nov 01, 2016 2:10 am
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us