LESSON 2 · Easy

Data and files: PF, LF, DDS and native I/O

Plain-English notes, safe code skeletons, IBM i commands, and a checkpoint you can use before opening the deeper question bank.

After this lesson

Learning notes

Model the record before choosing the operation

A physical file stores rows and can have keyed access paths. A logical file describes another view over one or more physical files, often with a different key or selected fields. DDS can define these objects; SQL DDL is another way to describe the database. The choice should follow the existing system and the team’s migration plan.

Before coding, name the record format, key, expected cardinality, and consistency need. That short design note prevents a developer from using a keyed operation where a set-based query or a range read is clearer.

  1. State the business key and expected number of rows
  2. Choose native I/O or SQL based on the access pattern
  3. Define not-found and end-of-file behavior
  4. Define the lock and commitment expectation
  5. Test empty, duplicate, and concurrent cases

Read safely with native RPG operations

CHAIN is a keyed lookup. SETLL positions an access path and READE reads records with an equal key. READ reads the next record in sequence. Every operation needs an explicit status check so stale fields are never treated as a successful read.

For a write, retrieve the intended record, validate the business rule, and update that record. State what happens if another job holds the record lock. A strong interview answer describes the operator-visible message and the retry or conflict path.

Same keyed lookup in two RPG styles

Fixed format

FCustomers       IF   E             K DISK
C     customerId    CHAIN     CustomerRec
C                   IF        %FOUND(Customers)
C                   EVAL      greeting = 'Hello ' + %TRIM(name)
C                   ENDIF

Fully free

**FREE
dcl-f Customers keyed usage(*input);
chain customerId CustomerRec;
if %found(Customers);
  greeting = 'Hello ' + %trim(name);
endif;

DDS and SQL can coexist during modernization

Many IBM i estates contain DDS-described files, SQL-created tables, and logical files that support older programs. Do not remove an access path just because a new SQL statement works in a test. Check which programs depend on record formats, key order, triggers, constraints, and journaling.

A practical migration is incremental: document the current object, add a tested SQL view or index when useful, move one access path, and keep a rollback plan.

Inspect the object before changing it

DSPFD FILE(APPDATA/ORDERS) TYPE(*BASIC)
DSPFFD FILE(APPDATA/ORDERS)
DSPDBR FILE(APPDATA/ORDERS)

Open the detailed question chapters

Practice checkpoint

Answer all five, then review the explanations. The interactive site stores your completed learning checkpoints in this browser.

  1. 1. Which operation positions without transferring a record?
    1. CHAIN
    2. READ
    3. READE
    4. SETLL
  2. 2. After a failed CHAIN, record fields are:
    1. Potentially still holding the previous values
    2. Automatically all zero
    3. Automatically NULL
    4. Guaranteed blank
  3. 3. Which loop stays within an equal-key group?
    1. WRITE followed by READ
    2. SETLL followed by READE
    3. SETGT followed by DELETE
    4. OPEN followed by UPDATE
  4. 4. What does CHAIN(N) request on an update disk file?
    1. A new record
    2. A commit
    3. A read without obtaining the normal update lock
    4. A next-member scan
  5. 5. An override is added after the file is already open. What must you inspect?
    1. Only the source member name
    2. Only the job priority
    3. The printer device
    4. The existing open data path and override scope
Show answer key and explanations

1. D — SETLL SETLL changes access-path position; retrieval requires a read operation.

2. A — Potentially still holding the previous values Always check %FOUND before consuming the buffer.

3. B — SETLL followed by READE READE retrieves the equal-key group until the relevant EOF condition.

4. C — A read without obtaining the normal update lock N is a nonlocking input extender; it does not make a later update automatically safe.

5. D — The existing open data path and override scope The current open path may already have resolved the file and member.

IBM documentation for this path