Purpose Upload a CSV file to a table control |
Solution 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 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
ProcessingOption
returnOnError="Off" 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
CreateTable
V[items]
material quantity description CopyText fromFile="&V[csvfile]" toText="temp"
CopyText
fromText="temp"
toTable="V[items]"
delimiter=";" Set V[k] 1 // index in screen table
label next_page Enter
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 |