setll, setgt, read, reade, readp

30 Views


In RPGLE (especially in native record-level access), file operations like SETLL, SETGT, READ, READE, and READP are used to navigate through database files manually, record by record. These operations are used primarily with full procedural file handling, not embedded SQL.

Here’s a breakdown of each and examples for clarity:


๐Ÿ”ท 1. SETLL (Set Lower Limit)

Positions the file pointer at the record equal to or just greater than the given key.

๐Ÿ”น Example:

Setll KeyValue MyFile;
Read MyFile;

If a record with the matching key exists, READ will retrieve it. If not, it reads the next higher key.


๐Ÿ”ท 2. SETGT (Set Greater Than)

Positions the file pointer at the first record strictly greater than the key.

๐Ÿ”น Example:

Setgt KeyValue MyFile;
Read MyFile;

This is useful for skipping the current key value and moving to the next one.


๐Ÿ”ท 3. READ

Reads the next sequential record.

๐Ÿ”น Example:

Read MyFile;
Dow Not %EOF(MyFile);
   Dsply MyFileField;
   Read MyFile;
EndDo;

Use %EOF(file) or *INxx to check for end of file.


๐Ÿ”ท 4. READE (Read Equal)

Reads records with a key that matches the most recent SETLL/SETGT key.

๐Ÿ”น Example:

Setll 'PARIS' Customers;
Reade 'PARIS' Customers;
Dow Not %EOF(Customers);
   Dsply Name;
   Reade 'PARIS' Customers;
EndDo;

Used for reading all records with the same key (e.g., city = 'PARIS').


๐Ÿ”ท 5. READP (Read Previous)

Reads the previous record in the file.

๐Ÿ”น Example:

Setll *HighVal MyFile;
Readp MyFile;
Dow Not %EOF(MyFile);
   Dsply MyFileField;
   Readp MyFile;
EndDo;

๐Ÿ”ท 6. READPE (Read Previous Equal)

Reads previous records with a key equal to the last SETLL/SETGT key.


๐Ÿงพ Example: All Combined

**FREE
Dcl-F Customers Usage(*Input) Keyed;

Dcl-S City Char(20);

City = 'PARIS';

Setll City Customers;
Reade City Customers;

Dow Not %EOF(Customers);
   Dsply ('Customer: ' + Name + ', City: ' + City);
   Reade City Customers;
EndDo;

*INLR = *ON;
Return;

๐Ÿ’ก Tips:

Operation Direction Condition
READ Forward All records
READE Forward Equal key
READP Backward All records
READPE Backward Equal key
SETLL Set pointer ≤ Key  
SETGT Set pointer > Key  

 

Post Comments