Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Chain read 2

Status
Not open for further replies.

bduke

Programmer
May 17, 2002
84
US
I set the key for the CHAIN read, but it doesn't find the correct record. My understanding is that if you set the key and then do a CHAIN it will find the record that matches that key... If that isn't correct let me know...


Thanks...
 
That is true, unless you have multiple keys and the key your are chaining with is only a patiral key. Then you can get any record that matched the partial key.
 
If there are multiple records with the same key, you are finding the first matching record using the chain operation. You could use setll and set up a loop that contains the reade operation and a filter for the record or record type you are seeking, design a unique key for the file for your application, sort the file to set up the order you desire, and or remove invalid records. One of these solutions should work for you.
 
Thanks both of those answers help.....
 
Could someone tell me if this will work.

A file has 5 keys. I want all recs that match the first 3.
Therefore, chain using the first 3 keys. That will locate and read the first one (if it exists). To retrieve the remaining, do a reade in a loop.

example of the code below.

Thanks for any advice.


*
C DelPickReleaseBEGSR
*
C KEY_MBCN CHAIN MBCNRES0
C IF %FOUND(MBCNRES0)
C DOW NOT %EOF(MBCNRES0)
C DELETE FGCREKN
*
C KEY_MBCN READE MBCNRES0
C ENDDO
C ENDIF
*
C ENDSR
*


 
Not a good idea to use CHAIN as a substitute for SETLL. The %EQUAL indicator is set on by SETLL if an exact match is found on your key. This has the advantage of being faster, since SETLL is almost always faster than an unneccesary read.

I'd code it like this:
Code:
 *                                                 
C     DelPickReleaseBEGSR                          
 *                                                 
C     KEY_MBCN      SETLL     MBCNRES0             
C                   IF        %EQUAL(MBCNRES0)     
C                   DOU       %EOF(MBCNRES0)   
C     KEY_MBCN      READE     MBCNRES0
C                   IF        NOT %EOF(MBCNRES0) 
C                   DELETE    FGCREKN              
C                   ENDIF
C                   ENDDO                          
C                   ENDIF                          
 *                                                 
C                   ENDSR                          
 *


"When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for here you have been, and there you will always long to return."

--Leonardo da Vinci

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top