Calling a BAPI Synchronously from SAP System
This example demonstrates how to send the BAPI CompanyCode.GetDetail from an SAP system to the Web via XML.
As the BAPI will be handled by a routing notification, you need to specify some information to enable correct routing. For this purpose, you should use the parameter SBCHEADER when calling the RFC function module from the SAP system.
![*](icon_task_xpe.png)
To set up for the example
1. Set up an RFC Listener for the SAP system on your Adapter for SAP as described in
Listeners. 3. Create a program Z_BAPI_RFC_DEMO in the SAP system using the transaction SE38 You can enter the following source code:
REPORT Z_BAPI_RFC_DEMO .
*variable companyCodes will take the application result
data companyCodes like BAPI0002_1 occurs 1 with header line.
*variable header gives Adapter for SAP instructions for routing
data header like SBCCALLENV occurs 1 with header line.
*variable returnCode takes the processing information after the
*synchronous call
data returnCode type BAPIRETURN.
*Fill the Adapter for SAP routing instructions
header-name = 'sender'.
header-value = 'CERCLNT800'.
append header.
header-name = 'receiver'.
header-value = 'CERCLNT750'.
append header.
*Execute the RFC with destination ISCER
CALL FUNCTION 'BAPI_COMPANYCODE_GETLIST'
*->ISCER should be maintained in SM59 as alias to Adapter for SAP
DESTINATION 'ISCER'
IMPORTING
RETURN = returnCode
TABLES
COMPANYCODE_LIST = companyCodes
SBCHEADER = header[]
.
*process the BAPI-Return parameter
if not returnCode is initial.
write: / 'BAPI return parameter:'.
write: / ' Code: ' , returnCode-CODE.
write: / ' Message: ' , returnCode-MESSAGE.
endif.
*display the application result
loop at companyCodes.
write: / companyCodes-COMP_CODE, ' ', companyCodes-COMP_NAME.
endloop.