× 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: finding the right place in a RRN file
  • From: "Greg Thielen" <gregt@xxxxxxxx>
  • Date: Wed, 16 Apr 97 01:53:09 -0700

On 15 Apr 97 21:32:27 EDT, John Carr wrote:

>I'd be willing to bet that 90% of the programers who will see or who 
>will be asked to maintain/enhance the File/Program/Algorithm 
>would rather maintain a RPGII Level Breaking Matching record program. 
>  But I might be wrong.
>
>John Carr


Well, if you're right, I don't think it says much for our industry :)

A binary search is one of the simplest "textbook" algorithms.  I will
agree that when dealing with a data base file, a logical file would
probably be the best way to go depending on the situation, of
course).  Without going too far off topic, though, here's a non-ILE
RPG algotighm for a binary search of a file. 

DTLSIZ is the number of records in the file
DTLSTR is the search block starting record number
DTLEND is the search block ending record number
DTLRCD is the current file record number
ORILIS is the requested search value
ORILIN is the file compare value

 * Set the start, end, and middle record numbers of the file.
C                     MOVE *OFF      FOUND
C                     Z-ADD1         DTLSTR        
C                     Z-ADDDTLSIZ    DTLEND        
C           DTLEND    DIV  2         DTLRCD   
 *
 * Loop until the requested line number is found or we're out of
range.
C           FOUND     DOUEQ*ON                  
C           DTLRCD    ORLT DTLSTR                  
C           DTLRCD    ORGT DTLEND                  
 *
 * Get the subfile record and compare the line number (ORILIS)
 * to the requested line number (ORILIS).  If equal, set the
 * found indicator.
C           DTLRCD    CHAINMDTLSFL              90
C           *IN90     IFEQ *OFF
C           ORILIS    ANDEQORILIN                 
C                     MOVE *ON       FOUND
C                     ELSE
 *
 * If the requested value is less than the current value,
 * move up the block end record number.
 * Otherwise, move down the block starting record number.
C           ORILIS    IFLT ORILIN                  
C           DTLRCD    SUB  1         DTLEND        
C                     ELSE                         
C           DTLRCD    ADD  1         DTLSTR        
C                     ENDIF                          
 * 
 * Calcualte the mid-point between the start and end records:
 *  DTLRCD = ((DTLEND - DTLSTR) / 2) + DTLSTR
C           DTLEND    SUB  DTLSTR    DTLRCD        
C                     DIV  2         DTLRCD
C                     ADD  DTLSTR    DTLRCD      
 *
C                     ENDIF
C                     ENDDO                        



-------------------------
Greg Thielen
Innovative Systems Design
gregt@isda.com
http://www.isda.com


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This is the Midrange System Mailing List!  To submit a new message,   *
* send your mail to "MIDRANGE-L@midrange.com".  To unsubscribe from     *
* this list send email to MAJORDOMO@midrange.com and specify            *
* 'unsubscribe MIDRANGE-L' in the body of your message.  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.