LOCATE (for TEXT/BYTE)

The LOCATE statement specifies where to store data of TEXT and BYTE variables.

Syntax 1: Locate in memory

LOCATE target [,...] IN MEMORY

Syntax 2: Locate in a specific file

LOCATE target [,...] IN FILE filename

Syntax 3: Locate in a temporary file

LOCATE target [,...] IN FILE
  1. target is the name of a TEXT or BYTE variable to be located.
  2. filename is a string expression defining the name of a file.

Usage

Defining the location of TEXT and BYTE large object data is mandatory before usage and must be done with the LOCATE instruction.

After defining the data storage, the variable can be used as input parameter or as a fetch buffer in SQL statements, as well as in interaction statements and reports.

You cannot use a large object variable if the data storage location is not defined.

The first syntax using the IN MEMORY clause specifies that the large object data must be located in memory. The second syntax using the IN FILE filename clause specifies that the large object data must be located in a specific file. The third syntax using the IN FILE clause specifies that the large object data must be located in a temporary file.

When using a temporary file, the location of the temporary file can be defined with the DBTEMP environment variable. By default, the runtime system will use /tmp on UNIX™ and %TMP% or %TEMP% on Windows™. The temporary files are automatically dropped by the runtime system when the program terminates. On UNIX systems, the permission on the temporary file can be controlled by umask.

The FREE instruction can be used to free the resources allocated to the large object variable.

MAIN
  DEFINE ctext1, ctext2 TEXT
  DATABASE stock 
  LOCATE ctext1 IN MEMORY
  LOCATE ctext2 IN FILE "/tmp/data1.txt"
  CREATE TABLE lobtab ( key INTEGER, col1 TEXT, col2 TEXT )
  INSERT INTO lobtab VALUES ( 123, ctext1, ctext2 )
END MAIN