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
 

 

COBOL Index issue

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Nagendran

New User


Joined: 24 Jan 2007
Posts: 89
Location: USA

PostPosted: Thu Mar 12, 2009 1:19 am    Post subject: COBOL Index issue
Reply with quote

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
View user's profile Send private message

dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Mar 12, 2009 1:33 am    Post subject:
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Thu Mar 12, 2009 1:35 am    Post subject: Reply to: COBOL Index issue
Reply with quote

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
View user's profile Send private message
Nagendran

New User


Joined: 24 Jan 2007
Posts: 89
Location: USA

PostPosted: Thu Mar 12, 2009 1:41 am    Post subject: Reply to: COBOL Index issue
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Mar 12, 2009 1:42 am    Post subject: Re: COBOL Index issue
Reply with quote

Nagendran wrote:
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.
I think you can......
Quote:
Can anybody explain?
The INDEXED BY phrase specifies the indexes that can be used with a table. A table without an INDEXED BY phrase can be referred to through indexing by using an index-name associated with another table.
And
An index-name can be used to reference any table. 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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Thu Mar 12, 2009 2:08 am    Post subject: Reply to: COBOL Index issue
Reply with quote

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. icon_surprised.gif

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Mar 12, 2009 2:13 am    Post subject:
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Thu Mar 12, 2009 2:22 am    Post subject: Re: Reply to: COBOL Index issue
Reply with quote

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
View user's profile Send private message
Nagendran

New User


Joined: 24 Jan 2007
Posts: 89
Location: USA

PostPosted: Thu Mar 12, 2009 2:26 am    Post subject: Reply to: COBOL Index issue
Reply with quote

thank you all for ur comments
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: Thu Mar 12, 2009 2:37 am    Post subject: Re: Reply to: COBOL Index issue
Reply with quote

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
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Mar 12, 2009 3:10 am    Post subject:
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2150
Location: At my coffee table

PostPosted: Thu Mar 12, 2009 3:13 am    Post subject: Re: Reply to: COBOL Index issue
Reply with quote

Terry Heinze wrote:
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.
I think that he was refering to this line:
At run time, the contents of the index corresponds to an occurrence number for that specific dimension of the table with which the index is associated.
Back to top
View user's profile Send private message
Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Thu Mar 12, 2009 3:13 am    Post subject:
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7908
Location: Bellevue, IA

PostPosted: Thu Mar 12, 2009 3:39 am    Post subject:
Reply with quote

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
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 DFHRESPONSE returns issue divated CICS 3 Wed Nov 02, 2016 6:32 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


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