Locate mode assigns to a pointer variable the location of the buffer. A based variable described the record. The same data can be interpreted in different ways by using different based variables. Locate mode can also be used to read self-defining records, in which information in one part of the record is used to indicate the structure of the rest of the record. For example, this information could be an array bound or a code identifying which based structure should be used for the attributes of the data.
A READ statement with a SET option sets the pointer variable in the SET option to a buffer containing the record. The data in the record can then be referenced by a based variable qualified with the pointer variable.
The pointer value is valid only until the execution of the next READ or CLOSE statement that refers to the same file.
The pointer variable specified in the SET option or, if SET was omitted, the pointer variable specified in the declaration of the based variable, is used. The pointer value is valid only until the execution of the next LOCATE, WRITE, or CLOSE statement that refers to the same file. It also initializes components of the based variable that have been specified in REFER options.
The LOCATE statement sets a pointer variable to a large enough area where the next record can be built.
After execution of the LOCATE statement, values can be assigned directly into the based variables qualified by the pointer variable set by the LOCATE statement.
The following example shows locate mode input:
dcl 1 Data based(P), 2
·
·
·
; on endfile(In) ; read file(In) set(P); do while (¬endfile(In));
·
·
·
/* process record */ read file(In) set(P); end;
The following example shows locate mode output:
dcl 1 Data based(P); 2
·
·
·
; do while (More_records_to_write); locate Data file(Out);
·
·
·
/* build record */ end;