Positions the read pointer of an index.
POSITION indexSelectVar [= location || END] {SETTING setting-var} [THEN statement(s) | ELSE statement(s)]
indexSelectVar is the name of a variable that identifies an index. A reference to an index must be obtained using the SELECT statement.
location is a key value (of the form by which the index is sorted) to compare against the index's sort criteria to position the read pointer in the index.
END sets the pointer to the end of the index.
setting-var is the name of a variable to which the error code or zero is assigned when the ELSE clause is taken. The file I/O error codes are described in File I/O and IPC Error Codes.
statement(s) is either a THEN or an ELSE clause (or both). A statement must be included. The THEN clause is executed if the index is referenced successfully, otherwise the ELSE clause is executed.
This statement positions the pointer to the first index entry with key equal to location or, if there is no match, with key greater than location, on a left-to-right matching basis. The END form sets the pointer to the end of the index.
See also the topic Using Indexes.
This statement will not work with any kind of list other than an index reference. Specifically, it will not work with a list returned by SELECT-INDEX or ISELECT, since those commands do not generate index references.
POSITION ACCPAYINDEX = MONTHCURR ELSE PRINT "NON-EXISTENT INDEX"; STOP
sets the read pointer of the index specified in variable ACCPAYINDEX to the first entry that is equal to or greater than the value in MONTHCURR.
POSITION ACCPAYINDEX END ELSE PRINT "NON-EXISTENT INDEX"; STOP
sets the pointer to the end of the index specified in variable ACCPAYINDEX.
EQU AM TO CHAR(254) * EQU FNAME TO "SQLEMP" EQU INAME TO "EMP.X2" * OPEN FNAME TO EMP ELSE STOP 201,FNAME SELECT EMP,INAME TO XV * * Position to first SMITH in department 90020 * DEPT = "90020" NAME = "SMITH" KEYVAL = DEPT:AM:NAME POSITION XV=KEYVAL ELSE STOP * * Print item-ids of all employees called SMITH in department 90020 * LOOP READNEXT ID FROM XV RETURNING KEYVAL ELSE KEYVAL="" DEPT = KEYVAL<1> NAME = KEYVAL<2> WHILE DEPT="90020" AND NAME="SMITH" PRINT ID REPEAT * END
In the above example, the index EMP.X2 has been created on
file SQLEMP with a definition such as: DEFINE-INDEX
SQLEMP EMP.X2 BY DEPTNO BY ENAME
, so that it is sorted first by
Department and secondly by Employee Name. The example, prints the item-ids of
all employees with the name SMITH in department number 90020. See also the READNEXT
statement.