TRANSFER - Writing to a File

Basic form

TRANSFER f TO dsn.

Addition:

... LENGTH len

In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs.

For more details, refer to The File Interface.

Effect

Transfers the data object f to a sequential file whose path and name are specified in dsn. dsn can be a field or a literal. You must already have opened the file using OPEN DATASET. f can be a field, a string, or a structure. If f is a deep structure or a reference, a syntax error occurs. Because of this, you must always transfer internal tables line by line, for example, using a LOOP construction.

In the OPEN DATASET statement, the data object f is interpreted in lines if you use IN TEXT MODE. If you use the IN BINARY MODE addition, the line breaks are ignored. If the specified file is not already open, TRANSFER attempts to open the file FOR OUTPUT IN BINARY MODE. If this is not possible, a runtime error occurs.


If the file is opened in TEXT MODE and if the character representation is UTF-8, you can only use character-type fields (C,N, D, T), strings, and purely character-type structures. The system does not check the component types, however, until runtime.

Example

DATA rec(80).
TRANSFER rec TO '/usr/test.dat'.

This example transfers the field rec to the file test.dat in the usr directory on the application server. The data record is 80 bytes long. If you do not specify a directory, the file is written in the directory specified in the profile parameter DIR_HOME.



Notes

Exceptions

Catchable Exceptions

CX_SY_CODEPAGE_CONVERTER_INIT

CX_SY_CONVERSION_CODEPAGE

CX_SY_FILE_AUTHORITY

CX_SY_FILE_IO

CX_SY_FILE_OPEN

CX_SY_FILE_OPEN_MODE

CX_SY_TOO_MANY_FILES

A CONVT_CODEPAGE can occur in either of the following two situations:

Addition

... LENGTH len

Effect

The length of the data object to be written is defined by len, where len can be either a constant or a variable. The length is specified in bytes if the file is opened in BINARY MODE or LEGACY MODE. Note that alignment bytes are included in the length, if the data object is a structure. If the file is opened in TEXT MODE, the length refers to the number of characters that are to be written.

If len is shorter than the data object f, the system truncates f on the right.

With type I or F fields, unexpected results may occur if len is shorter than the default length for the field type.



Related

OPEN DATASET, READ DATASET, CLOSE DATASET, GET DATASET, SET DATASET

Additional help

Writing Data to Files