Excel download of selected table rows

Many SAP ERP transactions display data in  tabular form (table control).  In some cases a user might wish to get these data into an Excel spreadsheet for further display, printing and processing.

We present a simple technique using an InputScript to build an Excel spreadsheet from the table. The user selects some (or all) rows in the table and then presses a button that invokes our InputScript. The script scrolls through the whole table, collects all selected lines and generates an xxl-file. It then uses the “View” command to start Excel for this file. Required components: InputAssistant and Viewer.

Sap Guixt excel1 Excel download of selected table rows

Transaction MIR6. The user selects the rows that she would like to have in the spreadsheet  She then clicks on the “Download” button. The system collects all selected rows and starts Excel:

Sap Guixt excel2 Excel download of selected table rows

For the implementation you need the following 2 scripts:

SAPMM08N.E0201.txt:
Pushbutton (toolbar) “Download selected items” “Process=InvoicesToExcel.txt” 

InvoicesToExcel.txt:

// Parameter
Parameter filename “C:\temp\invoices.xxl”   // Filename for download

// Variables
Set V[absrow] 1   // Absolute row number
Set V[relrow] 1   // Relative row number

Screen sapmm08n.0201
OpenFile “&U[filename]” “-Output” 

// Column headers 
Set V[C1] “Doc. number”
Set V[C2] “Invoicing party”
Set V[C3] “Name of invoicing party”
Set V[C4] “Gross amount”

AppendFile “&U[filename]” C1 C2 C3 C4 

// Start with 1st line
Enter “/ScrollToLine=1″ 

label new_screen
Screen sapmm08n.0201 
Set V[relrow] 1

label new_row

// end of table?
if V[absrow>&[_listlastrow]] 
  CloseFile “&U[filename]“
  View “&U[filename]“
  Enter “/ScrollToLine=1″
  Leave
endif

// end of screen? 
if V[absrow>&[_listlastvisiblerow]] 
  Enter “/ScrollToLine=&V[absrow]“ 
  goto new_screen
endif

Set V[selected] “&cell[Table,0,&V[relrow]]”

// selected?
if V[selected=X]

  Set V[C1] “&cell[Table,Doc. number,&V[relrow]]”
  Set V[C2] “&cell[Table,Invoicing party,&V[relrow]]”
  Set V[C3] “&cell[Table,Name of invoicing party,&V[relrow]]”
  Set V[C4] “&cell[Table,Gross amount,&V[relrow]]”

  AppendFile “&U[filename]” C1 C2 C3 C4 
endif

Set V[absrow] &V[absrow] + 1 
Set V[relrow] &V[relrow] + 1 

goto new_row

Excel download of selected table rows