SAP Function Call Builder

 

In this topic ...

Specifying Credentials

Calling Multiple BAPIs within a Single Connection

Related Topics ...

SAP View & Form Builder

The Function Call Builder provides the underlying technology required for a WebSphere Portlet Factory model to establish a connection to and interact with an SAP system. This Builder provides the basic SAP connection and function selection inputs that are used in the SAP View & Form Builder. This Builder does not provide the page and display options available in the View & Form Builder.

This low-level Builder is used to establish a call to a remote-enabled SAP function. This Builder creates a Java method that can be called to get data from the SAP system. This Builder also creates model variables that contain the data returned from the function.

This Builder s functionality is incorporated into the SAP View & Form Builder.

 

Specifying Inputs

The SAP Function Call Builder takes the inputs described in the table below. For help on inputs common to many or all Builders such as those in the Properties and HTML Attributes input groups, see "Using the Builder Call Editor."

Input Name Description
Name Enter a name for this Builder call. The Designer displays this name in the Builder Call List.
Connection
Properties File Enter the name of the properties file to be used to establish SAP host server information.

Example: my_sap.properties

This file must be located in the WEB-INF/config/sap_config directory

Test Connection Button Press this button to test the connection to the SAP host server. If the connection is successful, a connection confirmation dialog is displayed.
Runtime Credentials Select the type of credentials to use to access the SAP system. We can choose:

  • Use same credentials properties for all users To use the user name and password credentials specified in the .properties file regardless of which users is running the SAP portlet.

  • Specify execution credentials To specify a user name and password that will be used by this Builder to access the SAP host server.
Execution User Name This input is available when "Specify Execution Credentials" is selected as the Runtime Credentials input.

Specify an indirect reference to the location used to store the SAP user name. This location might be a variable or method result.

Execution Password This input is available when "Specify Execution Credentials" is selected as the Runtime Credentials input.

Specify an indirect reference to the location used to store the password.

Function Selection
Search Pattern Enter a string to be used as search criteria for a function. We can use an asterisk (*) as a wildcard at any location within the search string.

For example, entering DDIF_* returns all functions whose name starts with "DDIF".

Search for Functions Press this button to start a search.

When the search is complete, the SAP Function input contains a list of functions matching the search pattern.

SAP Function Use this select box to choose a function to call.

When you select a function in the list, a description of the function is displayed below the list.

Description A read-only field that displays a brief description of the selected function.
Enable Schema Caching Use this check box to enable the caching of the schema for the specified SAP Function. When enabled, the Builder s regeneration phase uses a cached version of the Function s schema. If a different Function is selected a new version of the schema will be cached.

Selecting this option provides two benefits:

  • Enhanced Performance -  This helps during editing models containing this Builder.

  • Enhanced Security - A cached schema avoids exposing model generation time credentials once an initial regen has been performed. To leverage this specify to use separate runtime credentials (see the "Runtime Credentials" input).

Note - If the schema for the data changes on the SAP server, disable this input, regenerate the model, and enable this input again.

Function Inputs
Function Inputs If you know the function you are calling accepts optional inputs, we can enter Input Names and Input Values in this table. These Function Inputs can be used instead of getting inputs from the user in an input form.

For example, if you want to supply a constant value to an input we can do it here. Or, if you are using this Builder to call a function using data from a row in a table of results, we can use values from the "SelectedRowData" variable as inputs. (See the SAPObjectBrowser model for some examples of this.)

These inputs will be set in Imports before the function is called and the values you define here override previously established values in the Input variable

Advanced
Connection Properties Use this input to override any connection properties established in the connection properties file. You might want to do this if you want to profile a value such as the host server name.

Select a property in the Property Name box and provide an input for that property in the Property Value box

Commit Transaction Enable this to commit transactions to the SAP database as a result of this function call.
Use tables as function inputs Enable to use a table as an input to a function call.

 

Specifying Credentials

You have several options when choosing the credentials used to access the SAP system at portlet execution time. We can use the same credentials for all portlet users if you want all users to use the same user name and password.  In many cases, it is desirable to have different credentials for each user. Implementing this feature varies greatly between different brands of portal server, therefore, it is best to refer to the specific portal server's documentation to learn how to implement user-specific credentials.

 

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. We can create an SAPCall object by calling createSAPCall from the SAPAccess object.  From there we can programmatically set Imports on this object, execute the BAPI, and get results from Exports or Tables.

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);

    }

}