Opening a File for Read Access Locate the document in its SAP Library structure

To open a file for reading, use the FOR INPUT addition to the OPEN DATASET statement.

Syntax

OPEN DATASET <dsn> FOR INPUT.

The file must already exist, otherwise, the system sets SY-SUBRC to 8, and ignores the statement.

If the file exists and is already open (for read or write access, or for appending), the position is reset to the beginning of the file. However, it is good programming style to close files that are already open before you reopen them for a different operation (for further information about closing files, refer to Closing a File).

Example

DATA FNAME(60) VALUE 'myfile'.

OPEN DATASET FNAME FOR INPUT.

IF SY-SUBRC = 0.
  WRITE / 'File opened'.
  .....
ELSE.
  WRITE / 'File not found'.
ENDIF.

This example opens the file "myfile" for reading.

 

 

 

 

Leaving content frame