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