From an InputScript, you can use  Call to call function modules of the SAP system, in particular the "BAPI" modules (Business API), which are provided by SAP for reading and saving data. In the case of the screen transactions described in the previous tutorial, you can also implement the saving of data by calling a BAPI in some cases instead of scripting the corresponding SAP transaction. This has advantages and disadvantages:

Advantages

  • Saving using a BAPI is usually faster, especially if the scripting of the SAP transaction requires a large number of dialog steps

  • Saving is independent of any changes to the SAP interface

Disadvantages

  • A suitable BAPI must be available that covers all the required fields

  • Implementation requires familiarization with the interface of the respective BAPI, which is sometimes only possible with debugging at ABAP level

  • The handling of incorrect entries is usually better covered by the SAP interface than by the BAPIs

  • Not all necessary authorization checks are always carried out in a BAPI; this is automatically the case when using the SAP user interface

  • For the BAPI interface you always need the internal formats of the input values. We therefore recommend that you use the GuiXT Open Call Interface to call the BAPI, which performs all format conversions automatically


As an example, we implement storing the maintenance malfunction report from the previous tutorial using a BAPI instead of the scripting of transaction IW21:

GuiXT mask for quick entry of a fault message for equipment


We use the BAPIs

In addition, the "Check" function then requires the equipment text to be read directly from the database; in the scripting solution, this text is taken from transaction IW21.

The GuiXT script for defining the fast entry interface is identical to the previous tutorial. The plausibility checks for the entered values are also identical. Saving itself is done by BAPI calls:

/ -----------------------------------------------------
// IW21 Fast data acquisition (check/save)
// File "iw21_simple_save.txt"
// Solution via BAPI calls
// -----------------------------------------------------

Parameter MODE // C=Check S=Save

// Plausibility checks

// Equipment specified?
if not V[iw21_equnr]
  SetCursor V[iw21_equnr]
  Return "E: Please enter the equipment number" -statusline
endif

//  Short text specified?
if not V[iw21_qmtxt]
  SetCursor V[iw21_qmtxt]
  Return "E: Please enter a short text" -statusline
endif

// Date specified?
if not V[iw21_ausvn]
  SetCursor V[iw21_ausvn]
  Return "E: Please emter the date" -statusline
endif

// Date format correct?
CheckDate "&V[iw21_ausvn]"
if not Q[ok]
  SetCursor V[iw21_ausvn]
  Return "E: Please check the date -statusline
endif

// Read equipment text
Set V[table] "EQKT"
Set V[condition] "EQUNR = @EQUNR AND SPRAS = '&V[_language]' "
Set V[fields] "EQKTX"
Set V[domname1] "EQUNR"
Set V[domvalue1] "&V[iw21_equnr]"

// Table for returning the database values
CreateTable V[eqkttab] eqkt

Call "/GUIXT/DBSELECT" cache="transaction" _
 
export.TABLE="table" _
 
export.CONDITION="condition" _
 
export.FIELDS="fields" _
 
export.DOMNAME1="domname1" _
 
export.DOMvalue1="domvalue1" _
 
import.VALUES="eqkttab"

//// Transfer equipment text
Set V[iw21_eqktx] "&V[eqkttab.eqkt.1]&]"

// found? otherwise error message
if not V[eqkttab.eqkt.1]
  SetCursor V[iw21_equnr]
  Return "E: Equipment &V[iw21_equnr] nicht gefunden" -statusline
enendif

// Notification type
Set V[iw21_qmart] &q"M2"

// Notification header
CreateStructure V[iw21_notifheader] equipment short_text strmlfndate strmlfntime priority

Set V[iw21_notifheader.equipment] "&V[iw21_equnr]"
Set V[iw21_notifheader.short_text] "&V[iw21_qmtxt]"
Set V[iw21_notifheader.strmlfndate] "&V[iw21_ausvn]"
Set V[iw21_notifheader.strmlfntime] "&V[iw21_auztv]"
Set V[iw21_notifheader.short_text] "&V[iw21_qmtxt]"
Set V[iw21_notifheader.priority] "&V[iw21_priok]"

//// Copy long text to BAPI format
CreateTable V[bapilongtext] objtype objkey format_col text_line

// Line index for long text lines
Set V[k] 1

label copy_text_line
CopyText fromText="iw21_longtext" toString=line line=&V[k]

if q[ok]
  Set V[bapilongtext.objtype.&V[k]] "QMEL"
  Set V[bapilongtext.format_col.&V[k]] "/"
  Set V[bapilongtext.text_line.&V[k]] "&V[line]"
 
Set V[k] &V[k] + 1
 
goto copy_text_line
endif

/// Structures/tables for BAPI call with the required fields
CreateStructure V[iw21_notifheader_export] notif_no
CreateStructure V[bapireturn] type message
CreateTable V[bapireturntab] include=V[bapireturn]

Call "BAPI_ALM_NOTIF_CREATE" _
 
export.NOTIF_TYPE="iw21_qmart" _
 
export.NOTIFHEADER="iw21_notifheader" _
 
export.LONGTEXTS="bapilongtext" _
 
import.NOTIFHEADER_EXPORT="iw21_notifheader_export" _
 
import.RETURN="bapireturntab"

// Error messages from BAPI?
ReadRow V[bapireturn] table=V[bapireturntab] key="E"

if Q[ok]
  Return "E: &V[bapireturn.message]" -statusline
endif

// Notification number
Set
V[qmnum] "&V[iw21_notifheader_export.notif_no]"

// Save notification
Call
"BAPI_ALM_NOTIF_SAVE" _
 
export.NUMBER="qmnum" _
 
import.RETURN="bapireturntab"

// Error messages from BAPI?
ReadRow V[bapireturn] table=V[bapireturntab] key="E"

if Q[ok]
  Return "E: &V[bapireturn.message]" -statusline
endif

// Check only
if U[MODE=C]
  Call "BAPI_TRANSACTION_ROLLBACK"
  Return "S: Eingabedaten geprüft" -statusline
endif

Call "BAPI_TRANSACTION_COMMIT"

// Reset input data
Clear V[iw21_*]
Clear text[iw21_longtext]

//  Stay on fast entry
Set V[iw21_simple] "X"

Return "S: Notification created: &V[qmnum]" -statusline