CHAIN vs SETLL/READE
CHAIN & READE, These are the two Operations that are used to read the data from a database file using a specified Key data.
SETLL Operation is used to point to the record provided in the Key data.
How do we use?
CHAIN
CHAIN (Search Arguments/Key Fields) FILENAME ;
IF %FOUND(FILENAME) ;
// Required Program Logic
ENDIF ;
Click Here to find more details about CHAIN.
SETLL/READE
SETLL (Search Arguments/Key Fields) FILENAME ;
READE (Search Arguments/Key Fields) FILENAME ;
DOW NOT %EOF(FILENAME) ;
// Required Program Logic
READE (Search Arguments/Key Fields) FILENAME ;
ENDDO ;
SETLL
SETLL (Search Arguments/Key Fields) FILENAME ;
IF %FOUND(FILENAME) ;
// Required Program Logic
ENDIF ;
Click Here to find more details about SETLL/RPGLE.
Now, What to use When?
- If the Data base file used has Unique key constraint and/or if only one/first matching record is required by the Program, CHAIN would be the best choice.
- If the Data base file used has Unique key constraint and/or if the program only intend to check if matching record is present or not (and doesn't require the data), SETLL would be the best choice (with %FOUND).
- If the Data base file may have multiple records with specified Search Arguments/Key fields and all records are required to be read, READE would be the best choice in combination with SETLL.
Perfect. Thank you!
ReplyDeleteGlad, You liked it.
Delete