Data Interface

Concept

Persistent data can be saved in files, as well as in database tables. For files on the application server, the statements OPEN DATASET, TRANSFER, READ DATASET, SET|GET DATASET, CLOSE DATASET, and DELETE DATASET are provided in the ABAP file interface. Access to files on the presentation server is wrapped in the class cl_gui_frontend_services.

Example

Opens a file and reads it line by line to an internal table. A query sent to the system structure component sy-subrc makes sure that the preceding command was executed successfully, meaning in this case that a file with the specified name was found.

               CONSTANTS filename TYPE string VALUE 'file.txt'.

DATA: text_line TYPE string,
      text_table TYPE TABLE OF string.

OPEN DATASET filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc = 0.
  DO.
    READ DATASET filename INTO text_line.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    INSERT text_line INTO TABLE text_table.
  ENDDO.
  CLOSE DATASET filename.
ENDIF.