× 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.



From looking at your data structure, it looks like you're trying to
create an array that is 10a per element over a field that will only ever
be 10a. Also, afaik, data structure arrays must be qualified.

What about this?


Struct DS Dim(32767) Qualified
Based(pStruct)
Ptr *
Retcod 10i 0
field 10a

Then use the qsort to sort it and bsearch function to do a lookup. The
inability for %lookup to work on data structure arrays sucks, but qsort
and bsearch are handy tools to use anyway.

// C Search Routine (requires a sorted array)
D bsearch PR * ExtProc('bsearch
D LookFor * Value
D DataStart * Value
D Elements 10u 0 Value
D Size 10u 0 Value
D CompFunc * ProcPtr Value

Here's a link to the archive with an example written by Hans on how to
use qsort & bsearch.
http://archive.midrange.com/rpg400-l/200207/msg00386.html

Below I've modified the search function procedure interface to resemble
your situation.

P compare5a b
D compare5a pi 10i 0
D element1 const Likeds( struct )
D element2 const Likeds( struct )
// then for the comparison you can do...
If element1.field > element2.field;


Just bits of info here, but I hope it helps.

Kurt Anderson
Application Developer
Highsmith Inc

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Paul Jackson
Sent: Monday, August 13, 2007 5:51 PM
To: RPG400-L@xxxxxxxxxxxx
Subject: Data structure array with lookup on subfield?

Hello,

I want to create a dynamically allocated array to store popular searches
with each element storing a pointer, return code and field name like
below:

Struct DS Dim(32767)
Based(pStruct)
Ptr *
Retcod 10i 0
field 10a
* define array over subfield of structure
fieldarr 10a Dim(32767) Overlay(field)

Now I want to allocate elements as needed and populate the structure.
The problem I have is that I want to be able to do a lookup on the field
part of the structure (which is basically the key), something like

pos = %lookup(Infield: fieldarr : 1: lastelemfilled);

Which would tell me if an element with the infield value already exists
and if so I would use the ptr and rtncod fields from that element
otherwise I would allocate memory and add another element to Struct.

Unfortunately I have not been able to figure out how to do this, the
multiple entries in struct with the DIM keyword work fine but I can't
figure out how to define an array over the field subfield.

Any help with this would be appreciated.

Paul
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing
list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.



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.