What you want is to combine QSORT and BSEARCH apis.
Or, another approach would be to create another data structure that
allows for %lookup:
D DS based(records__)
D records dim(%elem(record))
D comp#s like(comp#)
D overlay(records:1)
D prod#s like(prod#)
D overlay(records:*next)
D curdats like(curdat)
D overlay(records:*next)
D curprcs like(curprc)
D overlay(records:*next)
D statuses like(status)
D overlay(records:*next)
D gl#s like(gl#)
D overlay(records:*next)
D records__ S * inz(%addr(record))
(forgive the completely off columnar coding in the d-specs)
With this secondary structure, you can fetch into your MODS and the
second struct provides individual arrays over each subfield that will
contain the same data as the fetch block and allow for lookups.
Have fun!
Kind regards,
Michael P. Scott
Programmer Analyst II | Merch-Setup Engineer Liaison
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Timothy Adair
Sent: Wednesday, November 18, 2009 1:43 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Lookup in a M-O DS
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.
Here's my DS:
D Record ds occurs(2000)
D Comp# 4 0
D Prod# 7 0
D CurDat 8 0
D CurPrc 7 4
D Status 1
D GL# 7 0
I am populating this with an SQL cursor loop, and doing Order By the
last field, GL#. Now I need to be able to do some kind of lookup on the
GL# field and return the element number that gets the hit.
I know I can do something funky, like do a loop that checks each
occurrence of the GL# field, or pull the GL# field out of the DS and
make it its own array (both ugly), but isn't there a built-in function
for this? I tried %lookup but that doesn't compile if it's not an
array.
Help? (TIA.)
--
This is the RPG programming on the IBM i / System i (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.