Liquid UI - WS Reference Library

appendfile()


Purpose

With appendfile(), you can add content to existing files of the SAP screen.

This command enables users to quickly add data to a SAP screen or record using an external source.

Note: To append data to the file, you need to open and close the file.


Syntax

appendfile("filename",{"var1":true,"var2":true,"var3":true,"var4":true});

Note: When appending or writing to a file, the 'output' flag must be set to 'true' to open the file.

Each variable to be added is declared and then is marked true or false in the code as shown above. Those variables marked as being 'true' will be appended to the file. If a variable is marked false, it will not get appended. The supported file types are as follows:

  • .csv
  • .txt
  • .xls


Properties

  • Source - filename
  • Variable - data to append to a file


Option

"user-selected variable":".." 

"user-selected variable":true - This option is used to enter the variable name of the values to be appended in the file. By listing the variables, the user specifies the data to be appended. Please see the examples below for demonstrations on some of the possible usages.


Option Detail

user-selected variable

  1. This option enables the user to enter the variable names of the values appended in the file .

  2. inputfield([5,5],"User Name",[5,22],{"name":"z_appenddata","size":20});
    pushbutton([7,15],"Append",{"process":append});
    function append()
    {
    openfile("usernames.txt",{"delimiter":";","append":true}); 
    name1 = z_appenddata;
    appendfile("usernames.txt",{"name1":true}); 
    closefile("usernames.txt"); 
    }
    
  3. As per the code, usernames.txt file is created and appendfile command appends the values of name1 to the file.


Example

Appending records to a file

In the following example, we will append records to a file that we created using the file() command. Open the relevant script file and add the following lines of code:

openfile("VA01file.txt",{"append":true,"delimiter":";"});
set("V[gz_ordertype]",'&F[Order Type]');
set("V[gz_salesorg]",'&F[Sales Organization]');
set("V[gz_distchan]",'&F[Distribution Channel]');
set("V[gz_division]",'&F[Division]');
set("V[gz_salesoff]",'&F[Sales Office]');
set("V[gz_salesgroup]",'&F[Sales Group]');
appendfile("VA01file.txt",{"V[gz_ordertype]":true,"V[gz_salesorg]":true,"V[gz_distchan]":true,"V[gz_division]":true,"V[gz_salesoff]":true,"V[gz_salesgroup]":true});
closefile("VA01file.txt");

The records for Sales Organisation, Distribution Channel, Division, Sales Office, and Sales Group adds to the file 'VA01file.txt'.


Tips and Tricks

  • Increment counter using appendfile()

    To use appendfile command and increment counter in a file.

    appendToCounterFile(strFileName);

    Learn more about appendfile in practical.