Purpose
Read the content of an ABAP list (no ALV grid)

There are still a lot of "classic" ABAP lists in the SAP system which display a structured list output (no ALV grid). You may want to read the content of the list, for example in order to download the displayed values to a file.

Solution
Use the SAP system function  "Save into clipboard" and then read the Windows clipboard with CopyText.

Example
Transaction "MRN1" displays the range of coverage for the selected materials. We add a button
in the toolbar that allows the user to download the values to Excel:

 

 

Excel opens up and displays the list values:

.........


GuiXT Script

Pushbutton (toolbar) "@J2@Excel" process="mrn1_download.txt" -separator


InputScript
 "mrn1_download.txt"

// Save list
Enter "=%PC"

// popup screen
Screen  SAPLSPO5.0110

// SAP displays the text in this general
// popup via an HTML control
// we can disable the control
// avoiding that the popup becomes visible
// for a short moment
Disable controls

// save Windows clipboard content
CopyText toText="cbbackup" -fromClipboard

// select "clipboard" option
Set R[In the clipboard] "X"

Enter

Screen RMNIWE10_01.0120

// read the clipboard into a text variable
CopyText toText="list" -fromClipboard

// restore the clipboard
CopyText fromText="cbbackup" -toClipboard

// we now generate a temporary .csv file from the list
// build temporary filename using TEMP environment variable and current time
Set V[tfn] "&%[TEMP]\RangeOfCoverage.&V[today_ymdhms].csv"

// create new filee
Openfile "&V[tfn]" -output -utf8 delimiter=";"

Set V[k] 1

label next_line

CopyText fromText="list" toString="listline" line="&V[k]"
if Q[ok]
  CopyText fromString="listline" toText="temp"
 
CopyText fromText="temp" toString="material" line=3 delimiter="|"
 
CopyText fromText="temp" toString="mattext" line=5 delimiter="|"
 
CopyText fromText="temp" toString="avgstock" line=7 delimiter="|"
  CopyText fromText="temp" toString="avgcons" line=9 delimiter="|"
  CopyText fromText="temp" toString="unit" line=10 delimiter="|"
 
CopyText fromText="temp" toString="coverage" line=11 delimiter="|"
 
CopyText fromText="temp" toString="baseprice" line=12 delimiter="|"
 
CopyText fromText="temp" toString="newprice" line=14 delimiter="|"

   if Q[ok]
     AppendFile "&V[tfn]" material mattext avgstock _
               unit avgcons coverage baseprice newprice
  
endif

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

endif

// close the .csv file
Closefile "&V[tfn]"

// display file (Excel will open up for .csv if installed)
Start "&V[tfn]"

// press enter
Enter

 

Components
InputAssistant