× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello,

I've searched the archives and can't find an answer on this. How do you do a Lookup in a multiple-occurrence data structure. This is my first one and I can't seem to find a (good) solution.

You can't use the LOOKUP opcode or %LOOKUP BIF with a multiple occurence DS. You can, however, use a loop.

found = 0;
for x = 1 to %elem(Record);
%occur(Record) = x;
if GL# = KeyToSearchFor;
found = x;
endif;
endfor;

Also, in case you aren't aware, IBM added a new type of data structure array in V5R2 that you might want to consider using for new code. Personally, I like it better than MODS because it lets you reference multiple occurrences simultaneously, and it also works a lot better with prototypes (via LIKEDS).

The newer method would look like this:

D Record ds qualified
D dim(2000)
D Comp# 4 0
D Prod# 7 0
D CurDat 8 0
D CurPrc 7 4
D Status 1
D GL# 7p 0

However, it doesn't really solve the problem. You still can't use LOOKUP/%LOOKUP. You'd still have to do this:

found = 0;
for x = 1 to %elem(Record);
if Record(X).GL# = SearchKey;
found = x;
leave;
endif;
endfor;

There's a 3rd variant called an "overlay array" (I guess) that CAN do what you're looking for... however, I suspect by the time I post this, someone else will have already given you that answer. :)

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.