Skip to Content
Technical Articles
Author's profile photo Mathys van der Merwe

Copy Data from Screen to Excel via the Clipboard

In September 2021 during one of the practitioner forums someone mentioned needing to copy data from a screen onto Excel which sounded like a good challenge.

My example below is just taking a selection screen with a flavour on top to show the possibilities, but I’d guess any screen with different fields would do.  There is, of course, no need to do this with ALVs.

I created a simple favour with one additional script button:


To get the clipboard functionality I wrote a new function module which was placed in the Personas Whitelist.

FUNCTION zca_string_to_clipboard.
*"*"Local Interface:

  DATA: gt_text TYPE STANDARD TABLE OF char255.

  SPLIT p_excel_string AT '\n' INTO TABLE gt_text.

  CALL METHOD cl_gui_frontend_services=>clipboard_export
      data = gt_text
      rc   = gv_rc.



To use this function module, I attached the script which really only builds a long string of all the field values including tables and linefeeds.

var excelStr = session.findById("wnd[0]/usr/ctxtSO_PERNR-LOW").text;
excelStr += '\t';  //  Tab
excelStr += session.findById("wnd[0]/usr/ctxtSO_PERNR-HIGH").text;

excelStr += '\n';  // New Line

excelStr += session.findById("wnd[0]/usr/ctxtSO_UNAME-LOW").text;
excelStr += '\t';  //  Tab
excelStr += session.findById("wnd[0]/usr/ctxtSO_UNAME-HIGH").text;

excelStr += '\n';  // New Line

excelStr += session.findById("wnd[0]/usr/ctxtPA_DATAM").text;
excelStr += '\t';  //  Tab
excelStr += '';    // Empty cell for non-existing field

excelStr += '\n';  // New Line


var oRFC = session.createRFC("ZCA_STRING_TO_CLIPBOARD");
oRFC.setParameter("P_EXCEL_STRING", excelStr );

I tested this both on the browser as well as in the SAPGUI (we’re still on ECC 6.0, but guess would work on elsewhere).


This is a very fast, probably not the most elegant solution, but does work.

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.