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

Advantage of INDEX over OCCURS


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

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Mon Oct 06, 2008 5:53 pm
Reply with quote

Hi,

I am using a Array which is used to load the data sequentially,process it and write into on Output File.

Array is declared like this.

10 WS-TEMP-ARRAY OCCURS 10 TIMES INDEXED BY W-INDX.
15 WS-TEMP-YR PIC X(02).
15 WS-TEMP-NO PIC X(20).

For my Case as i m not searching the array ,just loading the Array and processing it sequentially. Will Index is advantageous over Suscript ? If so what are the reasons for that?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Oct 06, 2008 6:24 pm
Reply with quote

using a subscript requires the occurance number be converted to an offset.

SETting the INDEX up by 1 increases the offset, not the occurance, therefore no conversion is necessary.

and it does not matter that you are not searching the table, you are addressing each occurance.

It is all in the programmer guide, top of page.
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: Mon Oct 06, 2008 6:26 pm
Reply with quote

I've always heard that IBM's claim is INDEX is faster than subscripts. However, for a 10-element table that is not searched, I doubt it really matters whether INDEX or subscript is used.
Back to top
View user's profile Send private message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Mon Oct 06, 2008 6:41 pm
Reply with quote

Robert Sample wrote:
However, for a 10-element table that is not searched, I doubt it really matters whether INDEX or subscript is used.


For this Scenario will INDEX is preffered or not.
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: Mon Oct 06, 2008 6:54 pm
Reply with quote

The Programmer's Guide doesn't specify a lower limit for efficiency, but I doubt you'd be able to easily measure the CPU time difference with only 10 table entries:
Quote:
8.1.3 Handling tables efficiently


Pay close attention to table-handling operations, particularly when they are a major part of an application. Several techniques can improve the efficiency of these operations and can also influence the optimizer. The return for your efforts can be significant.

The following two guidelines affect your choice of how to refer to table elements:

* Use indexing rather than subscripting.

Although the compiler can eliminate duplicate indexes and subscripts, the original reference to a table element is more efficient with indexes than with subscripts, even if the subscripts are BINARY. The value of an index has the element size factored into it, whereas the value of a subscript must be multiplied by the element size when the subscript is used. The index already contains the displacement from the start of the table, and this value does not have to be calculated at run time. However, subscripting might be easier to understand and maintain.

* Use relative indexing.

Relative index references (that is, references in which an unsigned numeric literal is added to or subtracted from the index name) are executed as fast as direct index references and sometimes faster. There is no merit in keeping alternative indexes with the offset factored in.
Back to top
View user's profile Send private message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Mon Oct 06, 2008 7:02 pm
Reply with quote

Thanks Robert.But will the Usage of Index for this Scenario is disadvantagable when compared to subscript or for this scenario there will not be much diff if we use any of these(Index/Subscript)
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: Mon Oct 06, 2008 7:10 pm
Reply with quote

IBM's manual statement I quoted earlier is clear. INDEX is always more efficient than subscripts, period. What I am saying is that for the table you have defined, the "more efficient" isn't going to be worth worrying about; probably a few nanoseconds or microseconds. Leave it indexed and move on to more important issues.
Back to top
View user's profile Send private message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Mon Oct 06, 2008 7:19 pm
Reply with quote

Robert Sample wrote:
IBM's manual statement I quoted earlier is clear. INDEX is always more efficient than subscripts, period. What I am saying is that for the table you have defined, the "more efficient" isn't going to be worth worrying about; probably a few nanoseconds or microseconds. Leave it indexed and move on to more important issues.



Thanks Robert icon_biggrin.gif
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 Cobol file using index COBOL Programming 2
No new posts Updating a 1 byte thats in occurs mul... DFSORT/ICETOOL 6
No new posts DL/I status code AK for GU call using... IMS DB/DC 1
No new posts Add column to existing records using ... JCL & VSAM 2
No new posts choice of clustering index DB2 3
Search our Forums:

Back to Top