SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP File Interface → Statements for the ABAP File Interface →Syntax
TRANSFER dobj TO dset [LENGTH len]
[NO END OF LINE].
Extras:
1. ... LENGTH len
2. ... NO END OF LINE
Effect
This statement passes the content of data object dobj to the file specified in dset. For dobj, ´data objects with elementary data types and flat structures can be specified. In Unicode programs, dobj must be character-like if the file was opened as a text file (this restriction does not apply to legacy text files).
dset expects a character-like data object containing the physical name of the file. The content is written to the file from the current file pointer. After the data has been passed, the file pointer is positioned after the inserted data. The addition LENGTH can be used to restrict the number of characters or bytes passed.
In a Unicode program, the file for writing, appending, or changing data must be open. Otherwise, a handleable exception is raised.
If the file was not yet opened in a non-Unicode programm, it is implicitly opened using the statement
OPEN DATASET dset FOR OUTPUT IN BINARY MODE.
as a binary file for writing. If the system accesses an invalid file, a handleable exception is raised.
The Influence of Access Type
The access type defined in the statement OPEN DATASET has the following effect on the data passed from:
Note
If parts of a file are to be overwritten, it must be opened to be changed in Unicode programs. In non-Unicode programs, files opened only for reading can be overwritten, but this is not recommended.
Influence of the Storage Type
The data is passed regardless of the storage type used to open the file with the statement OPEN DATASET. If the specified storage type requires conversion, it is carried out before the write process.
If the file was opened as a text file or a legacy text file, the trailing blank characters are deleted for all data objects, except for those of data type string. The line end marker defined when the file was opened is then added to the remaining content of the data object or to the result of the conversion, and the final result is written byte-by-byte to the file. The appending of the end of line separator can be prevented using NO END OF LINE.
If the file was opened as a binary file or a
legacy binary file, the content of the data object or the result of the conversion is written byte-by-byte to the file.
Notes
... LENGTH len
Effect
This addition determines how many characters or bytes of the data object dobj are written to the file. len expects a data object of the type i. It contains the number of characters or bytes. In text files, the content of len specifies the number of characters that are written from the memory. For binary files, legacy text files, and legacy binary files, len specifies the number of bytes that are written to the file. The first len characters or bytes are passed and alignment gaps are included in the structures. If the addition LENGTH is not specified, all characters or bytes are passed.
If the value of len is less than or equal to 0, no characters or bytes are passed. If the file is opened as a (legacy) text file, however, a
line end marker is inserted into the file by
default. If the value of len is greater than the number of characters or
bytes in dobj, blank characters or hexadecimal 0 are passed to the file instead
of the missing characters or bytes, depending on whether the file was opened as a (legacy) text file or a (legacy) binary file.
... NO END OF LINE
Effect
This addition has the effect that, in text files or legacy text files, no end of line separator is appended to the data passed.
Example
The binary data from the database table SPFLI is passed to a binary file flights.dat. The structure of the table rows passed contains both character-like and numerical fields. Since the type-compliant storage of mixed structures in files is not possible, the binary content of the structure is directly accessed using a typed field symbol <hex_container>. To achieve the same result, the structure wa could be passed directly. The recommended procedure however is to use the field symbol, because it explicitly passes a binary data type to a binary file. This type of storage is only recommended for short-term storage within the same system, because the byte-like content depends on the byte order and the current system code page. For long-term storage or for exchanging between systems, the data should be converted to character-like containers and stored as a text file.
DATA: file TYPE string VALUE `flights.dat`,
wa TYPE spfli.
FIELD-SYMBOLS <hex_container> TYPE x.
OPEN DATASET file FOR OUTPUT IN BINARY MODE.
SELECT *
FROM spfli
INTO wa.
ASSIGN wa TO <hex_container> CASTING.
TRANSFER <hex_container> TO file.
ENDSELECT.
CLOSE DATASET file.
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_PIPE_REOPEN
CX_SY_TOO_MANY_FILES