appendfile

The appendfile command is used to add content to existing files.

In order to add a new record to an existing file in WS, users can utilize appendfile. This command enables users to quickly add data to a SAP screen or record using an external source. The syntax is as follows:

appendfile("filename", {"var1":true, "var2":true, "var3":true, "var4":true});
Remember: When appending or writing to a file, the 'output' flag must be set to 'true' when opening a 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 in question. If a variable is marked false, it will not be appended to the record in question. The supported file types are as follows:

Options

The appendfile command takes the following options:

user-selected variable:
This is chosen by the user depending on how the information in the file is categorized. By listing the variables, the user specifies what data will be appended. Please see the examples below for demonstrations on some of the possible usages.

Appending records to an existing 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("filenames.txt", {"delimiter":";", "output":true});
name1 = "John";
name2 = "Nancy";
name3 = "Alexander";
appendfile("filenames.txt", {"name1":true, "name2":true, "name3":true});
closefile("filenames.txt");

We have now added the records for John, Nancy and Alexander to the file 'filenames.txt'.