Use the IN FILE clause to store a TEXT or BYTE value in a named file. The name of the file is represented by a character expression that follows the IN FILE keywords, it can be:
The file is opened and closed each time you use the variable stored in an SQL or 4GL statement.
All the file names you use in your 4gl development must be platform-independent.
If you use platform-dependent names (e.g., combine upper and lower case, use colons, finish names with a full stop, etc.), please remember that they might cause different problems when you move your project to another platform.
If you retrieve the value from a database column into this variable, the corresponding section of the file is overwritten. When a row is updated with the help of this variable, the entire file is read and stored in the specified column.
A variable of large data type stored either in memory or in a named file can contain only the most recent value assigned to it.
If the file-name is omitted, but the IN FILE clause is specified, the value will be stored in a temporary file.
If the file-name is omitted after the IN FILE keywords, the value will be stored in a temporary file. This file will be created in the directory defined by the DBTEMP environment variable, when the 4GL program is run. If this variable is not set, the temporary file is located in the /tmp directory. If this temporary directory does not exist, 4GL will produce a runtime error.
DEFINE my_image BYTE
LOCATE my_image IN FILE
If the variable has been located in a temporary file, you may use the LOCATE statement to relocate it.
To place the values of BYTE or TEXT data types in a specific file, the IN FILE keywords must be followed by the file-name. It can be either literal name of the file or a variable of character data type that contains the name of the file. Optionally, it can also contain the relative path to the file and its extension. Here is the example of the literal representation of a file with its path:
DEFINE my_image BYTE
LOCATE my_image IN FILE "/source/img/my_image"
Below is an example of a variable used as the file-name:
DEFINE
my_image BYTE,
file_name VARCHAR(15)
LET file_name = "/source/img/my_image"
LOCATE my_image IN FILE file_name
Multiple file names can be specified by means of declaring an array of CHAR, VARCHAR or STRING data type:
DEFINE
file_name ARRAY[5] OF CHAR(25),
my_list ARRAY[5] OF TEXT
FOR x = 1 TO 5
LET file_name[x] = "/source/list_files/list", x
LOCATE my_list[x] IN FILE file_name[x]
END FOR