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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table Search Issue

Status
Not open for further replies.

jimvv06

Programmer
Aug 19, 2009
1
US
Hello,

I am fairly new to COBOL programming and I am running into a bit of a coding block.

Currently I am coding a program that searches fields in a large array. The problem I am running into is the array I am searching has multiple records that need to be reported out. Currently the only way I can figure out how to code the application is it will find only first record, report the field, and that’s it. I need to fix this search so it will search the array entirely and report all the correct fields. I have tried coding this program with a SEARCH ALL statement and that didn’t work. Please let me know if you can help me out. Thank you!



Here is the current code. Please let me know if you need more

PERFORM 4100-HLQ-CNTL
UNTIL SEARCH-SUB > ARRAY-STOP.
4100-HLQ-CNTL.
ADD 1 TO SEARCH-SUB.
MOVE ABM-HLQ(SEARCH-SUB) TO HLQ-SEARCH.

PERFORM 4200-JOB-COST-TABLE-SEARCH.

4200-JOB-COST-TABLE-SEARCH.
* SEARCH JOB ARRAY WITH HLQ8 SEARCH
SET COSTS-INDEX TO 1.
SEARCH REGDB-COSTS
AT END PERFORM 4300-JOB-COST-TABLE-SRCH-HLQ4
WHEN JOB-NAME(COSTS-INDEX)(1:8) =
HLQ-SEARCH(1:8)
PERFORM 5000-MATCH-FOUND
END-SEARCH.
4300-JOB-COST-TABLE-SRCH-HLQ4.



HLQ-SEARCH (variable for this example)
HLQ
ABCDEFGH


JOB-NAME (variables in the array to be searched)
000100 ABCDEFGH|
000200 ABCDEFGH|
000300 ABCDEFGH|
000400 ABCDEFGH|
000500 ABCDEFGH|



Current output (note that only the first and only field is being reported)
HLQ
--------
ABCDEFGH


Desired Output (note that all 5 Job names are reported)
HLQ
--------
ABCDEFGH
ABCDEFGH
ABCDEFGH
ABCDEFGH
ABCDEFGH




 
SEARCH ALL is a binary search (typically), and will only work if the data in the table are sorted and the data are reasonably discrete. This necessarily isn't the situation you seem to encounter, so let us dismiss this.

Your code may be corrected if you start with the index of the last hit in your search and then call the search again. AT END will indicate that there are no more hits between your starting index and the end of the table.

Measurement is not management.
 
You have too much left out. What you have given makes little sense. Please include the data (table) description, as a mininum.
 
Try what Glenn9999 said but be sure to increment the index before you search the next time. If you leave the index where the last hit was, you'll find a match at that entry again.
 
Hi Jim,

If the like-valued JOB-NAME fields in the table are in succession as shown in your post, here's a sleight variation on Glenn's idea that may help (untested):

When you get a search hit, set an increment(INCR) field to zero and PERFORM the hit code you have in mind adding 1 to the INCR and SET YR-IDX UP BY INCR until JOB-NAME(YR-IDX) not = to the original hit(saved) JOB-NAME(YR-IDX).

This would replace the multiple SEARCHes suggested and hopefully be more efficient.

Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
Binary searches (search All) are only good on keyed tables where the key is ordered and unique as stated above. Sounds like you need a multi level perform incrementing the X and y indexes. When the value you are looking for is found then write out the desired output. This searches all the fields in a array for a value.

Perform varying x from 1 by 1
until greater than max-x

Perform varying x from 1 by 1
until greater than max-x

perform varying y from 1 by 1
until greater than max-y
If value found
do this
end-if
end perform
end-perform

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top