Consider for example a list of articles in stock in a toys store:
%rec: Item %key: Description Description: 2cm metal soldier WWII Amount: 2111 Description: Flying Helicopter Indoor Maxi Amount: 8 ...
It would be natural to identify the items by their descriptions, but it is also error prone: was it “Flying Helicopter Indoor Maxi” or “Flying Helicopter Maxi Indoor”? Was “Helicopter” in lower case or upper case?
It is quite common in databases to use some kind of numeric “Id” to
uniquely identify items like those ones. That is because numbers are
easy to increment and manipulate. So we could add a new
Id field and use it as the primary key:
%rec: Item %key: Id %mandatory: Description Id: 0 Description: 2cm metal soldier WWII Amount: 2111 Id: 1 Description: Flying Helicopter Indoor Maxi Amount: 8 ...
A problem of this approach is that we must be careful to not assign already used ids when we introduce more articles in the database. Other than its uniqueness, it is not important which number is associated with which article.
To ease the management of those Ids database systems use to provide a
facility called “auto-counters”. Auto-counters can be implemented in
recfiles using the
%auto directive in the record descriptor.
Its usage is:
%auto: field1 field2 ... fieldN
The list of field names are separated by one or more blank characters.
There can be several
%auto fields in the same record
descriptor, the effective list of auto-generated fields being the
union of all the entries.
Note that the auto fields are generated at the beginning of the new
records, in the same order they are found in the
The concrete effect of the
%auto directive depends on the type
of the affected field. The following sections document how.