Thursday 12 March 2020

How to create a Payroll Function in SAP HR

All companies have their own business processes, that must be reflected into the Payroll calculation. Or, one company may simply disagree on SAP’s logic, and would like to replace it with their own. To these scenarios, the best alternative is to create a Payroll Function and add it the Payroll Schema, so that it can be called and executed by the Payroll and “do the magic” as the guys from business required. Check below how to do it!

Declare the function


The first step is to access transaction PE04 and declare the name of our new function. This name must respect three rules:

1. It must start with either Z_ or Y_, to symbolize that it is under custom namespace
2. It must have at least 2 characters
3. It must have at max 5 characters

In my case, I decided to call my function Z_RLQ. Once it has ben set, hit ‘Create‘

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Exam Prep, SAP ABAP Prep

Set the function’s routine name and country validity


With the function already created, we must set a name to its form routine. By default the system already suggests a name, which will be FU<NAME> with the name of our function. It can be altered if desired.

Second, we must check all the countries that will be able to call this function. In my scenario, only Chile will be allowed to use it.

Once the function is finally activated, the include pcasfXX0 (XX being the country code) will be re-generated and the new form routine will be added to the indexed perform.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Exam Prep, SAP ABAP Prep

Create a custom include to store the function’s code


This is quite straight forward: access SE38, type in the name of your new include and hit ‘Create’. The only rule here is that the include must either begin with a ‘Z’ or a ‘Y’, which indicates that it is a custom object.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Exam Prep, SAP ABAP Prep

Implement a form routine with the logic needed


The idea is to use the include created above to hold one subroutine that encapsulates the new behavior that should be added. The subroutine’s name has already been defined in the second step, FUZ_RLQ.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Exam Prep, SAP ABAP Prep

This code will lower all the social security bases by some percentage, which is an internal requirement made by business. It is not defined by law nor is it invented by SAP, therefore, a perfect scenario to add a custom function.

Add the custom code to the Payroll driver


Now, we must include our new code into the payroll driver. It can be done by adding it to the include pcburzXX0, where XX standard for the country’s abbreviation convention. In this example, I am creating a new function to Chile, therefore the include should be pcburzCL0.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Exam Prep, SAP ABAP Prep

Add the custom function to the Payroll Schema


Access PE01 and type in the schema that will call the new function. Then, hit ‘Change’.

No alt text provided for this image

Now, find the line with the function you need to replace and type ‘*’ into de column ‘D’, or if there is no replace, only the addition of a new function, then type an ‘i’ in the last character of the column ‘line’.

Once you hit enter, a new line will appear in blank right below where we added the ‘i’. Then, just type in the name of the subroutine created before in PE04.

SAP ABAP Tutorial and Material, SAP ABAP Certification, SAP ABAP Learning, SAP ABAP Exam Prep, SAP ABAP Prep

Done!


With the configurations finished, all that there is left is to run the payroll with the new schema that calls the new function, and then check if the results are correct or if more code must be added to meet what the guys from business defined.

No comments:

Post a Comment