ISO/IEC 7816-4 Annex C: Record Pointer Management

Record Pointer Management

ISO 7816 Part 4: Interindustry Commands for Interchange

ISO 7816 part 4, section..1 2 3 4 5 6 7 8 9 annex.. A B C D E F

The record pointer, and why it causes bugs

Commands that operate on record-structured files can address a record by absolute number or relative to a current record pointer the card maintains. That pointer is stateful, and state that is invisible in the command being sent is a reliable source of defects.

What the pointer is

When a record-structured elementary file is selected, the card holds a notion of which record is “current”. Commands such as READ RECORD can then ask for the current record, the next one, or the previous one, rather than naming a number. Each such operation may move the pointer.

Why relative addressing exists

It exists because record identifiers need not be unique. In a file where several records share an identifier, the only way to walk through the matches is to ask for the first occurrence and then repeatedly ask for the next. Absolute numbering cannot express “the next record whose identifier is X”.

It is also more compact for sequential reads: iterating a log file with a relative read avoids recomputing and resending a record number each time.

The three behaviours to keep straight

  • Absolute addressing names a record number directly. Predictable, and it sets the pointer to the record addressed.
  • Relative addressing names first, last, next or previous. What it returns depends entirely on where the pointer currently is.
  • Pointer invalidation. Selecting a different file, or a failed operation, can leave the pointer undefined. A relative read against an undefined pointer is an error, not a read of record one.

Cyclic files add a twist

In a cyclic file the record numbering is defined relative to the most recent write: record one is the newest record, not the oldest. Combined with a pointer that moves as you read, this is the single most common source of “the log is in the wrong order” reports. Appending a record rotates the ring and changes what every number refers to.

Practical guidance

  • Prefer absolute addressing wherever the record number is known. It is stateless, it is self-describing in a trace, and it survives an unexpected reselection.
  • Use relative addressing only for genuine iteration — walking occurrences of a repeated identifier, or streaming a log — and treat the whole loop as one atomic sequence.
  • Never interleave. Any other command between two relative reads may move or invalidate the pointer.
  • Re-establish deliberately. After selecting a file, issue an explicit first-occurrence or absolute read rather than assuming a starting position.
  • Log the pointer state. When traces show a relative read returning something unexpected, the pointer is almost always the explanation, and it is invisible unless you track it.
  • Illustrative example. Reading every record carrying identifier 01 means: select the file, read the first occurrence of 01, then repeatedly read the next occurrence until the card reports that none remains. Inserting an unrelated command anywhere in that loop can silently restart or truncate it.

Authoritative source

For the normative description of record referencing and current record pointer behaviour, refer to ISO/IEC 7816-4:2020, published by ISO. This page is Ambimat’s own explanation and does not reproduce or replace the standard.