Portlet Factory, Version 6.1.2


 

Calling multiple BAPIs within a single connection

To use some BAPIs, it is necessary to call more than one BAPI within the same connection or transaction. To do this, use Java code such as the example shown below. You would access this code using the Linked Java Object builder, in which you would use the callSAPFunction method from an Action List or Method in the builder.

This code makes use of two supporting classes that are provided with the SAP builders:

  • SAPAccess is the class that manages connections to SAP via JCO.

  • SAPCall is used to invoke a single BAPI. You can create an SAPCall object by calling createSAPCall from the SAPAccess object. From there you can programmatically set Imports on this object, execute the BAPI, and get results from Exports or Tables.

Note: To compile this code in your IDE, you will need to add the WEB-INF/work/lib/SAP_Builder.jar to your compile classpath.

package com.bowstreet.test; import com.bowstreet.Builders.webapp.methods.SAPAccess; import com.bowstreet.Builders.webapp.methods.SAPCall; import com.bowstreet.util.IXml; import com.bowstreet.webapp.WebAppAccess;
/**
* Example of calling multiple BAPI's on a single connection.
* The SAPCall class is used to programmtically invoke a single BAPI, setting Imports values.
*/
public class SAPMultiCall String BuilderName = "update"; // The name used in SAP Function Call or SAP View & Form Builder
static final String BAPI_EMPLOYEE_ENQUEUE = "BAPI_EMPLOYEE_ENQUEUE";
static final String BAPI_PTM_GRATTABS_MNGCREATION = "BAPI_PTM_GRATTABS_MNGCREATION";
static final String BAPI_TRANSACTION_COMMIT = "BAPI_TRANSACTION_COMMIT";
static final String BAPI_EMPLOYEE_DEQUEUE = "BAPI_EMPLOYEE_DEQUEUE";
/**
* Call multiple BAPI's on a single JCO connection.
* @param webAppAccess
*/ protected void callSAPFunction(WebAppAccess webAppAccess) SAPAccess sapAccess = (SAPAccess)webAppAccess.callMethod(BuilderName + ".getSAPAccess"); String empNo = "90000103"; SAPCall sapCall = sapAccess.createSAPCall(BAPI_EMPLOYEE_ENQUEUE); sapCall.setImportsValue("NUMBER", empNo); sapCall.execute(false); sapCall = sapAccess.createSAPCall(BAPI_PTM_GRATTABS_MNGCREATION); sapCall.setImportsValue("EMPLOYEENUMBER", empNo); sapCall.setImportsValue("ABS_ATT_TYPE", "0150"); sapCall.setImportsValue("HRABSATT_IN.FROM_DATE", "20040505"); sapCall.setImportsValue("HRABSATT_IN.TO_DATE", "20040506"); sapCall.execute(false);
// Populate Exports variable with this function Exports String varName = BuilderName + "_Exports";
IXml data = sapCall.getExportsXML(); if (data != null) webAppAccess.getVariables().setXml(varName, data); sapCall = sapAccess.createSAPCall(BAPI_TRANSACTION_COMMIT); sapCall.execute(false);
// last call - pass "true" to close connection sapCall = sapAccess.createSAPCall(BAPI_EMPLOYEE_DEQUEUE); sapCall.setImportsValue("NUMBER", empNo); sapCall.execute(true);
}

Parent topic: SAP Function Call builder


Library | Support |