Purpose With AppendFile you can append a new record to a file, e.g. in order to fill a table with SAP data for later use in Excel.

It is also possible to specify a second file. This file is copied to the first one, and all GuiXT variables in each line are replaced with their current values.

Examples

Further examples
AppendFile "X:\GuiXTFiles\MatDes.txt" s_matnr s_text s_unit s_price

The value of the variables &[s_matnr] &[s_text] &[s_unit] &[s_price] is concatenated to a single record. The values are separated by the delimiter specified in the OpenFile command (delimiter=, default delimiter is the tab).

Looking at the example, assume that &[s_matnr]= 10000120 &[s_text]= Screw &[s_unit]= ST &[s_price]= 0.02 and that the delimiter is ';'. The new file record is

1000001;20;Screw;ST;0.02

Format AppendFile "filename" var1 var2 var3 ...

Up to 60 variables are possible.

AppendFile "filename" template="templatefile"

The template file is copied and all GuiXT variables &[...] are replaced with their current values.

With if Q[ok], you can check whether the appending was successful.

Open and Close It is recommended that you explicitly open the file with OpenFile before calling  AppendFile for the first time and close it again with CloseFile after the last AppendFile.

If OpenFile or CloseFile is not explicitly used, the following automatic functions apply:

  • The first  AppendFile automatically opens the file in append mode. Existing content is retained.
  • The file is automatically closed each time the SAP GUI screen changes.
  • Calling ReadFile also closes the file and writes the content that has been buffered up to that point. Therefore, it is not recommended to use ReadFile and  AppendFile in the same OpenFile-CloseFile block and for the same file.
Tips & Tricks
Components GuiXT + InputAssistant