Get Example source ABAP code based on a different SAP table
• WITH LINEFEED OPEN DATASET
OPEN DATASET>, WITH LINEFEED> Short Reference >
ABAP_SYNTAX ... WITH ${ NATIVE $| SMART $| UNIX $| WINDOWS $} LINEFEED ...>
ABAP_ALTERNATIVES: 1 ... WITH NATIVE LINEFEED> 2 ... WITH SMART LINEFEED> 3 ... WITH UNIX LINEFEED> 4 ... WITH WINDOWS LINEFEED>
What does it do? These additions determine which end-of-line marker is used for text files> or legacy> text files. If these additions are used, the profile parameter> abap/NTfmode>> is ignored. The two values UNIX> or NT> cannot both be specified in the addition TYPE>> at the same time. If neither of these additions is used, the end-of-line marker is determined as follows, depending on the operating system of the current ABAP_ASINSTANCE > host computer>:
The end-of-line marker for Unix is LF>. On Unix, OS/390, and IBM i5/OS (previously known as OS/400), only LF> is used for reading and writing.
The end-of-line marker for MS> Windows is CRLF>. On MS > Windows, however, the values of the profile parameter> abap/NTfmode>> can also be used to specify whether new files are to be handled according to Unix conventions or Windows conventions. If the profile parameter has the value b>, the Unix end-of-line marker LF> is used. If the profile parameter has the value t> or is initial, the Windows end-of-line marker CRLF > is used. The setting in the profile parameter can be overridden with the addition TYPE>> and the value UNIX> or NT>. If an existing file is opened without the addition TYPE>, this file is searched for the first end-of-line marker (LF> or CRLF>), and this is used for the entire file. If no end-of-line marker is found, the profile parameter is used. This applies particularly if an existing file is completely overwritten with FOR OUTPUT >>. If an addition WITH NATIVE$|SMART$|UNIX$|WINDOWS LINEFEED> is used, this setting can be changed for the open file using the statement SET DATASET>>. If neither of the additions is used, the end-of-line marker cannot be changed using SET DATASET > either.
Latest notes:
Without the use of an addition WITH LINEFEED>, the end-of-line marker is dependent on various implicit factors such as the operating system of the current ABAP_ASINSTANCE host computer>, a profile parameter, and line end markings that are already used. For this reason, the explicit use of WITH LINEFEED> is recommended, which makes the use of the addition TYPE>> for setting the end-of-line marker obsolete.
The end-of-line marker that is currently used can be determined for every open file using GET DATASET>>. ABAP_HINT_END • WITH NATIVE LINEFEED OPEN DATASET
ABAP Alternative 1 ... WITH NATIVE LINEFEED>
What does it do? This addition defines the end-of-line marker independently of the access type> in accordance with the operating system of the current ABAP_ASINSTANCE host computer>, in other words LF > for Unix, OS/390, and IBM i5/OS (previously known as OS/400), and CRLF> for MS Windows. The end-of-line marker is interpreted in accordance with the current code page. If a code page is specified explicitly using the addition CODE PAGE>>, the control characters> of the end-of-line marker must be available or be written according to this code page.
Latest notes: The addition WITH NATIVE LINEFEED> is intended for processing files on a host computer that can also be accessed by other means. The addition receives the appropriate end-of-line marker without the program needing to know the operating system. ABAP_HINT_END
Example ABAP Coding
The following example shows the UTF 8 representation of the current line end marking. Comparisons with the corresponding control characters> in string templates > ensure that it is either LF> or CRLF>. ABEXA 00471 ABAP_EXAMPLE_END • WITH SMART LINEFEED OPEN DATASET
ABAP Alternative 2 ... WITH SMART LINEFEED>
What does it do? This addition depends on the access type >:
In files that are opened for reading using FOR INPUT>, both LF > and CRLF> are interpreted as an end-of-line marker. When opening an EBCDIC file with the addition CODE PAGE>>, the corresponding ASCII control characters> are recognized alongside the LF>, CRLF>, and EBCDIC control characters. In addition, the EBCDIC control characters NL> (line separator) is also interpreted as an end-of-line marker.
In files opened for appending or changing with FOR APPENDING> or FOR UPDATE>, the program searches for an end-of-line marker that is already used in the file. The end of the file is identified first. If no end-of-line marker is found here, a certain number of characters at the beginning is analyzed. If an end-of-line marker is found, this is used when writing to the file. This is also affected by the addition CODE PAGE>>. For example, ASCII end-of-line markers are recognized and used in a file opened with EBCDIC, but not the other way round. If no end-of-line marker is found or no search is possible, for example, if the file is opened with the addition FILTER> >, the end-of-line marker is defined in accordance with the operating system of the current ABAP_ASINSTANCE host computer>, as with the addition WITH NATIVE LINEFEED>.
In files opened for writing using FOR OUTPUT>, the end-of-line marker is determined in accordance with the operating system the current ABAP_ASINSTANCE host computer>, as with the addition WITH NATIVE LINEFEED>.
Latest notes: The addition WITH SMART LINEFEED> is intended for the generic processing of files in heterogeneous environments. The end-of-line marker is recognized and set for different formats. Using this addition is the best solution for most use cases. ABAP_HINT_END
Example ABAP Coding
Writing of a text file with the end-of-line marker CRLF>. Using the addition WITH SMART LINEFEED> when opening to read, this marking is also detected on platforms that expect LF>. ABEXA 00472 ABAP_EXAMPLE_END • WITH UNIX LINEFEED OPEN DATASET
ABAP Alternative 3 ... WITH UNIX LINEFEED>
What does it do? The end-of-line marker is set to LF> regardless of the access type> and operating system of the host computer> of the current ABAP_ASINSTANCE . The end-of-line marker is interpreted in accordance with the current code page. If a code page is specified explicitly using the addition CODE PAGE>>, the control characters> for the end-of-line marker must exist or be written according to this code page.
Latest notes: The addition WITH UNIX LINEFEED> is intended for processing Unix files in which the specific end-of-line markers are to be retained, even if the operating system of the current ABAP_ASINSTANCE host computer> is MS> Windows. ABAP_HINT_END
Example ABAP Coding
The following example sets the end-of-line marker to LF>. This marking is detected after it is read to a binary file and compared with the corresponding control character in a string template>. ABEXA 00473 ABAP_EXAMPLE_END • WITH WINDOWS LINEFEED OPEN DATASET
ABAP Alternative 4 ... WITH WINDOWS LINEFEED>
What does it do? The end-of-line marker is set to CRLF> regardless of the access type> and operating system of the current ABAP_ASINSTANCE host computer >. The end-of-line marker is interpreted in accordance with the current code page. If a code page is specified explicitly using the addition CODE PAGE>>, the control characters> for the end-of-line marker must exist or be written according to this code page.
Latest notes: The addition WITH WINDOWS LINEFEED> is intended for use with MS> Windows files in which the specific end-of-line marker is to be retained, even if the operating system of the current ABAP_ASINSTANCE host computer> is Unix, OS/390, or IBM i5/OS (previously known as OS/400). ABAP_HINT_END
Example ABAP Coding
The following example sets the line end marking to CRLF>. This marking is detected after it is read to a binary file and compared with the corresponding control character in a string template>. ABEXA 00474 ABAP_EXAMPLE_END