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



Well, with this size array, you can only fit just over 1000 elements into
the DS (64k max), so if this will always be a suitable amount, just
DIM(1170), and keep track of the number of elements, to speed up %Lookup
slightly.

If you need more elements than 1,170, it gets a bit trickier.  You have to
create a user space, allocate a pointer to it, and create a single BASED DS
that is based on the pointer, and 'walk' the pointer through the user space,
incrementing it by the size of the DS (56 bytes).  Instead of %lookup, you
would use the qsort() and bsearch() API.

I have only done this once, and it didn't make it to production, so the best
place for this example would be the Redbook, "Who knew you could do that
with RPGIV?  A Sorcerer's Guide to System Access and More".

There is also a way to directly allocate memory, and use that instead of a
user space, but I have never done this myself.

On 1/11/06, Grizzly M <grizzlym@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
> I'm sure this has been asked before but I can't seem to find what I'm
> looking for in the archives
>
> I'll post the code that I have to help paint the picture
> D AddItmIdx       S              5S 0 Inz(0)
> D BuyItmIdx       S              5S 0 Inz(0)
> D                 DS
> D BuyerInfo                     56A   DIM(1)
> D   Buyer                        3A   Overlay(BuyerInfo:1)
> D   Item                        27A   Overlay(BuyerInfo:4)
> D   Quantity                    11S 2 Overlay(BuyerInfo:31)
> D   LastPurch                    8S 0 Overlay(BuyerInfo:43)
> D   Vendor                       6A   Overlay(BuyerInfo:51)
>
> /Free
>
> BuyItmIdx = %LookUp(PBITNO:Item);
> IF BuyItmIdx > 0;
>     Quantity(BuyItmIdx) = PBORQT;
>
>     If WrkDate > LastPurch(BuyItmIdx);
>        LastPurch(BuyItmIdx) = WrkDate;
>     EndIF;
>
> Else;
>     AddItmIdx += 1;
>     Buyer(AdditmIdx) = PBVNNO;
>     Item(additmidx) = PBITNO;
>     Quantity(Additmidx) = PBORQT;
>     LastPurch(AddItmIdx) = WrkDate;
>     Vendor(AddItmIdx) = PBVNNO;
> EndIF;
>
> /Free
> I want to be able to increase the size of the array on an as needed
> basis. I'm pretty sure this can be done with pointers, but I can't
> figure out how. Can anyone offer some suggestions?
>
> --
> 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.
>
>


--
"Enter any 11-digit prime number to continue..."
"In Hebrew SQL, how do you use right() and left()?..." - Random Thought
"If all you have is a hammer, all your problems begin to look like nails"

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.