Some code fragments for bsearch. This just looks up a qualified file
name in a dynamically allocated array. Template is a V6R1 keyword. It
would have to be changed to Based(StdNullPointer)
d TD_DetailRecord...
d ds Qualified
d Template
d FILE_NAME...
d Like(StdNam)
d LIBRARY_NAME...
d Like(StdNam)
d SERVICE_PROGRAM_NAME...
d Like(StdNam)
d SERVICE_PROGRAM_LIBRARY...
d Like(StdNam)
d SERVICE_PROCEDURE...
d 50a
d BSearchCompare...
d pr Like(StdInt)
d ExtProc('BSearchCompare')
d PR_PointerToLookForValue...
d Like(StdPtr)
d Value
d PR_PointerToArrayElement...
d Like(StdPtr)
d Value
d FindNameApi...
d pr Like(StdPtr)
d ExtProc('bsearch')
d PR_PtrLookForValue...
d Like(StdPtr)
d Value
d PR_PtrArrayElement...
d Like(StdPtr)
d Value
d PR_NumberOfElements...
d Like(StdIntUns)
d Value
d PR_SizeOfEachElement...
d Like(StdIntUns)
d Value
d PR_PtrCompareProcedure...
d Like(StdPrcPtr)
d Value
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Structure of Detail Record available for triggers.
d DetailRecord...
d ds LikeDs(TD_DetailRecord)
d Based(ptrDetailRecord)
d FileNameQ...
d ds LikeDs(TD_QualifiedName)
// See if file is active for triggers.
FileNameQ.Name = InTriggerBuffer.PhysicalFileName;
FileNameQ.Library = InTriggerBuffer.PhysicalFileLibrary;
ptrDetailRecord = FindNameApi(%Addr(FileNameQ) :
g_PtrBaseOfDetailRecords :
g_NumberOfDetailRecordsLoaded:
%Size(DetailRecord) :
%PAddr('BSearchCompare') );
If ptrDetailRecord = *Null;
Return;
EndIf;
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* BSearchCompare
* Called by bsearch to compare two values and return result.
* Input - Pointer to Look for value.
* Pointer to Array Element.
* Out - None
* Returns - Result Code.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
p BSearchCompare...
p b
d pi Like(StdInt)
d InPointerToLookForValue...
d Like(StdPtr)
d Value
d InPointerToArrayElement...
d Like(StdPtr)
d Value
d LookForKey...
d s Like(StdQNam)
d Based(InPointerToLookForValue)
d ArrayElement...
d s Like(StdQNam)
d Based(InPointerToArrayElement)
d cLessThan...
d c Const(-1)
d cGreaterThan...
d c Const(1)
d cEqualTo...
d c Const(0)
/Free
Select;
When LookForKey < ArrayElement;
Return cLessThan;
When LookForKey = ArrayElement;
Return cEqualTo;
When LookForKey > ArrayElement;
Return cGreaterThan;
EndSl;
/End-Free
p e
---------- Forwarded message ----------
From: Jon Paris <jon.paris@xxxxxxxxxxxxxx>
Date: Fri, May 25, 2012 at 3:00 PM
Subject: Re: Using %LOOKUP with an Array Data Structure in SQLRPGLE
To: rpg400-l@xxxxxxxxxxxx
On 2012-05-25, at 4:51 PM, rpg400-l-request@xxxxxxxxxxxx wrote:
Sorry, forgot to mention that I'm at V5R4.
Then qsort/bsearch are your best options Dave. %Lookup support for DS
Arrays is not until V7.
Jon Paris
www.partner400.com
www.SystemiDeveloper.com
--
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.