Submit a report via RFC (Call statement) and process the list output, or read the resulting ALV grid data

ABAP reports are used in the implementation of numerous business functions in the SAP system. They either produce a standard list output (free format) or they display tabular data in a grid control via the the ABAP list viewer ALV.
In some cases the reports can be started via a transaction code, for example, IW39 (selection of PM orders, ABAP report RIAUFK20) or IW59 (selection of service notifications, ABAP report RIQMEL20) .

Solution Use the function module /guixt/submitreport.

Example 1
We read plant maintenance orders, using the standard ABAP report RIAUFK20 which implements transaction IW39:


At the right hand side of the above picture  you see the "System->Status" popup which shows the underlying program RIAUFK20, here in an S/4HANA system.

Alternatively you may use transaction SE93 to display the transaction type and the underlying ABAP program:

There are two ways to pass the selection parameters to /guixt/submitreport:

(a) Define a selection variant and pass the name of the variant
(b) Pass a table containing all individual selection parameters

In this example we assume that there is a selection variant "OPENORDERS" defined in IW39 which we want to use:

The selection variant OPENORDERS also defines the layout of the resulting grid control:

The "Displayed columns" are precisely the columns that are returned by /guixt/submitreport.



// read PM orders via RIAUFK20 and variant OPENORDERS
"/guixt/submitreport" _
in.progname="RIAUFK20" _
in.variant="OPENORDERS" _

// copy grid data into CSV file
CopyText fromText="pmorders" toFile="C:\temp\pmorders.csv" -utf8

// display the file (Excel)
Start "C:\temp\pmorders.csv"



Excel opens up and displays the selected PM orders:


Example 2
We display sales figures for material numbers entered by the user:

The material texts are read from the database (table MAKT) and the sales figures via the sales information system:

The underlying transaction is MCTC and the ABAP report is RMCV0200:

GuiXT Script  

// create structured variables
not V[matorders]
CreateStructure V[matinfo] matnr maktx orders sales quantity
CreateTable V[matorders] include=V[matinfo]

// list of selectable years
Set V[year0] "&V[today_y]"
Set V[year1] &V[year0] - 1
Set V[year2] &V[year0] - 2

Set text[list_of_years] "&V[year0];&V[year1];&V[year2]"

// default: current year
if not V[selected_year]
  Set V[selected_year] "&V[year0]"

// year selection
Text (1,10) "Select year" -label
DropDownList (1,20) "list_of_years" width=10 refer="V[selected_year]" -nosort

// button to read statistics data
Pushbutton (1,36) "Read sales data" size=(1,24) process="read_sales_data.txt"

// table to enter material numbers and display the sales figures
Table (3,10) (15,118) title="Material orders in &V[selected_year]" _
name="matorders" fixedcolumns=
Column "Material" size=16 name="matnr" searchhelp="MAT1"
Column "Text" -readonly size=40 name="maktx"
Column "Incoming orders" -readonly size=16 name="orders"
Column "Sales volume" size=16 name="sales" -readonly
Column "Billing Qty" size=16 name="quantity" -readonly


// ---------------------------------------
// Read sales data via SAP report RMCV0200
// ---------------------------------------

// First we check the entered material numbers and read the material texts
// We also determine the internal format of the material numbers and
// collect them as selection parameters

Set V[k] 0

// table for report selection parameters
CreateStructure V[rsparams] selname kind sign option low high
CreateTable V[myparams] include=V[rsparams]

// process all table rows
label next_row

if V[k<&V[matorders.rowcount]]

  Set V[k] &V[k] + 1
// read table row Nr. k
   ReadRow V[matinfo] table=V[matorders] index=&V[k]

  // material number specified?
   if V[matinfo.matnr]

  // read material text and also return matnr in internal format
  // we use the cache so that each material is read only once if
  // the user presses the "Read" button again

  Call text[r]

  Call /guixt/dbselect cache="transaction" _
 in.table="MAKT" _
