// add a button that downloads the order items to Excel
PushButton P[BT_ITEM]+(0,69) "@J2@" _
size=(1,2) process="table_to_file.txt"
Using tabname = "SAPMV45A_TCTRL_U_ERF_AUFTRA"
Using fid1 = "Material"
Using fid2 = "Order quantity"
Using fid3 = "UN"
Using fid4 = "Item Description"
Using fid5 = "Net value"
table_to_file.txt
GuiXT
// General script for table viewing / download
//
// Example how to use it:
//
// Pushbutton (toolbar) "Download table" _
// process="table_to_file.txt"
// using tabname = "SAPMV45A_TCTRL_U_ERF_AUFTRA"
// using fid1 = "Material"
// using fid2 = "Order quantity"
// using fid3 = "UN"
// using fid4 = "Description"
// using fid5 = "Net value"
Parameter filename "&%[TEMP]\guixttemp.&V[today_ymdhms].csv"
Parameter tabname Table
Parameter fid1 1
Parameter fid2 2
Parameter fid3 3
Parameter fid4 4
Parameter fid5 5
OpenFile "&U[filename]" -output -utf8 delimiter=";"
// Variables
Set V[absrow] 1 // Absolute row number
Set V[relrow] 1 // Relative row number
Screen *
GetTableAttribute T[&U[tabname]] _
firstVisibleRow=FVisRow _
lastVisibleRow=LVisRow _
lastRow=LastRow
// First row on screen?
if V[FVisRow=1]
goto new_row
endif
// scroll to first line
Enter "/scrollToLine=1" table="T[&U[tabname]]"
label new_screen
Screen *
GetTableAttribute T[&U[tabname]] _
firstVisibleRow=FVisRow _
lastVisibleRow=LVisRow _
lastRow=LastRow
Set V[relrow] 1
label new_row
// end of table?
if V[absrow>&V[LastRow]]
goto end_of_table
endif
// end of screen?
if V[absrow>&V[LVisRow]]
Enter "/scrollToLine=&V[absrow]" table="T[&U[tabname]]"
goto new_screen
endif
Set V[C1] "&cell[&U[tabname],&U[fid1],&V[relrow]]"
Set V[C2] "&cell[&U[tabname],&U[fid2],&V[relrow]]"
Set V[C3] "&cell[&U[tabname],&U[fid3],&V[relrow]]"
Set V[C4] "&cell[&U[tabname],&U[fid4],&V[relrow]]"
Set V[C5] "&cell[&U[tabname],&U[fid5],&V[relrow]]"
AppendFile "&U[filename]" C1 C2 C3 C4 C5
Set V[absrow] &V[absrow] + 1
Set V[relrow] &V[relrow] + 1
goto new_row
label end_of_table
CloseFile "&U[filename]"
// Display file
Start "&U[filename]"
// Back to line 1
Enter "/scrollToLine=1" table="T[&U[tabname]]"
Leave