OPEN


Basic form 1

OPEN DATASET dsn.

Additions




1. ... FOR OUTPUT
2. ... FOR INPUT
3. ... FOR APPENDING
4. ... IN BINARY MODE
5. ... IN TEXT MODE
6. ... AT POSITION pos
7. ... TYPE attr
8. ... MESSAGE msg
9. ... FILTER filter

Effect

Opens the specified file.

If no addition is specified, the file is opened for reading and in binary mode (see below).

The return code value is set as follows:


SY-SUBRC = 0 The file was opened.
SY-SUBRC = 8 The file could not be opened.

Example

DATA: DSN(20) VALUE '/usr/test', RECORD(80). OPEN DATASET DSN. DO. READ DATASET DSN INTO RECORD. IF SY-SUBRC NE 0. EXIT. ELSE. WRITE: / RECORD. ENDIF. ENDDO. CLOSE DATASET DSN.

Notes

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.

Notes

For the UNIX operating system

Addition 1

... FOR OUTPUT

Effect

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 generated.

Addition 2

... FOR INPUT

Effect

Opens an existing file for writing. If the file is already open, the positioning is set back only to the start of the file. The addition FOR INPUT does not have to be specified explicitly.

Addition 3

... FOR APPENDING

Effect

Opens the file for writing to the end of the file. If the file does not exist, it is generated. If the file is already open, positioning is only set back to the end.

Note

The additions 1 to 3 are mutually exclusive.

Addition 4

... IN BINARY MODE

Effect

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 explicitly.

Addition 5

... IN TEXT MODE

Effect

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.

Note

The additions 4 and 5 are mutually exclusive.

Addition 6

... AT POSITION pos

Effect

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.

Addition 7

... TYPE attr

Effect

In the field attr , 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.

Example

Generate a 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' FOR OUTPUT.

Example

Generate an OpenVMS file 'TEST.LOG' with the specified attributes. The individual parameters must be separated by blanks:
OPEN DATASET 'TEST.LOG' TYPE 'alq=100 deq=100 fop=cif,ctg' FOR OUTPUT.

Addition 8

... MESSAGE msg

Effect

Stores the relevant operating system message in the field msg if an error occurs when opening the file.

Example

DATA: DSN(20) VALUE '/usr/test', MSG(100). OPEN DATASET DSN FOR INPUT MESSAGE MSG. IF SY-SUBRC <> 0. WRITE: / MSG. STOP. ENDIF.

Addition 9

... FILTER filter

Effect

Under UNIX and Windows NT, you can specify an operating system command in the field filter .

Example

Under UNIX
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.

Index
© SAP AG 1996