×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Table Search Issue

Table Search Issue

Table Search Issue

(OP)
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




RE: Table Search Issue

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.

RE: Table Search Issue

You have too much left out. What you have given makes little sense.  Please include the data (table) description, as a mininum.

RE: Table Search Issue

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.

RE: Table Search Issue

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
 

RE: Table Search Issue

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

 

RE: Table Search Issue

ignore the first perform cut and paste error

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close