Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

which is faster?

Status
Not open for further replies.

nxm150

Programmer
May 22, 2002
78
US
I need to build an internal table. I can either build 1 talbe with 8 occurances or build 2 tables with 4 occurances each. This table will be search for each record. The top 4 occurances will be searched 1 time per record. The last 4 occurances can be searched more than 1 time per record. Should I build 1 or 2 tables?
 
Just thought about this a bit more and I will build the table with the 1st four being the fields that is searched more than once per record and the last 4 will be the ones that is searched once per record.
 
Can you supply a bit more information about the nature of the lookups? If this is happening 100 times/day, who cares? If it is happening 1,000,000 times/day, maybe we care, etc... The more info you supply, the better our suggestions will be on target.

Tom Morrison
 
The number of records my program will process varies but sometimes it does process over 1 million records.
 
Size of item(s) being searched?

Possible values (there appear to be at most 4 of each type)?

Clustering of values?





Tom Morrison
 
Here is my table definiton...

01 WS-INTERNAL-CONVERSION-TBL.
05 WS-TBL-VALUE
OCCURS 1 TO 20 TIMES
DEPENDING ON WS-TABLE-SIZE.
10 WS-TBL-FIELD1 PIC X(18).
10 WS-TBL-FIELD2 PIC X(20).
10 WS-TBL-FIELD3 PIC X(20).

Input file will contain field 1 and field 2. I need to compare these 2 fields from the file against table and move the corresponding field 3 when there is a match. There always will be a match.

Occurs depending is because I am building my internal table from a DB2 table and values maybe added in the future.
 
I will presume, from your problem statement, that the values for field 1 and field 2 are independent -- that is, that for the first search (1/record) you are only concerned about the value of field 1 matching, and that for the second search (many/record) you are concerned onoy about the value of field 2 matching. This would indicate that two tables are a better idea, since attempting to place the two tables together doesn't seem to make any logical sense and would probably obscure your intent. Also, by whatever amount the extra entries for the second search make the table larger for the first search, you will be slowing the overall process.

Since you are populating the table from a DB2 table I can presume that you will be able to fetch the values in sorted order. This brings both
Code:
SEARCH
and
Code:
SEARCH ALL
into play.

So most likely you want to have something like:
Code:
01  WS-INTERNAL-CONVERSION-TBL1.                     
    05  WS-TBL1-VALUE                                
           OCCURS 1 TO 20 TIMES                     
           DEPENDING ON WS-TABLE1-SIZE
           ASCENDING KEY IS WS-TBL1-FIELD1
           INDEXED BY WS-TBL1-INX.              
        10  WS-TBL1-FIELD1        PIC X(18).      
        10  WS-TBL1-FIELD3        PIC X(20).      

01  WS-INTERNAL-CONVERSION-TBL2.                     
    05  WS-TBL2-VALUE                                
           OCCURS 1 TO 20 TIMES                     
           DEPENDING ON WS-TABLE2-SIZE
           ASCENDING KEY IS WS-TBL2-FIELD2
           INDEXED BY WS-TBL2-INX.              
        10  WS-TBL2-FIELD2        PIC X(20).      
        10  WS-TBL2-FIELD3        PIC X(20).

Code:
SEARCH
is usually implemented in a manner that searches from occurrence 1 to occurrence N (as required by the COBOL standard). If a table is typically going to have only 4 entries, then it is probably best to use
Code:
SEARCH
.

Code:
SEARCH ALL
is usually implemented with a binary search, and requires that the searched values be in sorted order. For table sizes greater than 8 occrrences or so,
Code:
SEARCH ALL
will most likely be faster.

Note, however, that
Code:
SEARCH
may be faster than
Code:
SEARCH ALL
if you know a priori significant information about the relative frequency of the values you will be using to match in the search.

So, are you familiar with
Code:
SEARCH [ALL]
? You might have something like:
Code:
SEARCH ALL WS-TBL1-VALUE
    AT END MOVE ALL "*" TO OUTPUT-VALUE
    WHEN WS-TBL1-FIELD1 (WS-TBL1-INX)
        MOVE WS-TBL1-FIELD3 (WS-TBL1-INX) TO OUTPUT-VALUE
END-SEARCH

Tom Morrison
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top