openfile

The openfile command is used to open files.

It is sometimes necessary to open an external file to extract data. The openfile command is used to perform this action. This command typically creates a new file with the specified name. If a file with that name already exists, the command will delete the file. The syntax is as follows:

openfile("filename" {"output":true, "delimiter":";"});
Note: If no path is specified for the file, it will be created in the SAP work directory on your local system.

Supported file types are as follows:

Options

The openfile command takes the following options:

output

The output option specifies an existing file with the same name will be deleted and replaced with a new empty file using the same name. The syntax is as follows:

{"output":true}
Note: The output option must be set to true when appending or writing to a file.
delimiter

The delimiter option identifies the character used to separate between data entries in a file. In our example below, we are specifying the delimiter as the semicolon character. The syntax is as follows:

{"delimiter":";"}

Example

  1. Create a file named filenames.txt.

  2. Open the VA01 script file (SAPMV45A.E0101.sjs) and add the following code:

    openfile("filenames.txt", {"delimiter":";", "output":true});
  3. The file is now open and ready to be written to or read from.