Skip to content
PDF

Content Script Extension for SAP

Using the extension

This section describes how to use the SAP API to retrieve data from the SAP system. The main Script API Object you are going to use is the SAPFunction object, which can be obtained from the sap service by calling sap.getFunction Script API Method. The SAPFunction object works the same for either an existing xECM connection or for a custom connection.

def sapfunc = sap.getFunction("BAPI_TIMEQUOTA_GETDETAILEDLIST", "PRD")

Function's input parameters can be specified using the setImpParam method:

def sapfunc = sap.getFunction("BAPI_TIMEQUOTA_GETDETAILEDLIST", "PRD")
sapfunc.setImpParam("EMPLOYEENUMBER", cid)
sapfunc.setImpParam("DEDUCTBEGIN", now)
sapfunc.setImpParam("DEDUCTEND", now)

To invoke a function in the target system and retrieve the function's result just call the execute method of the SAPFunction object:

def sapfunc = sap.getFunction("BAPI_TIMEQUOTA_GETDETAILEDLIST", "PRD")
sapfunc.setImpParam("EMPLOYEENUMBER", cid)
sapfunc.setImpParam("DEDUCTBEGIN", now)
sapfunc.setImpParam("DEDUCTEND", now)
sapfunc.execute()

Function execution results

The extension package features several options that help you in properly manage a function's execution result:

  1. Function export parameter is in Table form Get content of table parameter of function execution result, i.e. as SapTable Script API Object. See sample code below
//result as SAPTable class
def sapTblQuote = sapfunct.table("ABSENCEQUOTARETURNTABLE", 
                            "QUOTATYPE", 
                            "QUOTATEXT", 
                            "DEDUCTBEGIN", 
                            "DEDUCTEND", 
                            "ENTITLE", 
                            "DEDUCT", 
                            "ORDERED", 
                            "REST", 
                            "REST_FREE", 
                            "TIMEUNIT_TEXT" )

def quote = sapTblQuote.rows.collect{ 
            [
                "quotaType":it.QUOTATYPE, 
                "quotaText":it.QUOTATEXT, 
                "begin":it.DEDUCTBEGIN, 
                "end":it.DEDUCTEND, 
                "entitle":it.ENTITLE, 
                "deduct":it.DEDUCT+it.ORDERED, 
                "rest":it.REST_FREE
            ]}

Please refer to SAPTable Script API Object for more detailed description of available methods and options.

  1. Function export parameter is in Structure form Get content of a structure export parameter as a SapStructure Script API Object. See sample code below
def cumulateSAPStctr = sapfunct.table("CUMULATEDVALUES", 
                                    "QUOTATYPE", 
                                    "QUOTATEXT", 
                                    "ENTITLE", 
                                    "DEDUCT", 
                                    "ORDERED", 
                                    "REST", 
                                    "REST_FREE", 
                                    "TIMEUNIT_TEXT" )
//optionally you can call cumulateSAPStctr.getRows("QUOTATYPE","QUOTATEXT",...).collect()             
def cumulate = cumulateSAPStctr.rows.collect{
                    [
                        "quotaType":it.QUOTATYPE, 
                        "quotaText":it.QUOTATEXT, 
                        "entitle":it.ENTITLE, 
                        "deduct":it.DEDUCT+it.ORDERED, 
                        "rest":it.REST_FREE
                    ]}

Please refer to SapStructure class API for more detailed description of available methods and options.

  1. Get generic value of export parameter To get value of function export parameter you can use gertExportParam() method. Please see sample code below:
def empldet = sap.getFunction("Z_HR_MSD_RFC01_AD_EMPL_SINGLE", "PRD")
                    .setImpParam("I_PERNR", cid).execute()
                    .getExportParam("E_AD_EMPL")

All necessary conversions between Java and ABAP data types are done automatically.

Sample code listing below contains sample usage scenarios of SAP integration extension:

        // BAPI Function
