Get Example source ABAP code based on a different SAP table
ID SET-DATASET • SET DATASET ABAP Statement
SET DATASET> Short Reference >
ABAP_SYNTAX SET DATASET dset $[POSITION ${pos$|${END OF FILE$}$}$]> $[ATTRIBUTES attr$].>
ABAP Addition 1 ... POSITION ${pos$|${END OF FILE$}$}> 2 ... ATTRIBUTES attr>
What does it do? This statement uses the addition POSITION> to determine the position of the file pointer in the file specified in dset>. It uses the addition ATTRIBUTES> to set additional attributes for the file. At least one of these two additions must be specified. dset> expects a character-like data object containing the physical name> of the file. The file must be open, otherwise a catchable exception is raised. ABAP_SUBRC_GENERAL The statement SET DATASET> always sets sy-subrc> to the value 0 or raises an exception. • POSITION SET DATASET • END OF FILE SET DATASET
ABAP Addition
What does it do? This addition sets the file pointer in the file, either in the position specified in pos>, or at the end of the file. pos> expects a numeric data object. The position is specified in bytes, where the start of the file corresponds to position 0. If the value of pos> is -1, the file pointer is set at the end of the file. Other negative values are not allowed. The following cases must be distinguished: If the file is open for reads and the value of pos> is greater than the length of the file, the file pointer is positioned outside the file. Unless the position is changed, no data can be read. If the file is opened for writes and the value of pos> is greater than the length of the file, it is filled with hexadecimal 0s from the end of the file to the specified position the next time a write is performed on it. If the file is opened for appending, the position specified is ignored and the file pointer remains positioned at the end of the file. If the file is opened for changes, and the value of pos> is greater than the length of the file, it is filled with hexadecimal 0 from the end of the file to the specified position the next time a write is performed on it. The addition POSITION> cannot be specified for files that have been opened with the addition FILTER>> of the statement OPEN DATASET>. This raises a catchable exception.
Latest notes:
For file sizes greater than 2 GB, a data object pos> of data type i> is not sufficient for specifying all possible positions of the file pointer.
Free position specifications are more suitable for binary files than for text files. In text files, positions depend on the character representation, end-of-line markers, and in UTF-8 files, also on a Byte Order Mark (BOM). In text files, the file pointer should only be placed in positions known exactly, for example positions obtained using GET DATASET>>. ABAP_HINT_END
Example ABAP Coding
When writing, the file is read from the start of the file until the first end-of-line marker, and then the new content is written starting from the end of the file. If the file pointer is not set explicitly after a read, the last TRANSFER>> statements would overwrite the file after the first end-of-line marker. ABEXA 00649 ABAP_EXAMPLE_END • ATTRIBUTES SET DATASET
ABAP Addition
What does it do? This addition can be used to change some of the attributes that were determined when the file was opened with the statement OPEN DATASET>>. attr> expects a data object of type dset_changeable_attributes> from the type pool> DSET>> (see the table below). The structure dset_changeable_attributes> corresponds to the substructure changeable> of the structure dset_attributes> . Data objects of the structure dset_attributes> can be filled using the statement GET DATASET>>. Component>Meaning> indicator>Structure with the components repl_char>, conv_errors>, code_page>, endian>, and linefeed_mode>. If these components contain the value X> in attr>, the values are used in the components with the same names in the structure dset_changeable_attributes> when changes are made. repl_char>In this component of attr>, a single-character character-like replacement character can be specified to overwrite the replacement character specified when the file was opened using the addition REPLACEMENT CHARACTER >> of the statement OPEN DATASET>. conv_errors>In this component of attr>, the value I> or R> can be specified to overwrite the setting made when the file was opened using the addition IGNORING CONVERSION ERRORS> >. The value I> suppresses the exceptions, R> raises the exceptions. code_page>In this component of attr>, a code page> from the column CPCODEPAGE> of the database table TCP00>> can be specified to overwrite the code page specified when the file was opened using the addition CODE PAGE> > of the statement OPEN DATASET>. endian>In this component of attr>, the value B> or L> can be specified to overwrite the setting made when the file was opened using the additions ${BIG$|LITTLE$} ENDIAN>> of the statement OPEN DATASET> . The value B> sets the byte order to Big Endian; the value L> sets it to Little Endian. linefeed_mode>In this component of attr>, one of the values N>, S>, U> or W> can be entered to overwrite the setting made using the addition WITH NATIVE$|SMART$|UNIX$|WINDOWS LINEFEED>> of the statement OPEN DATASET> as appropriate. For some components, the possible input values are defined as constants in the type pool DSET>>. The values specified in attr> must comply with the syntax rules for the associated additions of the statement OPEN DATASET>, otherwise a catchable exception is raised:
The components repl_char> and conv_errors> can only be used when making changes if the file is open as a text file>, legacy> text file, or legacy> binary file, but not if it is opened as a binary file>
The components code_page> and endian> can only be used when making changes if the file is open as a legacy text file or a legacy binary file.
The component linefeed_mode> can only be used when making changes if the file is open as a text file> or a legacy> text file and if the end-of-line marker has been set explicitly using the addition WITH LINEFEED>>.
Latest notes: The modifiable attributes do not affect the attributes of the file in the operating system, but rather the attributes with which the file is opened in ABAP and according to which it is handled in ABAP. ABAP_HINT_END
Example ABAP Coding
Depending on the non-modifiable attributes of the file test.dat>, some of its modifiable attributes are reset. ABEXA 00650 ABAP_EXAMPLE_END
The specified code page is not available for the current ABAP_ASINSTANCE .
Runtime error:
CONVT_CODEPAGE_INIT> CX_SY_CONVERSION_CODEPAGE>>
Reason for error:
The escape character cannot be represented in the target code page. Escape characters and handling of conversion errors can only be changed in TEXT MODE> or in LEGACY ... MODE>.
Runtime error:
CONVT_CODEPAGE> CX_SY_FILE_OPEN_MODE>>
ABAP_TEXTID READ_ONLY>
Reason for error:
File is only open for reads.
Runtime error:
DATASET_READ_ONLY>
ABAP_TEXTID NOT_OPEN>
Reason for error:
File is not open.
Runtime error:
DATASET_NOT_OPEN>
ABAP_TEXTID INCOMPATIBLE_MODE>
Reason for error:
File opened in incompatible mode.
Runtime error:
DATASET_INCOMPATIBLE_MODE> CX_SY_FILE_POSITION>>
ABAP_TEXTID SEEK_ERROR>
Reason for error:
Error when positioning in file.
Runtime error:
DATASET_SEEK_ERROR>
ABAP_TEXTID TELL_ERROR>
Reason for error:
No access to current read/write position in the file.
Runtime error:
DATASET_NO_POSITION>
ABAP_TEXTID OFFSET_TOO_LARGE>
Reason for error:
The specified offset for the file exceeds the defined system limit for the platform. Runtime error: DATASET_OFFSET_TOO_LARGE>
Non-catchable Exceptions
Reason for error:
An attempt was made to change the position in the case of a pipe>. Pipes cannot, however, be positioned.