File Handling Introduction
ABAP/4 provides three statements for handling files:
- The OPEN DATASET statement opens a file.
- The CLOSE DATASET statement closes a file.
- The DELETE DATASET statement deletes a file.
- To open a file for read access, use the FOR INPUT option of the OPEN DATASET statement
- To open a file for write access, use the FOR OUTPUT option of the OPEN DATASET statement
- To open a file for appending data to the file, use the FOR APPENDING option of the OPEN DATASET statement
- To process a file in binary mode, use the IN BINARY MODE option of the OPEN DATASET statement
- To process a file in text mode, use the IN TEXT MODE option of the OPEN DATASET statement
To open a file at a specific position, use the AT POSITION option of the OPEN DATASET statement. When you work with the operating systems UNIX or WINDOWS NT, you can send an operating system command with the statement OPEN DATASET. To do so, use the option FILTER. To receive the operating system message after trying to open a file, use the MESSAGE option of the OPEN DATASET statement. To close a file on the application server, use the CLOSE DATASET statement.
To delete a file on the application server, use the DELETE DATASET statement. To write data to a file on the application server, use the TRANSFER statement. To read data from a file on the application server, use the READ DATASET statement.
GUI_UPLOAD: This Function module is used to read the data from Presentation Layer.
GUI_DOWNLOAD : This Function module is used to write the data into Presentation Layer.
DATA(file) = `test.dat`.
OPEN DATASET file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED.
TRANSFER `1234567890` TO file.
CLOSE DATASET file.
OPEN DATASET file FOR UPDATE IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED
AT POSITION 2.
TRANSFER `ABCD` TO file.
CLOSE DATASET file.
...
OPEN DATASET file FOR INPUT IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED.
DATA: result TYPE string,
output TYPE TABLE OF string WITH EMPTY KEY.
WHILE sy-subrc = 0.
READ DATASET file INTO result.
APPEND result TO output.
ENDWHILE.
CLOSE DATASET file.
cl_demo_output=>display_data( output ).
DELETE DATASET file.
Comments
Post a Comment