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


  • Subject: RE: bsearch on partial array elements
  • From: Alan Campin <Alan.Campin@xxxxxxxxxxxxx>
  • Date: Thu, 13 Jan 2000 09:42:46 -0700

Here is an example of how I would think you would do it. 

Original code. 

 p CompareProc     b                                       
 d                 pi                  like(StdBin)        
 d  ptrLookFor                         like(StdPtr)        
 d                                       value             
 d  ptrArrayElem                       like(StdPtr)        
 d                                       value             
                                                           
 d wfKey           s                   like(StdNam)        
 d                                     based(ptrLookFor)   
 d wfArrElt        s                   like(StdNam)        
 d                                     based(ptrArrayElem) 
                                                           
 d cLessThan       c                   const(-1)           
 d cGreaterThan    c                   const(1)            
 d cEqualTo        c                   const(0)            
                                                           
 c                   select                                
 c                   when      wfKey < wfArrElt          
 c                   return    cLessThan                 
 c                   when      wfKey = wfArrElt          
 c                   return    cEqualTo                  
 c                   when      wfKey > wfArrElt          
 c                   return    cGreaterThan              
 c                   endsl                               
 p CompareProc     e
                                     
Code modified to check a short key.
 
 p CompareProc     b                                             
 d                 pi                  like(StdBin)              
 d  ptrLookFor                         like(StdPtr)              
 d                                       value                   
 d  ptrArrayElem                       like(StdPtr)              
 d                                       value                   
                                                                 
 d wfKey           s                   like(StdNam)              
 d                                     based(ptrLookFor)         
 d wfArrElt        s                   like(StdNam)              
 d                                     based(ptrArrayElem)       
                                                                 
 d cLessThan       c                   const(-1)                 
 d cGreaterThan    c                   const(1)                  
 d cEqualTo        c                   const(0)                  
 d ShortElem       s              5
 d ShortKey        s              5

 c                   eval       SortElement = %substr(wfArrElt:1:5)

 c                   eval       SortKey     = %substr(wfKey:1:5)           
 c                   select                                      
 c                   when      SortKey < ShortElem           
 c                   return    cLessThan                  
 c                   when      SortKey = ShortElem           
 c                   return    cEqualTo                   
 c                   when      SortKey > ShortElem           
 c                   return    cGreaterThan               
 c                   endsl                                
 p CompareProc     e                                      

-----Original Message-----
From: David.Biggs@bernardmatthews.com
[mailto:David.Biggs@bernardmatthews.com]
Sent: Thursday, January 13, 2000 8:45 AM
To: rpg400-l@midrange.com
Subject: bsearch on partial array elements




I have an RPG IV program in which I am using 'bsearch' to search a number of
arrays, which is working fine (and quickly too !). However, one of the
arrays is
defined with an element length of 37A, but I want to search it by the first
30
bytes only.
The trailing 7 bytes of the array elements will not contain blanks, so I
assume
that the bsearch routine will not work correctly when comparing 30A to 37A.

Any ideas how I can get round this without creating more arrays ?

TIA,
Dave Biggs





+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator:
david@midrange.com
+---
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.