Purpose
Upload a CSV file to a table control

Solution
Since the input file may contain more rows than are visible on the screen, we need to scroll the table after filling the first page. Most SAP transactions scroll automatically when you press Enter after filling in all visible rows, and in most cases the table is scrolled so that the last row entered becomes the first row in the visible part of the table. 

For a specific transaction, first check this behavior and adjust the InputScript below if necessary.

Another issue is what you want to do in case of an error message. A simple solution is not to handle errors explicitly in your InputScript, so GuiXT stops processing and displays the error message. It is then up to the user to correct the data in the file and upload the data again. For another approach, see the following tip (Excel upload), which writes error messages back to the Excel file.

Example
In transaction VA01 we add a button that reads a CSV file and enters the read data into the VA01 item table. For the example we assume that the CSV file contains the fields material number, quantity and material description.

GuiXT Script 

Pushbutton (toolbar) "Upload items" process="va01_upload_items.txt"


InputScript
"va01_upload_items.txt"

// Upload a CSV file into the VA01 items table

// do not leave the transaction if any error occurs

ProcessingOption returnOnError="Off"

// select the input file

SelectFile name="csvfile" _

  filter="*.csv" _

  title="Choose CSV file with VA01 item data" _

  directory="E:\temp"

// done?

if not Q[ok]

  Return "S: No file selected"  -statusline

endif

// create a table variable

CreateTable V[items] material quantity description

// copy csv file

CopyText fromFile="&V[csvfile]" toText="temp"

CopyText fromText="temp" toTable="V[items]" delimiter=";"

Set V[n] 1  // index in table variable

Set V[k] 1  // index in screen table

 

label next_page

Enter


Screen
sapmv45a.4001

  Title "Uploading item &V[n]"

 

  label next_item

  if not V[n>&V[items.rowcount]]

   

    // table row on screen?

    if cell[All items,Material,&V[k]]

     

      // set item attributes

      Set  cell[All items,Material,&V[k]] "&V[items.material.&V[n]]"

      Set  cell[All items,Order Quantity,&V[k]] "&V[items.quantity.&V[n]]"

      Set  cell[All items,Item Description,&V[k]] "&V[items.description.&V[n]]"

     

      // increase index

      Set V[n] &V[n] + 1

      Set V[k] &V[k] + 1

     

     

      goto next_item

    endif 

   

    // after Enter, row 2 will be the next free table row in VA01

    Set V[k] 2 

   

    goto next_page

  endif

 

  Enter

 

Screen sapmv45a.4001

 

  // final message 

  Message "S: &V[allitems.rowcount] items uploaded" -statusline

 

  // scroll to top of table

  Enter "/ScrollToLine=1" table="T[All items]"

 

Components
InputAssistant