in.fields="MAKTX,*MATNR" _
in.condition="SPRAS = '&V[_language]' and MATNR = @MATNR" _
in.domname1="MATNR" _
in.domvalue1="&V[matinfo.matnr]" _

  // material text and matnr in internal format
  CopyText fromText="r" toString="maktx" line=1
  CopyText fromText="r" toString="intmatnr" line=2

 // set material text
  Set V[matinfo.maktx] "&V[maktx]"

  // material not found?
  if not V[maktx]

     // clear existing text
    UpdateRow V[matinfo] table=V[matorders] index=&V[k]

    // set cursor to wrong material number
     if V[k<&V[matorders.stat.firstvisiblerow]] or _

         // scrolling is necessary
        Set V[matorders.stat.firstvisiblerow] &V[k]
        SetCursor cell[matorders,matnr,1]


      // no scrolling is necessary
      Set V[relposrow] &V[k] - &V[matorders.stat.firstvisiblerow]
      Set V[relposrow] &V[relposrow] + 1
      SetCursor cell[matorders,matnr,&V[relposrow]]


     // display error message
      Message "E: Material &V[matinfo.matnr] not found" -statusline

    // teminate processing


    // append material number
  Set V[rsparams.selname] "SL_MATNR"
  Set V[rsparams.kind] "S"
Set V[rsparams.sign] "I"
Set V[rsparams.option] "EQ"
Set V[rsparams.low] "&V[intmatnr]"
AppendRow V[rsparams] table=V[myparams]


   Clear V[matinfo]


 // update the row, i.e. set the material text
 UpdateRow V[matinfo] table=V[matorders] index=&V[k]

 goto next_row


// set sales organization selection
Set V[rsparams.selname] "SL_VKORG"
Set V[rsparams.kind] "S"
Set V[rsparams.sign] "I"
Set V[rsparams.option] "EQ"
Set V[rsparams.low] "1010"
AppendRow V[rsparams] table=V[myparams]

// set period selection
Set V[rsparams.selname] "SL_SPBUP"
Set V[rsparams.kind] "S"
Set V[rsparams.sign] "I"
Set V[rsparams.option] "BT"
Set V[rsparams.low] "&V[selected_year]01"
Set V[rsparams.high] "&V[selected_year]12"
AppendRow V[rsparams] table=V[myparams]

// Start report RMCV0200 for the entered material numbers
Set V[progname] "RMCV0200"

// csvdata has only one component ("feld")
V[csvdata] feld

// submit report
"/guixt/submitreport" _
export.progname="progname" _
export.params="myparams" _

// we transform the CSV format into GuiXT structured table
CreateStructure V[mysalesinfo] matnr orders sales openquantity quantity
CreateTable V[mysales] include=V[mysalesinfo]

fromTable=V[csvdata] toText="temp"
CopyText fromText="temp" toTable=V[mysales] delimiter=";"

// finally we merge the sales values into our table
Set V[k] 0

label merge_sales

if V[k<&V[matorders.rowcount]]
  Set V[k] &V[k] + 1

  // read table row
  ReadRow V[matinfo] table=V[matorders] index=&V[k]

  // material number specified?
  if V[matinfo.matnr]

   // table lookup in the sales figure table
     ReadRow V[mysalesinfo] table=V[mysales] key="&V[matinfo.matnr]"
     if q[ok]
        Set V[matinfo.orders] "&V[mysalesinfo.orders]"
        Set V[matinfo.sales] "&V[mysalesinfo.sales]"
 Set V[matinfo.quantity] "&V[mysalesinfo.quantity]"
       Clear V[matinfo.orders]
  Clear V[matinfo.sales]
 Clear V[matinfo.quantity]

   // update table row (sales figures)
    UpdateRow V[matinfo] table=V[matorders] index=&V[k]


  // next row
  goto merge_sales




Components InputAssistant