Liquid UI - Documentation - 7.10 readfile()

7.10 readfile()


Purpose

With readfile(), you can read the content from the file. This command allows you to retrieve data from the file with the help of variables.

For instance, if you want to copy all the data present in a .csv file. Then based on the number of column values existing in each row or line, you need to add the variables in this command as options as illustrated, in the File Operations article. In this way, you can update the information from the file into SAP. The following file types are supported:

  • .csv
  • .txt
 

The readfile() returns a number based on the read status of the file.

  • 1: If the file is read successfully
  • -1: If the file cannot be read
 

Note: You need to open the file to read the data from the file.


Syntax

Format 1: Reads values from the file into variables. Here, the command will search for the file in your scripts directory.

readfile("filename.ext",{"variable":true});
 

Format 2: Reads values from the file into variables. Here, the command will search for the file in the specified folder.

readfile("C:\\LiquidUI\\MMModule\\filename.ext",{"variable":true});

Note: You can specify upto 60 variables in the command to read the record values from the file.

 


Properties

  • filename.ext - Enter the filename with its extension.


Options

The readfile command takes the following option:

"variable":"true"

"variable": true - This option copy the file data into a variable.

"variable": false - This option does not copy the file data into a variable.


Options Detail

variable

  1. This option allows you to specify the variable(s) in which data needs to save from the file.

  2. openfile('file.txt',{"delimiter":","}); 
    readfile('file.txt',{"z_first_&V[idx]":true, "z_second_&V[idx]":true, "z_third_&V[idx]":true}); 
    println("Reading file.txt file "); 
  3. As per the code, filenames.txt is read and updates the data into the variable, which is specified as an option in the command.


Example

The following scenario demonstrates the readfile() command usage:

The SAP Easy Access screen appears, as shown below:

Click Enter. The data from the file appears in the fields as shown below:

 


Script

readfile('file.txt',{"z_first_&V[idx]":true,"z_second_&V[idx]":true,"z_third_&V[idx]":true});

Script Details


Usage Details


Tips and Tricks

  • You can handle the end condition after the readfile operation using the labels in the scripts.
    if(isBlank(z_checkfld)) {
      println("<<<<<<<<>>>>>>>>>" + z_checkfld);
      goto end_create;
    }
    goto create;
    end_create:
    

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