You may have the requirement in your company, that you only want to create new hires/terminations from HR Triggers for users that belong to a certain Company Code (BUKRS).
How can you do that?
My suggestion is to create a Procedure Call that executes a function module to get the user BUKRS. Then you add BUKRS to the condition columns of your Decision Table, and it is done!
Okay, you will ask me.. why not use a DBLookup instead of a Procedure Call? Answer is, BUKRS field is stored in HR System table PA0001. If I was wanting to retrieve field value from any table sititng in the GRC Foundation system itself, I could have used a DBLookup – no problem. But the table I need to access is on another system, the HR System. Therefore, by using a Function Module tied to a BRF+ Procedure Call expression, I can make use of SAP Standard Function Module RFC_READ_TABLE to complete this task.
Below are the steps suggested to achieve it.
CREATE a FUNCTION MODULE in the GRC FOUNDATION system
Code for the Function Module:
NOTE: this code is a sample, and IS NOT standard application code. It is merely a suggestion on how to create the Z Function Module in order to get Company Code (BUKRS) for the PERNR user triggered by HR Triggers.
NOTE2: I made this sample in the most basic form, you will need to add treatment for Exceptions, etc.
My FM is called “Z_HR_TRIGGER_GET_BUKRS”, and you may call it whatever you like.
Also you may use it for any other HR info type information that you would want to add to your Decision Table. In this scenario, the data I want is BUKRS, but you may want to use WERKS, Personnel Area, etc. As long as the data is stored in a HR Table related to the employee PERNR number, you can map it following this blog.
The suggested code is:
*” VALUE(IT_HR_DATA) TYPE GRAC_T_HR_TRIGGER_BRFP
*” VALUE(ET_BUKRS) TYPE BUKRS
DATA: lv_pernr TYPE string,
ls_hr_data TYPE GRAC_S_HR_TRIGGER_BRFP,
lv_connector TYPE GRFN_CONNECTORID.
DATA: lv_data TYPE string,
lt_data TYPE STANDARD TABLE OF tab512,
lv_table TYPE TABNAME,
lv_fields TYPE string,
lt_fields TYPE STANDARD TABLE OF rfc_db_fld,
lv_options TYPE string,
lt_options TYPE STANDARD TABLE OF rfc_db_opt.
FIELD-SYMBOLS <fs_hr_data> LIKE LINE OF it_hr_data.
FIELD-SYMBOLS <fs_lt_data> LIKE LINE OF lt_data.
LOOP AT it_hr_data INTO ls_hr_data WHERE field_name = ‘PERNR’.
lv_connector = ls_hr_data–CONNECTOR.
lv_pernr = ls_hr_data–NEW_FIELD_VALUE.
IF lv_connector IS NOT INITIAL AND lv_pernr IS NOT INITIAL.
lv_fields = ‘BUKRS’.
APPEND lv_fields TO lt_fields.
CONCATENATE ‘PERNR EQ’ lv_pernr ‘AND ENDDA GE “‘ sy–datum ‘”‘ INTO lv_options SEPARATED BY ‘ ‘.
REPLACE ALL OCCURENCES OF ‘”‘ IN lv_options WITH ””.
APPEND lv_options TO lt_options.
lv_table = ‘PA0001’.
CALL FUNCTION ‘RFC_READ_TABLE’
query_table = lv_table
rowcount = 1
options = lt_options
fields = lt_fields
data = lt_data
table_not_available = 1
table_without_data = 2
option_not_valid = 3
field_not_valid = 4
not_authorized = 5
data_buffer_exceeded = 6
OTHERS = 7.
” fine, do nothing
“lv_msgno = ‘082’.
“lv_msgno = ‘083’.
“lv_msgno = ‘084’.
“lv_msgno = ‘085’.
“lv_msgno = ‘086’.
“lv_msgno = ‘087’.
“Only one line must be in lt_data, only one Active BUKRS per PERNR is expected in PA0001.
IF lines( lt_data ) = 1.
READ TABLE lt_data ASSIGNING <fs_lt_data> INDEX 1.
lv_data = <fs_lt_data>.
MOVE lv_data TO et_bukrs.
BRFPlus APPLICATION changes
Assuming your BRFPlus HR Triggers rule is created according to blog:
we will make the below modifications:
1) Create two Data Elements. Type: TEXT, Length: 4
2) Add the newly created Element “DT_BUKRS” to the Function context:
3) Create an Expression of type “Procedure Call”, I am calling it “GET_BUKRS”.
In my sample, I have created a Function Module in the GRC Foundation system, called Z_HR_TRIGGER_GET_BUKRS.
Below I mapped the FM parameters for Import and Export.
4) Create an Expression of type “Formula”. I called it “FORMULA”.
Assign “Result Data Object” to Element “DT_BUKRS”.
To add the GET_BUKRS to the formula, right-click anywhere in the formula area (white box), choose “Insert Expression” and select the existing “GET_BUKRS”.
5) Now go to Rule 1 (if you have named them differently, go to the Rule that has the LOOP.
Add below expression and make it the first expression (1).
6) Open Decision Table, and add DT_BUKRS to the “Condition Columns”
Lets simulate the scenario.
1) In my test HR system called GH7CLNT600, I have PERNR 3, with BUKRS “US01”.
Note that there are two rows for the PERNR 3, the Function Module must take the valid entry, and ignore the expired entries.
2) My decision table has below conditions, for New Hire (0105 0001):
3) Simulating the FUNCTION:
Click Start Simulation.
I have entered two lines in my simulation.
The first line is to match the New Hire condition.
The second entry always comes within HR Trigger data from HR system, which is the PERNR number.
If PERNR is not coming, it will fail. In real scenario, it will always come along with the changed info types.
What must happen: in Rule 1, the BUKRS will be collected for the PERNR 3, and my New HIre condition will meet only if all columns are matched, including DT_BUKRS.
Other HR Trigger documents and on WIKIS
Debugging HR Trigger – GRAC_HR_TRIGGER_EVENT_RECIEVER
Debugging HR Trigger – PA40 changes to infotypes
Debugging HR Trigger – Simulation