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



Tim,

To be honest, I'm not sure.  I'd have to dig around to find out details.

Again, the better idea is to use qsort and bsearch.  Heck, here's the
code:
(Prototypes for bsearch and qsort taken from Hans post here: 
http://archive.midrange.com/rpg400-l/200207/msg00386.html)


     H dftactgrp(*no) bnddir('QC2LE')

     D qsort           pr                  extproc('qsort')
     D   base                          *   value
     D   num                         10i 0 value
     D   width                       10i 0 value
     D   compare                       *   procptr value

     D bsearch         pr              *   extproc('bsearch')
     D   key                           *   value
     D   base                          *   value
     D   num                         10i 0 value
     D   size                        10i 0 value
     D   compare                       *   procptr value

     d CompareByCode...
     d                 pr            10i 0
     d  element1                           const likeds(dlrDs)
     d  element2                           const likeds(dlrds)

     d CompareByName...
     d                 pr            10i 0
     d  element1                           const likeds(dlrDs)
     d  element2                           const likeds(dlrds)

     D DlrDs           Ds                  Qualified based( TEMPLATE )
     D  Idx                                Like(Int10)
     D  Code                               Like(CsRecd.CsDele)
     D  Type                               Like(A_1)
     D  Grp#                               Like(CsRecd.CsGrp#)
     D  Dlr#                               Like(CsRecd.CsDlr#)
     D  Name                               Like(CsRecd.CsName)
     D  Stat                               Like(DaRecd.DaStat)
     D  City                               Like(DaRecd.DaCity)

     d myArray         ds                  likeds(dlrDs) dim(2500)
     d searchValue     ds                  likeds(dlrDs)
     d returnedEntry   ds                  likeds(dlrDs)
based(returnedEntryPtr)


     d currentNumberOfEntries...
     d                 s             10u 0

      // Begin Mainline
      /free
         //load array, make sure currentNumberOfEntries is updated

         // bsearch = binary search, must have a sorted array
         //now sort, then search by Code subfield
         qsort(myArray
               : currentNumberEntries
               : %size(DlrDs)
               : %paddr(CompareByCode));
         searchValue.code = 10;
         returnedEntryPointer = bsearch(searchValue
                                       : myArray
                                       : currentNumberEntries
                                       : %size(DlrDs)
                                       : %paddr(CompareByCode));
         if returnEntryPoint <> *NULL;
           //found it do something with returnedEntry
         endif;

         //now sort, then search by Name subfield
         qsort(myArray
               : currentNumberEntries
               : %size(DlrDs)
               : %paddr(CompareByName));
         searchValue.name = 'Charles';
         returnedEntryPointer = bsearch(searchValue
                                       : myArray
                                       : currentNumberEntries
                                       : %size(DlrDs)
                                       : %paddr(CompareByName));
         if returnEntryPoint <> *NULL;
           //found it do something with returnedEntry
         endif;

         *INLR = *ON
         return;
      /end-free
      //end mainline

     p CompareByCode...
     p                 b
     d CompareByCode...
     d                 pi            10i 0
     d  element1                           const likeds(dlrDs)
     d  element2                           const likeds(dlrds)
      /free
          if element1.code < element2.code;
             return -1;
          elseif element1.code > element2.code;
             return 1;
          endif;
          return 0;
      /end-free
     p CompareByCode...
     p                 e

     p CompareByName...
     p                 b
     d CompareByName...
     d                 pi            10i 0
     d  element1                           const likeds(dlrDs)
     d  element2                           const likeds(dlrds)
      /free
          if element1.name < element2.name;
             return -1;
          elseif element1.name > element2.name;
             return 1;
          endif;
          return 0;
      /end-free
     p CompareByCode...
     p                 e
 
HTH,


Charles Wilt
--
iSeries Systems Administrator / Developer
Mitsubishi Electric Automotive America
ph: 513-573-4343
fax: 513-398-1121
  

> -----Original Message-----
> From: rpg400-l-bounces@xxxxxxxxxxxx 
> [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Tim Kredlo
> Sent: Thursday, February 09, 2006 11:12 AM
> To: 'RPG programming on the AS400 / iSeries'
> Subject: RE: Problem with based data structures
> 
> Charles,
> 
> Thanks for the suggestion. I will look into both sort methods.
> 
> I know I can sort the data structures by sub-fields if I go 
> through the
> hoops of declaring the sub-fields using 'overlay' instead of the much
> simpler 'likeds'. (Don't you end up with identical data 
> structures using
> either method?) This isn't one of those methods that 'don't 
> work' is it?
> 
> 
> Thanks for your help.
> 
> Tim Kredlo
> 
> 
> 
> -----Original Message-----
> From: rpg400-l-bounces@xxxxxxxxxxxx 
> [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
> On Behalf Of Wilt, Charles
> Sent: Thursday, February 09, 2006 4:59 AM
> To: RPG programming on the AS400 / iSeries
> Subject: RE: Problem with based data structures
> 
> Tim,
> 
> Why other to do the copy from the fixed version of the array to the
> variable size one?
> 
> Instead of trying to use %lookup and SORTA, which don't work well with
> DS arrays ( you _CAN'T_ sort/search on subfields)*, use the 
> bsearch and
> qsort C runtime functions.
> 
> There are plenty of examples on the web and in the archives 
> of using the
> bsearch and qsort from within RPGLE.
> 
> *note: I've seen some interesting hoops here on the people have jumped
> through trying to work around this, some work, some don't really.
> However, using qsort and bsearch are the best solutions.  
> They are easy
> and 100% effective.  
> 
> HTH,
> 
> Charles Wilt
> --
> iSeries Systems Administrator / Developer
> Mitsubishi Electric Automotive America
> ph: 513-573-4343
> fax: 513-398-1121
>   
> 
> > -----Original Message-----
> > From: rpg400-l-bounces@xxxxxxxxxxxx 
> > [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Tim Kredlo
> > Sent: Wednesday, February 08, 2006 9:19 PM
> > To: RPG400-L@xxxxxxxxxxxx
> > Subject: Problem with based data structures
> > 
> > Help!
> > 
> >  
> > 
> > I am having difficulty accomplishing the following:
> > 
> > I need to create and fill a data structure that will hold an 
> > array of up to
> > approximately 2500 elements.
> > 
> > The exact number will not be known until run time.
> > 
> > Each element of the array will be like (likeds) a 94 character data
> > structure.
> > 
> > I need to be able to resize the 2500 element data structure 
> > to remove any
> > unfilled elements.
> > 
> > I need to be able to sort the data structure by any of the 
> sub-fields.
> > 
> >  
> > 
> > This is what I have done so far:
> > 
> >  
> > 
> > Declared a data structure 'template' for each element of both 
> > arrays (Dlr
> > and Dlr1):
> > 
> > D DlrDs           Ds                  Qualified          
> > 
> > D  Idx                                Like(Int10)        
> > 
> > D  Code                               Like(CsRecd.CsDele)
> > 
> > D  Type                               Like(A_1)          
> > 
> > D  Grp#                               Like(CsRecd.CsGrp#)
> > 
> > D  Dlr#                               Like(CsRecd.CsDlr#)
> > 
> > D  Name                               Like(CsRecd.CsName)
> > 
> > D  Stat                               Like(DaRecd.DaStat)
> > 
> > D  City                               Like(DaRecd.DaCity)
> > 
> > A_1 is declared as 1A
> > 
> > CsRecd.CsDele is declared as 1A
> > 
> > CsRecd.CsGrp# is declared as 6P 0
> > 
> > CsRecd.CsDlr# is declared as 6P 0
> > 
> > CsRecd.CsName is declared as 40A
> > 
> > DaRecd.DaStat is declared as 10A
> > 
> > DaRecd.DaCity is declared as 20A
> > 
> >  
> > 
> > Declared 2 pointers:
> > 
> > D DlrBase         S               *   Inz 
> > 
> > D DlrBas1         S               *   Inz
> > 
> >  
> > 
> > Declared two data structures based on the above pointers:
> > 
> > D                 Ds                  Based(DlrBase)      
> > 
> > D  Dlr                          94A   Varying             
> > 
> > D                                     Dim(2500)           
> > 
> > D                                     Ascend              
> > 
> > D  DlrIdx                             Like(DlrDs.Idx)     
> > 
> > D                                     Overlay(Dlr : 1)    
> > 
> > D  DlrCode                            Like(DlrDs.Code)    
> > 
> > D                                     Overlay(Dlr : *Next)
> > 
> > D  DlrType                            Like(DlrDs.Type)    
> > 
> > D                                     Overlay(Dlr : *Next)
> > 
> > D  DlrGrp#                            Like(DlrDs.Grp#)    
> > 
> > D                                     Overlay(Dlr : *Next)
> > 
> > D  DlrDlr#                            Like(DlrDs.Dlr#)    
> > 
> > D                                     Overlay(Dlr : *Next)
> > 
> > D  DlrName                            Like(DlrDs.Name)    
> > 
> > D                                     Overlay(Dlr : *Next)
> > 
> > D  DlrCity                            Like(DlrDs.City)    
> > 
> > D                                     Overlay(Dlr : *Next)
> > 
> > D  DlrStat                            Like(DlrDs.Stat)    
> > 
> > D                                     Overlay(Dlr : *Next)
> > 
> >  
> > 
> > D                 Ds                  Based(DlrBas1)       
> > 
> > D  Dlr1                         94A   Dim(2500)            
> > 
> > D                                     Ascend               
> > 
> > D  Dlr1Idx                            Like(DlrDs.Idx)      
> > 
> > D                                     Overlay(Dlr1 : 1)    
> > 
> > D  Dlr1Code                           Like(DlrDs.Code)     
> > 
> > D                                     Overlay(Dlr1 : *Next)
> > 
> > D  Dlr1Type                           Like(DlrDs.Type)     
> > 
> > D                                     Overlay(Dlr1 : *Next)
> > 
> > D  Dlr1Grp#                           Like(DlrDs.Grp#)     
> > 
> > D                                     Overlay(Dlr1 : *Next)
> > 
> > D  Dlr1Dlr#                           Like(DlrDs.Dlr#)     
> > 
> > D                                     Overlay(Dlr1 : *Next)
> > 
> > D  Dlr1Name                           Like(DlrDs.Name)     
> > 
> > D                                     Overlay(Dlr1 : *Next)
> > 
> > D  Dlr1City                           Like(DlrDs.City)     
> > 
> > D                                     Overlay(Dlr1 : *Next)
> > 
> > D  Dlr1Stat                           Like(DlrDs.Stat)     
> > 
> > D                                     Overlay(Dlr1 : *Next)
> > 
> >  
> > 
> > I had hoped that I could have declared these using 'likeds', 
> > but I don't
> > think I could have made them 'varying' or been able to sort by the
> > sub-fields. Please tell me I am wrong about that, because it 
> > sure would make
> > maintenance easier.
> > 
> > What I would really like to be able to do is "SortArray
> > (QlfdDs((QlfdDs.Field1:Ascend)(QlfdDs.Field2:Descend)))".
> > 
> > (In my dreams)
> > 
> >  
> > 
> > I then created 2 user spaces, initialized with blanks('x'40') 
> > and retrieved
> > their pointers (DlrBase and DlrBas1).
> > 
> > I filled elements of Dlr1, the non-varying array, from files 
> > till done and
> > kept the number of elements filled (Idx = 1820 today).
> > 
> >  
> > 
> > The following statement was then executed to fill Dlr and 
> > resize it to only
> > contain the filled elements:
> > 
> > %SubArr( Dlr : 1 : Idx ) = %SubArr ( Dlr1 : 1 : Idx );
> > 
> >  
> > 
> > Immediately after that statement was executed, debug evals 
> showed the
> > following:
> > 
> > > EVAL dlr1(1)                                                
> >            
> > 
> >   DLR1(1) =                                                   
> >            
> > 
> >             
> > ....5...10...15...20...25...30...35...40...45...50...55...60 
> > 
> >        1   '   -AA000000000050MISCELLANEOUS                   
> >           '
> > 
> >       61   '                                  '               
> >            
> > 
> > > EVAL dlr(1)                                                 
> >            
> > 
> >   DLR(1) =                                                    
> >            
> > 
> >             
> > ....5...10...15...20...25...30...35...40...45...50...55...60 
> > 
> >        1   '   -AA000000000050MISCELLANEOUS                   
> >           '
> > 
> >       61   '                                    ' 
> > 
> > I don't know if the e-mail formatting will show this 
> > correctly, but the end
> > "'" for DLR(1) is in position 95 and the end "'" for DLR(1) 
> > is in position
> > 97.
> > 
> >  
> > 
> > I then did the following debug evals:                       
> > 
> > > EVAL dlr1name(1)                                        
> > 
> >   DLR1NAME(1) = 'MISCELLANEOUS                           '
> > 
> > > EVAL dlrname(1)                                         
> > 
> >   DLRNAME(1) = '50MISCELLANEOUS                         '
> > 
> >  
> > 
> > Notice that the two data structures (Dlr and Dlr1) are 
> > declared identically,
> > but the DlrName field now appears to start 2 characters prior 
> > to Dlr1name
> > field.
> > 
> >  
> > 
> > I thought that perhaps this was an 'align' issue, so stuck 
> > 'align' on the
> > declaration for both Dlr and Dlr1 and recompiled. (I don't 
> > know if there is
> > more that I would need to do.)There were no warnings in the 
> > compile listing
> > about mis-aligned fields. I re-ran and received the same results.
> > 
> >  
> > 
> > I am stuck as to where to look next.
> > 
> >  
> > 
> > All code and debug info was 'cut and pasted' into this email. 
> > So if you see
> > what appears to be a typo, it is probably wrong in my code 
> > and needs to be
> > pointed out.
> > 
> > Thanks in advance for any help. 
> > 
> >  
> > 
> >  
> > 
> >  
> > 
> >  
> > 
> >  
> > 
> >  
> > 
> >  
> > 
> >  
> > 
> >  
> > 
> >  
> > 
> > -- 
> > 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.
> > 
> > 
> 
> -- 
> 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.
> 
> 
> 
> -- 
> 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 ...

Follow-Ups:

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.