Liquid UI - Documentation - 7.09 openfile()

7.09 openfile()


Purpose

With openfile(), you can open a file to either read or write the data into it. The output option in the command will create a new file with the specified file name in your scripts folder. If a file with that name already exists in the folder, then the command will replace it with the new one.

The openfile() returns a boolean value based on the open status of the file.

  • True: If the file opened successfully
  • False: If the file is not opened


Syntax

Format 1: Opens a file existing in your SAP work directory.

openfile("filename",{"options":"value"});

Note: If a file path is not specified, the file will be created in the SAP work directory on your local system. Supported file types are .csv, .txt, and .xls.

 

Format 2: Opens a file existing in the specified location on your system.

// You need to place double backward slashes between the folder names in the file path.
openfile("C:\\LiquidUI\\MMModule\\filename.ext",{"options":"value"});

Note: You need to specify the file path in the command if the file does not exist in your scripts folder.

 


Properties

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


Options

The openfile command takes the following options:

"append":".."

"append": true - If true, the append option allows you to append or write to a file.

"append": false - If false, you cannot append or write to a file.

"delimiter":".."

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

"output":".."

"output": true - The output option will create a file with the specified file name. If the file already exists, it will be deleted and replaced with a new empty file.


Options Detail

append

  1. The append option allows you to append or write to a file.
  2. openfile("filenames.txt",{"append":true});                          
  3. As per the code, filenames.txt is opened and is ready to read or write the file.

output

  1. The output option will create a file with the specified file name. If the file already exists, it will be deleted and replaced with a new empty file.
  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 data entries in a file.

  2. openfile("ordertypes.txt",{"delimiter":",","output":true,"append":true});
    name1 = "Standard Order";
    name2 = "Promotion Order";
    name3 = "Returns";
    appendfile("ordertypes.txt",{"name1":true,"name2":true,"name3":true});
    closefile("ordertypes.txt");
  3. As per the code, the ordertypes.txt is opened, and the delimiter specified here is the comma character, which is appended while adding variable data.
     


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 file with the following data:

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

Create a script file using the script provided on the Script Details page and save the file.

The SAP Easy Access screen appears, as shown below:

Press Enter key. The data from the file appears in the fields, as shown below:


Script Details

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

Script Details


Tips and Tricks


Can't find the answers you're looking for?