In this series of blogs, I am going to share about the use-case based implementations of Cloud BAdis in SAP S/4HANA Cloud.
For this purpose, I have taken those SAP S/4HANA Cloud BAdis which are popular among many of our Customers.
There would be 3 major key learnings for you in this blog:
How to implement a BAdi?
How to consume CDS views in a BAdi?
How to write the business logic for Approver determination?
Timesheet Approver Determination BAdi:
Default functionality of Timesheet Approval:
We are aware that, the Timesheet Approver for CPM Projects is the Project Manager by default.
But there are 2 cases in which a Project Manager gets his/her own time sheet for approval (self-approval) in the standard case:
1- When a Project Manager is also one of the Consultants contributing to the same project and submits his Timesheet for consulting efforts.
2- When Project Manager submits his own time sheet for billing of Project Management efforts.
Although this is an intended functionality, but it is given with the flexibility of customization i.e. we may define who would be the Approver.
Customization using BAdi:
Most of our Professional Services Customers want to customize this behavior by making one of the other project stakeholders as Approver when Project manager submits his Timesheet.
There can be many such scenarios where the Approver needs to be defined by Customers based on different criteria.
Let us look into the details of how we make Project Partner as the Approver of Project Manager’s Timesheet via Timesheet Approver Determination BAdi:
First, let’s implement the Timesheet Approver Determination BAdi and then we will test it.
Note: This BAdi gets called only when the approval scenario is enabled in the configuration app ‘Maintain Data Entry Profiles’ for Timesheet.
Step1: Go to Custom Fields and Logic App, navigate to custom logic tab and Create New Enhanced Implementation.
Step2: Select Business Context – ‘HCM- Timesheet Approver Determination', BAdi Description and give a name to your implementation.
Insert the below code snippet under logic:
IF timeentry-wbselement IS NOT INITIAL.
SELECT SINGLE \_engagementprojfinancialplan\_engagementproject-engagementproject
WHERE workpackage = @timeentry-wbselement
SELECT ProjectManager FROM I_EngagementProject
UP TO 1 ROWS
WHERE EngagementProject = @lv_eng_project.
IF timeentry-personworkagreement = lv_project_manager.
SELECT EMPLOYMENTINTERNALID FROM i_engagementprojectroles
UP TO 1 ROWS
WHERE EngagementProject = @lv_eng_project AND EngagementProjectRole = 'P004'.
approverperson = lv_project_partner.
Let’s understand what happens in above code:
- First, we identify the Engagement Project using the CDS view I_workpackage
- Then we identify the Project Manager of this Project using CDS view I_engagementproject
- When the project manager is the person assigned to work agreement, we determine the Project Partner of this Project using CDS view i_engagementprojectroles
- The Project Partner is then assigned as the Approver person
Step 4: Save the logic and Publish it.
Step 5: You should see a success message stating successful publishing of your BAdi.
In the second part, let us test this BAdi:
The below video showcases the behavior after implementation of BAdi and here are the key things to notice it:
Anjani Kumar Mishra is the Project Manager and Consultant who submits his Timesheet and it goes for approval to Project Partner as coded in our BAdi.
Akshay Kumar is Project Partner who gets the Timesheet for approval in his inbox and approves it.