View previous topic :: View next topic
|
Author |
Message |
Heeraj
New User
Joined: 07 Dec 2010 Posts: 16 Location: Bangalore
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Heeraj
New User
Joined: 07 Dec 2010 Posts: 16 Location: Bangalore
|
|
|
|
Thanks all, I got the concept now. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|