Purpose
Read an ALV grid

Solution
Use a SAP standard function to copy the content of the ALV grid to the Windows clipboard; then read the clipboard via CopyText.

  • The ALV Grid Control (ALV = SAP List Viewer) is used in a large range of SAP transactions
  • An alternative way to read the grid values is offered by the command GetGridValues
Example
We read PM operations via IW37N and display them in a SAP GUI table:





GuiXT script

Pushbutton (toolbar) "Load operations" _

      process="load_operations.txt"

 

if V[opcount>0]

  Table (2,2) (30,135) name="operations" rows="&V[opcount]" _

      fixedcolumns=6 title="&V[opcount] operations selected"

   Column "Order" name="aufnr" size=8

   Column "Description" name="ktext" size=40

   Column "Operation" name="vornr" size=8

   Column "Short text" name="ltxa1" size=40

   Column "Workplace" name="arbpl" size=10

   Column "Syst.State" name="sttxt" size=20

endif

 


Input script load_operations.txt

Enter "/niw37n"

 

//  Selection of Orders and Operations

Screen RI_ORDER_OPERATION_LIST.1000

  Title "Please wait... Reading operations"

 

  // Sample selection criteria

  Set F[Period]        "25.02.2000"

  Set F[Period to]     "31.12.2017"

 

  Enter "/8"           // Execute

 

// List of Orders and Operations

Screen SAPLSLVC_FULLSCREEN.0500

  Title "Please wait... Reading operations"

  Enter "==%PC"   // Use command "==%PC", not "=%PC" !

 // Alternative:

  //  Enter "/Menu=1,11,3"  

 

// popup screen

Screen   SAPLSPO5.0110

  Title "Please wait... Reading operations"

 

  // 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 SAPLSLVC_FULLSCREEN.0500

  Title "Please wait... Reading operations"

 

  // read the clipboard into a text variable

  CopyText toText="temp"  -fromClipboard

 

  // restore the clipboard

  CopyText fromText="cbbackup"  -toCLipboard

  

  // clear all values

  Clear V[operations.*]

 

  // skip 3 header rows

  Set V[k] 4

 

  // table row index

  Set V[n] 0

 

  label next_row

  CopyText fromText="temp" toString="s"  line="&V[k]"

  if Q[ok]

  

    // increase row index

    Set V[n] &V[n] + 1

 

    CopyText fromString="s" toText="cells"

   

    CopyText fromText="cells" toString="operations.cell.aufnr.&V[n]" _
     
 line=3 delimiter="|"

    CopyText fromText="cells" toString="operations.cell.ktext.&V[n]" _
     
 
line=4 delimiter="|"

    CopyText fromText="cells" toString="operations.cell.vornr.&V[n]" _
     
 line=5 delimiter="|"

    CopyText fromText="cells" toString="operations.cell.ltxa1.&V[n]" _
     
 
line=6 delimiter="|"

    CopyText fromText="cells" toString="operations.cell.arbpl.&V[n]" _
     
 
line=7 delimiter="|"

    CopyText fromText="cells" toString="operations.cell.sttxt.&V[n]" _
     
 
line=8 delimiter="|"

   

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

    goto next_row

   

  endif

 

  Set V[opcount] &V[n]

 

  Return

Components
InputAssistant