Exposing BAPI as Web Services through SAP XI
The example used in this step-by-step guide of building a web service through SAP XI
exposes the function module SAP_WAPI_START_WORKFLOW as a web service, which when executed
starts the WS20000391 (Schedule Manager) workflow to start a job.
1.2 Steps Overview
- Identify the import/export parameters of the workflow and the function module
- Design interface in SAP XI
- Configure interface in SAP XI
- Create web service in SAP XI
- Test the web service using Microsoft Office InfoPath 2003
- Verify the test results
- Basic understanding of SAP R/3 and SAP XI
- Working SAP R/3 or ECC system, and Exchange Infrastructure 3.0 and up
2.0 Identifying Required Parameters
2.1 Parameters for the Workflow
Display the template for workflow WS20000391 and view the container through transaction PFTC. Identify the required import parameters for this workflow which are marked with exclamation marks. JobName, StepsReports and StepsReportVariants are the required parameters for this workflow.
2.2 Parameters for the Function Module
Display the function module SAP_WAPI_START_WORKFLOW in function builder through transaction SE37. View its import information under the Import tab. Identify TASK, LANGUAGE, DO_COMMIT as the necessary import parameters for this scenario.
Display the Tables tab for the function module to identify the necessary table parameter INPUT_CONTAINER for this scenario.
3.0 Designing the Interface in XI
3.1 Integration Repository
Start up the homepage for the menu for XI tools using transaction SXMB_IFR. This can also be started with a manually entered URL in the browser. Click on Integration Repository under Integration Builder: Design to start designing the interface. A list of objects is displayed on th left when the integration repository window starts up. Expand the object that the interface will be created under, and then expand Imported Objects. Right click on RFC under Imported Objects to import the function module.
3.2 Activating Changes
Save and activate changes now and then to prevent from losing the work. Click on the Change Lists tab next to the Objects tab in the repository, and the change list for the user will be displayed. Navigate to the Standard Change List that contains the recent changes to be activated. Right click on Standard Change List and click Activate. Repeat this process throughout the design and configuration process within XI.
3.3 Deifning Request and Response Data Types
In the Objects tab, expand the namespace being worked with. Navigate to Data Types under Interface Objects. Right click on Data Types and click New to create a new data type. Name the data type correspondingly and save it.
Define a new data type each for request and response. The request data type for this interface is named StartWorkflowSchJob_REQ_DT. Name the response data type correspondingly as well.
Using the Type Definition tools, add necessary elements to the request and response data type structures.
3.4 Creating Request and Response Message Types
Navigate to Message Types under Interface Objects under the same namespace. Right click on Message Types and click New to create a new message type. Name the message types correspondingly for request and response; StartWorkflowSchJob_REQ_MT and StartWorkflowSchJob_RESP_MT.
In the Edit Message Type window after creating the message type, specify the corresponding data type that will be used for the specific message type by clicking on the Display Input Help button. The structure of the request data type is displayed in the request message type, and the structure of the response data type is displayed in the response message type.
3.5 Defining a Fault Message Type
Navigate to Fault Message Types under the same namespace and right click on it to create a new fault message type for the interface. The fault message type for this scenario is named StartWorkflowSchJob_FAULT_MT. Save and activate changes.
3.6 Defining the Message Interface
Navigate to Message Interfaces under Interface Objects under the same namespace in the integration repository. Right click on it to create a new message interface. Name the message interface correspondingly, in this case it is named StartWorkflowSchJob_MI.
Specify the interface to be outbound and synchronous in the Attributes section under the message interface Definition. Specify the request message type for the output message, the response message type for the input message and the fault message type for the fault message type by clicking on each Input Help button to the right of the input fields.
This conclude the creation of interface objects for this interface in the integration repository. Next mapping objects will be defined in the integration repository for the messages.
3.7 Creating a Message Mapping for the Inbound Request
Navigate to Message Mappings under Mapping Objects in the same namespace in integration repository. Right click on Message Mappings and click on New to create a new message mapping. Name the message mapping correspondingly. The request message mapping for this scenario is named StartWorkflowSchJob_REQ_MM. Specify the source and target messages for the message mapping and perform desired mapping using the graphical mapping tool. Click on Select Message in the Enter a source message section to display the list of options to choose from. Do the same in the Enter a target message section when selecting a target message.
Choose StartWorkflowSchJob_REQ_MT as the source message type for the request message mapping, and choose the imported function module SAP_WAPI_START_WORKFLOW as the target message.
The structures of the source and target messages specified are displayed in the left and right sections in the Design tab of the message mapping. Save the message mapping that has been defined so far to prevent from losing the progress. The RFC message structure for SAP_WAPI_START_WORKFLOW is displayed on the right hand side of the Design tab in the request message mapping as the target message.
Map the source elements to the target elements based on desired conditions and values. Recall the required import parameters that were identified for the function module in section 2.2. Those are the parameters that correspond to the elements in the target message that should be mapped for the request message mapping.
Map the constant “WS20000391” that specifies the workflow to the element TASK in the target message.
Map the constant “X” to the DO_COMMIT element in the target
Map the contant “EN” for English to the LANGUAGE element in the target message.
The INPUT_CONTAINER table parameter for the SAP_WAPI_START_WORKFLOW function module has three container elements. Therefore, the subtree of the INPUT_CONTAINER node in the target message must be duplicated twice to represent the three rows of the table. Right click on the item subtree under INPUT_CONTAINER in the target message and click on Duplicate Subtree. Repeat this step one other time so that INPUT_CONTAINER has three of the same Item subtrees.
Map the names of the required import parameters of the workflow Schedule Job identified in step 2.1 to each ELEMENT under each item subtree. The third ELEMENT would be mapped with the constant “StepsReportVariants”.
Map the node StartWorkflowSchJob_REQ_MT from the source message to the INPUT_CONTAINER node and each of the item subnodes. Each VALUE under each item subtree is mapped with each element in the source message. The second VALUE is mapped with ProgramName.
3.8 Creating a Message mapping for the Outbound Response
Navigate to Message Mappings under Mapping Objects in the same namespace in integration repository. Right click on Message Mappings and click on New to create a new message mapping. Name the message mapping correspondingly. Specify the source and target messages for the message mapping and perform desired mapping using the graphical mapping tool. The source message is the function module and the target message is the response message StartWorkflowSchJob_RESP_MT.
Map the source elements with the same names as the target elements to the target elements.
3.9 Defining the Interface Mapping
Navigate to Interface Mappings under Mapping Objects in the same namespace in integration repository. Right click on Interface Mappings and click New to create a new interface mapping for the interface. Name the mapping accordingly. Specify the source and target interfaces, and select the correct request and response message mappings. The interface mapping for the SOAP interface that is being defined in XI is named StartWorkflowSchJob_IM.
Select StartWorkflowSchJob_MI for the source interface of the interface mapping.
Select the imported function module SAP_WAPI_START_WORKFLOW as the target interface for the interface mapping.
Specify the request message mapping StartWorkflowSchJob_REQ_MM as the request mapping program.
Specify the response message mapping StartWorkflowSchJob_RESP_MM for the response mapping program. Save and activate all changes. The design of the interface in XI Integration Repository is done.
4.0 Configuring the Interface in XI
4.1 Configuration Wizard
Start up the homepage for the menu for XI tools. This can also be started with a manually entered URL in the browser. Click on Integration Directory under Integration Builder: Configuration to start designing the interface. A list of scenarios is displayed on the left when the integration directory window starts up. Click on the Configuration Wizard icon to start the configuration wizard.
Choose Internal Communication for message exchange within the same system landscape.
Specify the appropriate service and interface for the sender.
Specify the appropriate service and interface for the receiver.
Name the communication channel accordingly to define how the SOAP adapter will process the inbound message.
Use the default receiver determination configuration.
Use the default interface determination configuration.
Name the communication channel for the receiver accordingly.
4.2 Defining Communication Channel Details
After generating the scenario in the integration directory, define details for the sender and receiver communication channels specified by navigating to the objects from the Scenarios list and under the scenario that has been created. In the sender communication channel, specify the default interface namespace and name. The Quality of Service parameter can be specified for specific message delivery options.
5.0 Web Service Creation
5.1 Generating the WSDL File
In Integration Directory, from Tools in the main menu, select Define Web Service. Specify the parameters for the web service and save the generated wsdl file to desired path.
Specify the URL for the web service. The format should be
http://[server]:[port]/XISOAPAdapter/MessageServlet?channel=:[sender communication channel service]:[sender communication channel name]
Use the default interface information.
Specify the sender as done in interface configuration.
Review the information specified and click Finish to generate the wsdl file of the web service.
Click on Save to save the generated web service document to an accessible path.
6.0 Testing the Web Service
6.1 Designing and Testing the Form
Using Microsoft Office 2003 InfoPath, the web service that has been generated can be easily tested. To begin testing the web service, first design the form in InfoPath. Various other tools are also available for web service testing, including licensed and free tools.
Click on Design a Form after starting up InfoPath 2003.
Click on New from Data Connection in Design a Form window.
The Data Connection wizard starts up, choose Web service.
Choose Receive and submit data since the web service involves request and response.
Enter the path to the web service document that had been saved from XI.
Highlight the message interface.
Enter the name for the data connection for receiving data accordingly.
Click Next and follow the same steps for the data connection for sending data as done for the data connection for receiving data. Enter a name for the sending data connection correspondingly.
After configuring the data connections for both send and receive, specify the parameters that will be submitted through the web service to start the workflow. Choose one parameter at a time.
Finish the data connection creation.
Design the actual form of the web service.
Drag and drop field elements from the Data Source window into the submit and return sections of the form accordingly. When done with designing the form, click on Preview Form from the top menu to test.
Input valid test parameters into the boxes for the submit parameters and click the Submit Request button.
Enter valid logon information to connect to the web service.
7.0 Verifying the Test Results
7.1 Verification in XI
Go to the XI Integration Engine to make sure that the request and response messages have been successfully processed. In transaction SXMB_MONI, check the corresponding message ID for the processed request and response messages. Notice in the SOAP header of the request message, the
7.2 Verification in R/3
Verify in the target system that the workflow and the job have been started successfully. In transaction SWI1, verify that the Schedule Manager: Schedule Job job instance has been started correctly by the workflow instance.