1. ... FOR OUTPUT
2. ... FOR INPUT
3. ... FOR APPENDING
4. ... IN BINARY MODE
5. ... IN TEXT MODE
... AT POSITION pos
7. ... TYPE ctrl
8. ... MESSAGE mess
9. ... FILTER f
Opens the specified file. If no addition is specified, the file is opened for reading and in binary mode (see below).
DATA: DSN(20) VALUE '/usr/test',
OPEN DATASET DSN.
READ DATASET DSN INTO RECORD.
IF SY-SUBRC NE 0.
WRITE: / RECORD.
CLOSE DATASET DSN.
The file must be accessible from the application server. You cannot use OPEN DATASET to process files on the current
presentation server (whether PC or workstation). The function modules WS_DOWNLOAD and WS_UPLOAD
exist for this purpose.
- The format of file names depends largely on the operating system. You
can access portable programs by using the function module FILE_GET_NAME which returns the physical file name for a given
logical file name.
- The system automatically performs an authorization check. If the user
does not have the appropriate authorization, a runtime error occurs.
You can check the existence of the authorization with the function module
The following catchable runtime errors may occur with this statement:
- DATASET_NO_PIPE: OPEN DATASET with the FILTER addition is not supported on the current operating system.
- DATASET_TOO_MANY_FILES: Maximum number of open files has been exceeded.
- OPEN_DATASET_NO_AUTHORITY: No authorization to access this file.
- OPEN_PIPE_NO_AUTHORITY: No authorization to access this file (using OPEN DATASET ... FILTER ....
- You should specify the path name of any file you wish to open in its
absolute form ('/usr/test'), not in its relative form ('test').
Otherwise, the file may be opened in the directory where the SAP System is already running.
- When you create a file, it exists under the user name used to start
the SAP System. This user name is not normally identical with the user's UNIX name. To be able to create the file, the user must
have the appropriate write authorization in the relevant directory.
Opens the file for writing. If the file already exists,
its contents are deleted unless it is already open. If it is open, the
positioning is set back to the start of the file. If the file does not exist, it is created.
Opens an existing file for writing. If the file is already open, the positioning is set back to the start of the file. The
addition FOR INPUT does not have to be specified explicitly.
Opens the file for writing to the end of the file. If the file does not exist, it is created. If the file is already open,
the positioning is set to the end.
The contents of the file are not interpreted by the read and write operations READ DATASET and TRANSFER. The data
areas specified with these key words are directly input or output. The addition IN BINARY MODE does not have to be specified
If a file is opened with this addition, the system assumes that the file has a line structure. Each time READ DATASET or
TRANSFER occurs, exactly one line is input or output. If the data area is too big for the line read, the remaining
area is padded with blanks. If it is too small, the remainder of the line is lost.
This addition allows you to specify an explicit file position pos in bytes from the start of the file. The next read
or write operation then occurs there. You cannot specify a position before the start of the file.
Although this addition can also be used with the addition IN TEXT MODE
, it makes little sense, because the physical format of a text file depends largely on the operating system.
In the field ctrl, you can specify further file attributes. The contents of this field are passed unchanged to the
operating system. No checks are performed. See the documentation of the fopen command for the relevant operating system.
create an MVS file "'QXX.YYY'" with the
specified attributes. (The apostrophes ['] are part of the file name.):
OPEN DATASET '''QXX.YYY'''
TYPE 'lrecl=80, blksize=8000, recfm=F'
Create an OpenVMS file 'TEST.LOG' with the specified attributes. The individual parameters must be separated
OPEN DATASET 'TEST.LOG'
TYPE 'alq=100 deq=100 fop=cif,ctg'
Stores the relevant operating system message in the field mess if an error occurs when opening the file.
DATA: DSN(20) VALUE '/usr/test',
OPEN DATASET DSN FOR INPUT MESSAGE MSG.
IF SY-SUBRC <> 0.
WRITE: / MSG.
Under UNIX and Windows NT, you can specify an operating system command in the field f.
DATA DSN(20) VALUE '/usr/test.Z'.
OPEN DATASET DSN FOR OUTPUT FILTER 'compress'.
opens the file DSN and writes the output data to this file via the UNIX command 'compress'.
OPEN DATASET DSN FOR INPUT FILTER 'uncompress'.
reads the file in again.