Reads the previous sequential item-id from an index or the active select list.
READPREV
itemid-var
itemid-var The name of a variable to which the string value of each previous item-id is assigned.
vmc-var The name of a variable that is assigned the value count indicating the position of the multivalue within an attribute when an exploding sort has been processed using a BY-EXP or BY-EXP-DSND clause during the creation of the list or index.
svmc-var The name of a variable that is assigned the value count indicating the position of the subvalue within an attribute when an exploding sort has been processed using a BY-EXP-SUB or BY-EXP-SUB-DSND clause during the creation of the list or index.
listNumber Must be 0. Specifies the active select list.
indexSelectVar The name of the variable assigned to the index via a SELECT statement.
key-var The name of a variable to which is assigned the key value associated with the item-id retrieved. The key value consists of the actual values (within the associated item) of the attributes specified in the sort criteria for the index, separated by attribute marks.
If a list number is specified in the FROM clause and a RETURNING clause is included, key-var will return null.
setting-var The name of a variable to which the file I/O error code or zero is assigned. The file I/O error codes are described in File I/O and IPC Error Codes.
statement(s) One or more DataBasic statements:
- If the READPREV statement is used as the condition in a WHILE statement, the THEN/ELSE clauses must be omitted. In this case, the READPREV statement returns 1 (TRUE) if the read is successful or 0 (FALSE) if not.
- Otherwise, either a THEN or an ELSE clause (or both) must be included. The THEN clause is executed if the read is successful. The ELSE clause is executed if the list of item-ids or index has been exhausted, or if no selection has been performed.
The variable vmc-var is assigned the value count indicating the position of the multivalue within the attribute specified after the BY-EXP or BY-EXP-DSND connective. This value can be used in a dynamic array extraction after the item has been read (via a READ statement) to obtain multivalues in exploded sort order. See also the topic Using Indexes.
READPREV ACCRECID FROM ACCRECINDEX RETURNING ACCRECKEY ELSE STOP
Reads the previous item-id from the index in ACCRECINDEX and assigns its string value to ACCRECID. Variable ACCRECKEY receives the item's sort key.
LOOP WHILE READPREV ID FROM SV SETTING ERROR DO PRINT ID REPEAT
Prints, in reverse order, all the item-ids in the index SV. Any file error code is assigned to variable ERROR. The program terminates when the list is exhausted.
SELECT statement, READNEXT statement, WHILE statement, READPREV statement (MultiValue Compatibility).