|
Alan, I don't think the code you have posted will work as you plan. Your first array is an array of data-structures. You second array is a simple array. Basing your second array to somewhere in-between the first array is not going to help you. Probably the following example will illustrate it more clearly... d SomeDS ds Qualified Based(ptrSomeDS) d Dim(5) d Elem1 2a d Elem2 2a d SomeArr s 2a Based(ptrSomeArr) Dim(5) d I s 10i 0 /FREE // SomeDS looks like this - // Index Elem1 Elem2 // 1 A1 C1 // 2 B1 C2 // 3 C1 C3 // 4 D1 C4 // 5 E1 C5 ptrSomeDS = %alloc(%size(SomeDS)); SomeDS(1).Elem1 = 'A1'; SomeDS(1).Elem2 = 'C1'; SomeDS(2).Elem1 = 'B1'; SomeDS(2).Elem2 = 'C2'; SomeDS(3).Elem1 = 'C1'; SomeDS(3).Elem2 = 'C3'; SomeDS(4).Elem1 = 'D1'; SomeDS(4).Elem2 = 'C4'; SomeDS(5).Elem1 = 'E1'; SomeDS(5).Elem2 = 'C5'; ptrSomeArr = %addr(SomeDS(1).Elem1); // Now SomeArr looks like this - // A1 // C1 // B1 // C2 // C1 // This will return 2 instead of the intended 3 from the original DS. I = %lookup('C1':SomeArr); *inlr = '1'; /END-FREE ------------------------------ message: 3 date: Fri, 21 Jul 2006 11:53:18 -0600 from: "Alan G. Campin" <agc@xxxxxxxxxxxxxxxxxxxx> subject: Re: Lookup in a array of records Found a solution. I think it is kinda ugly but it seems to work. Define second array based on pointer and then in dynamic allocation code, add one line of code to load the address of the function array. I still wonder if there is not a more elegant way to do this. d g_FunctionList... d ds Qualified d Based(g_ptrFunctionList) d Dim(32764) d FunctionName... d 50a d ServiceProgramName... d Like(StdNam) d ServiceProgramLibrary... d Like(StdNam) d ServiceProcedure... d 64a Varying d pptrProcedure... d Like(StdPrcPtr) d g_FunctionName... <<< New Array d s 50a Based(g_ptrFunctionName) d Dim(32764) Position = %Lookup(Function : g_FunctionName: 1 : g_FunctionCount); If Position = 0; Position = LoadFunction(%TrimR(Function)); EndIf; LoadFunction code. g_FunctionCount += 1; If g_FunctionCount > g_ListSize; If g_FunctionCount = 1; g_ListSize = cInitialListSize; g_ptrFunctionList = %Alloc(g_ListSize * %Size(g_FunctionList)); Else; g_ListSize += cListIncrement; g_ptrFunctionList = %ReAlloc(g_ptrFunctionList : g_ListSize * %Size(g_FunctionList)); EndIf; // Get pointer into function name list for lookup. g_ptrFunctionName = %Addr(g_FunctionList(1).FunctionName); << New code EndIf; Haven't tested yet but it should work. ****************************************************************************** The information contained in this electronic communication and any accompanying document is confidential, may be attorney-client privileged, and is intended only for the use of the addressee. It is the property of Ryder System, Inc. Unauthorized use, disclosure or copying of this communication, or any part of it, is strictly prohibited and may be unlawful. If you have received this communication in error, please notify the sender immediately by return email, and destroy this communication and all copies of it, including all attachments. Electronic communication may be susceptible to data corruption, interception and unauthorized tampering and Ryder disclaims all liability of any kind for such actions or any consequences that may arise directly or indirectly therefrom. ******************************************************************************
As an Amazon Associate we earn from qualifying purchases.
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.