Liquid UI - WS Reference Library

openfile()


Purpose

With openfile(), you can open a file.

Using openfile() command, you can import data from a file. This command creates a new file with the source file name. If a file with that name already exists, the command will delete the existing file.


Syntax

openfile("filename",{"options":"value"});
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 .csv, .txt, and .xls


Properties

  • filename - filename to enter data
  • delimiter - delimiters to separate data


Options

The openfile command takes the following options:

"output":".."

"output":true - 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.

"delimiter":".."

"delimiter":value - The delimiter option identifies the character used to separate between data entries in a file.


Options Detail

output

  1. 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.
  2. openfile("filenames.txt",{"output":true});                          
  3. As per the code, filenames.txt is created in the scripts folder and is ready to read or write the file.

delimiter

  1. The delimiter option identifies the character used to separate between data entries in a file.

  2. openfile("filenames.txt",{"delimiter":",","output":true});
    name1 = "Sarvani";
    name2 = "Poojitha";
    name3 = "Synactive";
    appendfile("filenames.txt",{"name1":true,"name2":true,"name3":true});
    closefile("filenames.txt");
  3. As per the code, the filenames.txt is opened and the delimiter specified here is the semicolon character.


Example

The following scenario demonstrates the openfile() command usage:

On the SAP Easy Access screen, create 3 fields with the labels:

  • Order Type
  • Sales
  • Description

Create a data file with the following data:

OR,1000,Standard Order
RE,2000,Returns
AA,3000,Promotion order

Create a script file as present in the Script Details page and save the file.

The SAP Easy Access screen appears, as shown in the following figure:

Press Enter key. The data from the file appears in the fields as shown in the following figure:


Script Details

openfile('file1.txt',{"delimiter":","});

Script Details


Tips and Tricks

  • File Handling

    This is a basic example of opening a file, appending to it, and then closing the file. In this example we use .txt file, however you can use .csv and .xls as well.

    openfile("filenames.txt",{"delimiter":";","output":true});
    appendfile("filenames.txt",{"name1":true,"name2":true,"name3":true});
    closefile("filenames.txt");

    Learn more about File Handling example.