Extend SAP 'features' with ABAP code

One of the powerful tools for configuring SAP HR is features – structured decision logic that looks at various attributes of an employee. Features are used to determine all sorts of things in the SAP HR system – which wagetype to use in paying an employee, which benefit plans they are eligible for, which pay frequency to use and so on.

Sometimes we need more flexibility in a given feature than the system provides. Maybe the decision logic has more steps than the feature can handle (i.e. the variable key is too small to support all the decisions we need to make), or maybe we need to make a decision on an attribute that doesn't exist in the feature. We can extend the flexibility of features by calling ABAP code, which in turn is used to make whatever decision we need.

Before I go into the details for constructing the ABAP code and linking it to the feature, I have to point out one very important restriction: The ABAP code only has access to the data that was passed into the feature. Every feature has a structure assigned to it, a collection of data items that is sent to the feature for it to use in its decision. In turn, the ABAP code only has that data to work with.

Here's a shell of ABAP code you can start with:

REPORT ZHR_FEATURE_CODE.

FORM ext_call_f USING namen back status struc STRUCTURE structure-name.

* namen = feature name
* back = the value you want the feature to return
* status = return code: 0 = success, 2 = failure
* struc = the data that was passed into the feature
* structure-name = the data dictionary structure of 'struc'

IF struc-field1 = value1.
   back = 'RETURN1'.
  status = 0.
ELSEIF struc-field1 = value2.
  back = 'RETURN2'.
  status = 0.
ELSE.
* this is how we return an error condition
  status = 2.
ENDIF.

ENDFORM.

According to this code, if the value of struc-field1 is value1, then the feature returns a value of RETURN1. If the value of struc-field1 is neither value1 nor value2, then the feature returns a status of 2, which tells the system that the feature failed. The return of a failure is rarely done, but I included it here to make sure it was known as an option.

In the feature, call this ABAP code by specifying the program name:

&FEATURE-NAME(ZHR_FEATURE_CODE),

For example, if the feature was ABKRS, the line would be:

&ABKRS(ZHR_FEATURE_CODE),

So that's how you do it – pretty simple, actually. And powerful.

up
144 users have voted.

Add new comment

randomness