getSAPHRData = {
    cid ->
    def now = new Date()
    def sapfunct = sap.getFunction("BAPI_TIMEQUOTA_GETDETAILEDLIST", "PRD")
                        .setImpParam("EMPLOYEENUMBER", cid)
                        .setImpParam("DEDUCTBEGIN", now)
                        .setImpParam("DEDUCTEND", now)
                        .execute()
    def quote = sapfunct.table("ABSENCEQUOTARETURNTABLE", 
                            "QUOTATYPE", 
                            "QUOTATEXT", 
                            "DEDUCTBEGIN", 
                            "DEDUCTEND", 
                            "ENTITLE", 
                            "DEDUCT", 
                            "ORDERED", 
                            "REST", 
                            "REST_FREE", 
                            "TIMEUNIT_TEXT" ).rows.collect{ 
        ["quotaType":it.QUOTATYPE, "quotaText":it.QUOTATEXT, "begin":it.DEDUCTBEGIN, "end":it.DEDUCTEND, "entitle":it.ENTITLE, "deduct":it.DEDUCT+it.ORDERED, "rest":it.REST_FREE]
    }
    def cumulate = sapfunct.table("CUMULATEDVALUES", 
                                "QUOTATYPE", 
                                "QUOTATEXT", 
                                "ENTITLE", 
                                "DEDUCT", 
                                "ORDERED", 
                                "REST", 
                                "REST_FREE", 
                                "TIMEUNIT_TEXT" ).rows.collect{ 
        ["quotaType":it.QUOTATYPE, "quotaText":it.QUOTATEXT, "entitle":it.ENTITLE, "deduct":it.DEDUCT+it.ORDERED, "rest":it.REST_FREE]
    }
    return ["quote":quote, "cumulate":cumulate]
}


quotaMap = getSAPHRData(cid)


out << template.evaluateTemplate("""

<div>
    #@cstable(['Quote', 'Begin', 'End', 'Entitle','Deduction', 'Rest'] {  '':'' } {  '':'' })
        #foreach(\$row in \$quotaMap.quote)
            <tr>
                <td>\$row.quotaText</td>
                <td>\$date.format('dd.MM.yyyy', \$row.begin)</td>
                <td>\$date.format('dd.MM.yyyy', \$row.end)</td>
                <td>\$row.entitle</td>
                <td>\$row.deduct</td>
                <td>\$row.rest</td>
            </tr>
        #end
    #end
</div>

"""
)       

SAP service APIs

Method Summary
SapFunction
getFunction(String functionName, String destinationName)
Get a SAP function for the specified destination
SapFunction
getFunction(String functionName)
Get a SAP function for the default destination ('default')

API Objects

SapField

Method Summary
SapField
setValue(Object value)
Set the field value
Field Summary
Object
value
Get the field value

SapFunction


Method Summary
SapFunction
disableExpParam(String paramName)
Disable an export param
SapFunction
enableExpParam(String paramName)
Enable an export param
SapFunction
execute()
Executes the SAP function.
Object
getChangingParam(String paramName)
Get a changing param
Object
getExportParam(String paramName)
Get an export param
Object
getImportParam(String paramName)
Get an import param
SapFunction
setImpParam(String paramName, Object paramValue)
Set the value of an import param
SapStructure
structure(String structureName, String[] fieldNames)
Fetch the content of a structure export parameter
SapTable
table(String tableName, String[] columnNames)
Fetch the content of a table parameter

SapStructure


Method Summary
Map<String, Object>
getRow(String[] columns)
Return the table content as a list of maps
SapStructure
setColumns(String[] columns)
Set the table columns in the list of maps
SapStructure
setColums(String[] columns)
Set the table columns in the list of maps
SapStructure
setRow(Map<String, Object> values)
Add a row and set the key/value mappings for the row
Field Summary
Map<String, Object>
row
Return the table content as a list of maps

SapTable


Method Summary
SapTable
addRow(Map<String, Object> values)
Add a row and set the key/value mappings for the row
List<Map<String, Object>>
getRows(String[] columns)
Return the table content as a list of maps
SapTable
setColumns(String[] columns)
Set the table colums in the list of maps
SapTable
setColums(String[] columns)
Set the table columns in the list of maps
Field Summary
List<Map<String, Object>>
rows
Return the table content as a list of maps