Purpose
Process all table columns

We want to process all table columns, e.g. download all columns to a file.

Solution
Use the command GetFieldAttribute in order to loop through all table columns.

Example 1:

// loop through all table columns of table "All items", display test message

// column index
Set
V[m]
1

// text variable for test output
Set text[msg] ""

label next_header_column

// get column header
GetFieldAttribute [All items,&V[m]] header="h"
if Q[ok]
 
CopyText fromString="h"  toText="msg" -appendline
  
  // next column
  Set V[m] &V[m] + 1
 
goto next_header_column
endif

// display test message
Message "&text[msg]"


 .....

Example 2

This is a variant of the example in the previous tip "Scroll through a table". Instead of downloading a subset of the table columns we download all columns and also add a column title (first row of .csv file).
In transaction VA03 we add a button which saves all order items to a file and opens this file immediately. We use a ".csv" file so that Excel (if installed on the PC) will open up.

 

...


 
Excel opens and displays all order items and all columns

 

Our InputScript (below) uses GuiXT text variables instead of normal variables to generate the lines of the .csv file, since the size of one single row could exceed 4000 bytes for some tables,  and 4000 is the maximum size of normal variables.

GuiXT Script 

// add a button that downloads the order items to Excel
Pushbutton P[Display item details]+(0,54) "@J2@" _
       size=
(1,2) process=
"table_to_file.txt"
  using tabname = "All items"


InputScript
"table_to_file.txt"
 

// General script for table download including all columns
//
// Example how to use it:
//
// Pushbutton (toolbar) "Download table" _
// Process="table_to_file.txt"
// using tabname = "All items"

Parameter filename "&%[TEMP]\guixttemp.&V[today_ymdhms].csv"
Parameter tabname Table

// delimiter in CSV file
Set
V[delimiter] ";"

// Generate header row
Set
V[m] 1

// text variable for file generation
Set
text[txt] ""

label next_header_column

GetFieldAttribute [&U[tabname],&V[m]] header="h"

if Q[ok]
 
if V[m>1]
   
CopyText fromString="delimiter" toText="txt" -append
 
endif
 
 CopyText fromString="h" toText="txt" -append

  // next column
   Set V[m] &V[m] + 1
 
goto next_header_column

endif

// 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

// loop through all columns
Set V[m] 1
Set V[line] ""

label next_column

if cell[&U[tabname],&V[m],1]
 
if V[m=1]
   
Set V[line] "&cell[&U[tabname],&V[m],&V[relrow]]"
       CopyText fromString="line" toText="txt" -appendline
  else
      Set V[line] ";&cell[&U[tabname],&V[m],&V[relrow]]"
      CopyText fromString="line" toText="txt" -append
  endif

  // next column
  Set V[m] &V[m] + 1
  goto next_column

endif

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

label end_of_table

// Write text to file
CopyText fromText="txt" toFile="&U[filename]" -utf8

// Display file
Start "&U[filename]"

// Back to line 1
Enter "/ScrollToLine=1" Table="T[&U[tabname]]"

Leave

Components
InputAssistant