Financial Management Blogs by Members
Dive into a treasure trove of SAP financial management wisdom shared by a vibrant community of bloggers. Submit a blog post of your own to share knowledge.
cancel
Showing results for 
Search instead for 
Did you mean: 
Amogh_Kulkarni
Explorer
1,909
Introduction :

SAP Profitability and Performance Management (PaPM) Remote Function Adapter offers you the capability to use powerful coding language like Python and JavaScript.

This blog will help you understand and configure how to make use of the Python function and code a simple logic to calculate the difference between two dates using a Python library in PaPM

Challenge :


I am sure that you must have faced this nagging question of how to calculate difference between two dates irrespective of the technology that you must be working on. To solve this, you have to first convert the date fields into date formats and then write logics to calculate the difference between the two dates.

In SAP Profitability and Performance Management (PaPM), i too faced this challenge, specially when my source data was in STRING format as compared to DATE format.

Solution :


As usual, I tried to overcome this challenge by using a CALCULATE function but for this, I had to first convert the STRING data type to DATE by using TO_DATE function.  Now this is a tried and tested methodology but I thought to myself why not try something different and that is when i was encouraged to look at the Python function type from the Remote Function Adapter family in SAP Profitability and Performance Management (PaPM).

  1. Create two date type fields 'Start Date' (STR_DATE) and 'End Date' (END_DATE' in your environment and create a Model Table called as 'Dates Data' with these fields and populate it with some date entries as shown below: -

  2. Created a field called as NUM_DAYS (Number of Days) in the environment.

  3. Created a Remote Function Adapter - Python - 'Date Difference' and linked it with the Model Table 'Dates Data' as shown below

  4. Now comes the interesting part :).

    1. In the Python function 'Date Difference' , select the Input and assign the source model table, in this case 'Dates Data' to link the model table with the python function as shown below

    2. In the 'Signature', select the

      1. 'Start Date' and 'End Date' fields (which are from your model table 'Dates Data' as part of 'Selection'

      2. 'Number of Days' field (which you created earlier in the environment (step 2)) as part of 'Actions



    3. Here is the PYTHON code that calculates the difference between the Start Date and the End Date and populates in the Number of Days field

    4. Save and Activate the Python Function 'Date Difference'


    5. Execute the Python function and see the results




As shown, the Python Code has executed and has populated the difference between the End Date and the Start Date in the 'Number of Days' field.

Conclusion :


We can use a simple PYTHON logic to calculate the difference between two dates using the Python - Remote Function Adapter.

References :


I would like to give credit for following references that helped in writing this blog


https://answers.sap.com/questions/13589848/ppm-cloud-remote-function-adapter.html

Summary :


To wrap up, I have shown how we can use ‘SAP Profitability and Performance Management (PaPM) Python – Remote Function Adapter’ function type to calculate differences between two dates

I thank you for reading through my second blog in SAP Profitability and Performance Management (PaPM).

Kindly requesting you to leave your feedback and comments.

I would encourage you to follow the topics in for more enlightenment on SAP Profitability and Performance Management (PaPM).

https://community.sap.com/topics/profitability-and-performance-management

Thanks

Amogh Kulkarni
7 Comments
akki0785
Participant
0 Kudos
Nice Blog on Python Function use case!!!.

 

Regards,

Akshay
Amogh_Kulkarni
Explorer
0 Kudos
Thanks Akshay
Fabrício
Participant
Awesome job amogh_kulkarni_1210 !!!

 

Quick question: Is it possible use PaPM cloud Python function to call RFC functions in S/4 HANA on premise?

 

Thanks.

Best,

Fabrício Souza
Amogh_Kulkarni
Explorer
0 Kudos
Hello Farbicio,

Greetings

Thanks for your comments

In PaPM Cloud, you do have RFA (remote function adapter) functions that help you call AP, AR, GL, SD and even Group Reporting data from S/4 HANA system which can be both on-premise or cloud edition. Basically the data is retrieved from ACDOCA and ACDOCU (for Group Reporting) tables

You dont need a RFA - Python function to call RFC functions from S/4 HANA system.

If there is a custom table or a different table that you need from S/4 HANA, you just need to provide authentication to the SCHEMA in which your table is created to SAP_PAPM_ADMIN user . Then, you can create virtual table on top of it in the HANA Cloud Database (using Database explorer) and retrieve the data using a DP Agent. This will still be a virtual table so you are not duplicating the data in the HANA Cloud DB in your SAP BTP.

Thanks

Amogh
Fabrício
Participant
0 Kudos
Hello amogh_kulkarni_1210,

First of all, thank you very much for the quick response 🙂

I had already seen these RFAs, but I am starting to imagine cases in which they are not sufficient and it is, for example, necessary to call other BAPIs or other processes inside S/4 HANA on premises version.

Can I say that these PaPM functions (Java and Python)  are for calculations and internal processes restricted to PaPM and shouldn't they also be used for integrations with other systems, such as calling a web service, for example?

Thanks.

Best,

Fabrício Souza

 
Amogh_Kulkarni
Explorer
Hello Fabricio,

Greetings

Ideally, these PaPM RFA Functions (Java and Python) are used in complex calculations OR to have a structure which can be re-used as an asset (the one like i did which can be used in any use-case for date difference with little change in the field naming convention based on the requirements).

However, these RFA functions can also be used for integrations for calling web services, i.e. to use them to call APIs.

Please refer to this blog. Although the blog below talks about triggering an event for CPI to capture the calculated results from PaPM where CPI uses “OData” API to read data from PaPM cloud and generate IDocs, i.e. this is for writing data back to ECC.

https://blogs.sap.com/2023/05/23/sap-profitability-and-performance-management-cloud-api-and-erp-inte...

I believe we can use RFA-Python to READ data, but, i would prefer CPI in between if it is non SAP source  that you want to read in PaPM Cloud as compared to directly using RFA - Python for integration

Thanks
Amogh
emanuele_fumeo
Product and Topic Expert
Product and Topic Expert

Hi colleagues,

as far as I understand, PaPM RFAs to SAP S/4HANA are built to post data rather than collecting data.

In order to collect data from RFCs, you can use SAP HANA Cloud's Smart Data Integration (SDI) capabilities via Data Provisioning Agent, which include data collection from RFCs / BAPIs: https://help.sap.com/docs/HANA_SMART_DATA_INTEGRATION/7952ef28a6914997abc01745fef1b607/c911a7b06cf14...

In addition, I suspect that it is not possible to use Python RFA to call RFCs, because currently it does not support PyRFC library nor importing new libraries: https://help.sap.com/docs/SAP_PROFITABILITY_PERFORMANCE_MANAGEMENT_CLOUD/56471df1959f4cfd9e3bf7a6d2d...

Nevertheless, it is correct to say that Python RFA can be used to collect data from external systems, for instance please refer to this blog post series related to PaPM Cloud integration with Snowflake:

Hope it helps.
Kind Regards,
Emanuele