Quantcast
Channel: Governance, Risk and Compliance (SAP GRC)
Viewing all articles
Browse latest Browse all 205

HR Triggers BRF Plus -> Decision Table with Company Code (BUKRS)?

$
0
0

Hello folks,

 

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.

 

IMPORT parameter:

import.PNG

 

EXPORT parameter:

export.PNG

 

 

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:

 

 

FUNCTION Z_HR_TRIGGER_GET_BUKRS.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IT_HR_DATA) TYPE  GRAC_T_HR_TRIGGER_BRFP
*"  EXPORTING
*"     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.





 
CLEAR lv_connector.

 
CLEAR lv_pernr.





 
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.



   
EXIT.



 
ENDLOOP.



 
IF lv_connector IS NOT INITIAL AND lv_pernr IS NOT INITIAL.



   
CLEAR lt_data.

   
CLEAR lv_options.

   
CLEAR lt_options.

   
CLEAR lt_fields.



    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.

   
WRITE: lv_options.



    lv_table
= 'PA0001'.



   
CALL FUNCTION 'RFC_READ_TABLE'

      DESTINATION lv_connector

     
EXPORTING

        query_table         
= lv_table

        rowcount            
= 1

     
TABLES

        options             
= lt_options

       
fields               = lt_fields

       
data                 = lt_data

     
EXCEPTIONS

        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.



   
CASE sy-subrc.

     
WHEN 0.

       
" fine, do nothing



     
WHEN 1.

       
"lv_msgno = '082'.



     
WHEN 2.

       
"lv_msgno = '083'.



     
WHEN 3.

       
"lv_msgno = '084'.



     
WHEN 5.

       
"lv_msgno = '085'.



     
WHEN 6.

       
"lv_msgno = '086'.



     
WHEN OTHERS.

       
"lv_msgno = '087'.



   
ENDCASE.



   
"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.

     
WRITE: lv_data.

   
ELSE.

     
CLEAR lv_data.

     
"WRITE: 'Error'.

   
ENDIF.



 
ENDIF.




ENDFUNCTION.

 

 

 

 

 

 

BRFPlus APPLICATION changes

 

 

 

 

 

Assuming your BRFPlus HR Triggers rule is created according to blog:

 

 

Creating your first HR Triggers BRFPlus - BASIC

 

 

we will make the below modifications:

 

 

1) Create two Data Elements. Type: TEXT, Length: 4

 

 

- BUKRS

- DT_BUKRS

 

w1.PNG

 

2) Add the newly created Element "DT_BUKRS" to the Function context:

 

w2.PNG

 

 

 

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.

 

 

w3.PNG

 

 

 

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".

 

 

w4.PNG

 

 

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).

 

 

w5.PNG

 

 

6) Open Decision Table, and add DT_BUKRS to the "Condition Columns"

 

 

w6.PNG

 

 

 

 

SIMULATE

 

 

 

 

 

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.

 

s1.PNG

 

 

2) My decision table has below conditions, for New Hire (0105 0001):

 

s2.PNG

 

 

3) Simulating the FUNCTION:

 

 

Click Start Simulation.

 

 

s3.PNG

 

 

 

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.

 

s31.PNG

 

 

 

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.

 

 

r1.PNG

r2.PNG

 

 

 

 

 

 

 

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


Viewing all articles
Browse latest Browse all 205

Trending Articles