View previous topic :: View next topic
|
Author |
Message |
Nagendran
New User
Joined: 24 Jan 2007 Posts: 89 Location: USA
|
|
|
|
I have the below array.
Code: |
01 WS-TABLE-A.
05 WS-COL-A OCCURS 9000 times indexed by WS-A
05 WS-COL-B OCCURS 9000 times. |
Is it possible for me to access the array WS-COL-B using the index WS-A.
Can anybody explain?
Thanks,
Nagendran.R |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Is it possible for me to access the array WS-COL-B using the index WS-A. |
No.
Quote: |
Can anybody explain? |
The second array has no index, so it would be subscripted rather than indexed.
Neither array has any elementary items. . . If you want to continue the topic, suggest you post something more realistic. . . |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Is this an Interview question?
If it is, it certainly doesn't represent realistic coding (I hope), unless it's an example of extremely poor coding techniques.
If this were to be presented during a code-review, suffice to say it would be immediately rejected. In some shops, your A$$ would be fired on the spot!
But to answer your question, NO.
Bill |
|
Back to top |
|
|
Nagendran
New User
Joined: 24 Jan 2007 Posts: 89 Location: USA
|
|
|
|
Hi
Sorry for the confusion..
Below is the code
01 WS-TABLE-A.
05 WS-COL-A PIC X(09) OCCURS 9000 times indexed by WS-A
05 WS-COL-B PIC X(02) OCCURS 9000 times.
IS it possible for me to the access thh array WS-COL-B using the index WS-A.
If not can any body tell me why????
As per my understanding index will always have displacement.......
Thanks,
Nagendran |
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Even though you possibly CAN, I would NOT as it can confuse others.
Why in the Wide World of Sports would you do this anyway?
It certainly doesn't represent a technique (IMHO) which would pass code review.
Why add this confusion? It makes no sense whatsoever and you may find colleagues asking you the same. You could simply assign a separate index to the second array and be done with it _O R_ eliminate the first index and resort to subscripts.
You need to think of the next poor slob who needs to maintain your "idea", especially in an ABEND situation when he/she must resolve this index displacement and determine which array it was pointing to when the program went belly-up.
Stick with the KISS method -
"A method to fend off creeping featurism and control complexity of development. "Keep It Simple Stupid".
Bill |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Even though you possibly CAN, I would NOT as it can confuse others. |
And with the example provided, it would run "wrong", possibly not get caught in testing, and would be a nightmare to figure out when the eventual problem/abend occurred. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Nagendran wrote: |
As per my understanding index will always have displacement....... |
The same links pointed to by CG mention that indexes contain the occurrence number, not the actual displacement.
BTW, I still find it interesting that I can still learn new things and used properly, I see no problem with it.
Dick wrote: |
And with the example provided, it would run "wrong" |
Sorry I missed that, but huh? |
|
Back to top |
|
|
Nagendran
New User
Joined: 24 Jan 2007 Posts: 89 Location: USA
|
|
|
|
thank you all for ur comments |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
William Thompson wrote: |
The same links pointed to by CG mention that indexes contain the occurrence number, not the actual displacement. |
I interpret that to mean that the index corresponds to an occurrence number but it actually consists of the displacement (4-byte binary). If the index is displayed or used in an arithmetic comparison, it will display as and act as it it's an occurrence number though. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Sorry I missed that, but huh? |
The example arrays have elements of different length.
Quote: |
However, the element length of the table being referenced and of the table that the index-name is associated with should match. Otherwise, the reference will not be to the same table element in each table, and you might get runtime errors. . |
|
|
Back to top |
|
|
CICS Guy
Senior Member
Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
Back to top |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
In order to tell how this would work we need the elementary item definitions.
In the following the same index may be used for both and it should work ok:
Code: |
01 WS-TABLE-A.
05 WS-COL-A OCCURS 9000 times indexed by WS-A.
10 PIC X.
05 WS-COL-B OCCURS 9000 times.
10 PIC X.
|
In the following 2 examples if the same index is used for both it would not work as someone might expect them to:
Code: |
01 WS-TABLE-A.
05 WS-COL-A OCCURS 9000 times indexed by WS-A.
10 PIC X.
05 WS-COL-B OCCURS 9000 times.
10 PIC X(2).
|
Code: |
01 WS-TABLE-A.
05 WS-COL-A OCCURS 9000 times indexed by WS-A.
05 WS-COL-B OCCURS 9000 times.
10 PIC X.
|
This last one is the closest I could assume from the original question. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
The COBOL Language Reference manual (link at the top of the page) is quite clear in stating that you can reference WS-COL-B using WS-A index. However, if the table elements are not the same size, as in Douglas Wilder's second example, the COBOL manual states you will not be referencing the same element in both tables and can get runtime errors as a result.
So you can do it, but it can be a source of production abends and therefore the recommendation is very strongly not to do it. |
|
Back to top |
|
|
|