Purpose
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.

 

InputScript  

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

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

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

 

 

Result
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
if
not V[matorders]
 
CreateStructure V[matinfo] matnr maktx orders sales quantity
 
CreateTable V[matorders] include=V[matinfo]
endif

// 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]"
endif

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

 

InputScript
 
// ---------------------------------------
// 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]" _
  
table.values="r"

  // 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 _
     
V[k>&V[matorders.stat.lastvisiblerow]]

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

     else

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

    endif

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

    // teminate processing
     return

  endif

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

 else

   Clear V[matinfo]

 endif

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

 goto next_row

endif

// 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")
CreateTable
V[csvdata] feld

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

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

CopyText
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]"
     else
       Clear V[matinfo.orders]
  
  Clear V[matinfo.sales]
   
 Clear V[matinfo.quantity]
 
 endif

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

  endif

  // next row
  goto merge_sales

endif

return

 

Components InputAssistant