Exploring SAP Profitability and Performance Management’s Remote Function Adapter – External Function Type
SAP Profitability and Performance Management (abbreviated as “PaPM” in this blog further) Remote Function Adapter (RFA) function provides automated communication capabilities to other application and systems. Remote Function Adapter comes with different function types to set-up communication and posting. These vary from:
- Posting of Finance AP, AR, GL entries
- Calling external R script procedure
- Calling HANA stored procedure
- Integration scenario with SAP SD for creation of Sales Order, Inquiry or Quotation
- Replicating CO Master Data
- And External Function for calling remote NetWeaver function or a Web service
In this blog I am sharing one example to showcase the configuration of Remote function Adapter Function’s “External Function” type and its execution.
Let’s assume that Database Connection and RFC destination is already in place as per Post Installation Steps Guide. (Ref. – https://help.sap.com/viewer/a8068ea2f9ba403aa6d8bda3abcdbecd/3.12/en-US/35fb5f2fc7e4448484b32162cdb1f17c.html )
Consider a scenario where we are running Allocations in PaPM system and want to post the results of allocations to SAP S/4HANA®. There is standard BAPI BAPI_ACC_MANUAL_ALLOC_POST available in SAP to Post Manual Cost Allocation. As this BAPI is not covered in standard Function Types of Remote Function Adapter, let’s configure RFA’s External Function to meet this requirement.
Steps in SAP PaPM:
It is assumed allocation function is already set up, activated and allocation results are available as output of this function. (The detailed steps for setting up Allocations Cycle is beyond Scope of this blog.)
- In the Modeling Environment, select Allocation function from the panel and click on Function Attribute
The function Attributes pop- up will appear. Navigate to Runtime Attribute tab and note down DDIC Table Name (this will be required in SAP S/4HANA system steps)
- Add Function in the environment in right node– Select Type as Remote Function Adapter, Enter Function ID, Description. You can keep remaining fields as defaults or as per your requirement.
Inside RFA function ZTRFA, select Remote Function Adapter Type as “External Function”. Enter RFC Connection where this External Function Belongs to. Select the function Name which you will be creating in SAP S/4HANA System (If External function is already available in the remote system, you can select the function from the search help provided with the Function Name field in PaPM)
Input Tab –
Select the Allocation Function whose results need to be posted in SAP S/4HANA as Input Function.
In Rules Tab –
Unlike other RFA types Rules tab in External Function Type does not contain mapping of the fields. Here there are 2 section provided, Template and Statement.
Template will give you construct of the remote function as catering to Input function provided in Input Tab. Note here, the function is Importing IS_AL and IT_DATA as importing parameters. IT_DATA is table of type DDIC objected created for Allocation Function (ZSNDM), containing fields from Allocation function in addition to some standard Technical Fields. Also, there is Changing section, where logs can be populated back to PaPM from SAP S/4HANA system. This is optional and can be included on need to need basis.
Statement will give source code of the FM created/available in SAP S/4HANA as selected in header. (At present we have not yet created FM in SAP S/4HANA, hence statement section is blank)
For a time being save the function, we will come back to this function activation once we complete the SAP S/4HANA steps.
Steps in SAP S/4HANA System:
Following steps need to be performed in SAP ERP or SAP S/4HANA system where remote function belongs to.
- Create table type of type DDIC table of Allocation Function. Use the DDIC table noted from previous steps for line type reference. Activate the table type.
2. Create Function Module ZFM_POST_ALLOCATION
Add Importing Parameter IS_AL and IT_DATA as per Template generated in Remote Function adapter. For IT_DATA select associated type as table type created in previous step. Refer below screenshot.
Add changing parameters as CT_MSG, to get the logs of the BAPI execution back to PaPM.
The source code section can be modified/coded for meeting different requirements. Some example including but not limited to:
- to call standard BAPI which is not provided out of box as RFA type in PaPM (this blog covering this)
- to call a process chain on remote SAP BW system for Data Transfer requirement
- Complex calculation coding which are not available as standard in PaPM
During Execution of Remote function Adapter function, the data from Allocation will be made available in this FM under IT_DATA. Which can be used for any of above development.
Sample Source Code Construct for calling Post Manual Allocation (BAPI_ACC_MANUAL_ALLOC_POST)
FUNCTION ZFM_POST_ALLOCATION. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(IS_AL) TYPE /NXI/TP1AL OPTIONAL *" VALUE(IT_DATA) TYPE ZTT_POST_ALLOCATION *" CHANGING *" VALUE(CT_MSG) TYPE /NXI/P1_TAB_ALMSG *"---------------------------------------------------------------------- * Data Declaration and Code to read it_data, * and map the fields to the BAPI's Import Paramaters as per Import, Export and tables CALL FUNCTION 'BAPI_ACC_MANUAL_ALLOC_POST' EXPORTING doc_header = ls_header IMPORTING doc_no = lv_docno TABLES doc_items = lt_items return = lt_return. * Code for Transaction commit as per need basis based on BAPI execution * Code to Populate return messages from BAPI execution to CT_MSG, so that logs can be taken back to PaPM for analysis ENDFUNCTION.
Once Source code is written as per requirement. Activate the Function Module. Do not forget to create this FM as Remote Enabled Module from Attributes tab.
Back to SAP PaPM System:
In the environment navigate to the RFA created earlier. Click on Edit and Activate the RFA function. Once activated you will notice, the statements section in the Rules tab which was blank earlier now populated with the Source Code we written in the SAP S/4HANA system Function Module.
Now our RFA is ready for execution run and post the output of Allocation Function to SAP S/4HANA. For executing select the RFA and click on Run. Based on the source code in the Function Module you will get the results of ct_msg table in the execution Logs.
Results for the Post Manual Cost Allocation BAPI
So this way , we have seen the configuration and development steps for Remote Function Adapter External Function type. This functionality can be utilized in multiple business requirement where other function types have challenges. With this set up now you should be able to create wrapper for any of standard BAPIs, any Remote Function call, calling SAP BW(or SAP BW/4HANA) Data Transfer Process Chains and running complex calculation in an ABAP environment.