Uploaded by Siva Rama Krishna Gumudavelli

HR TRIGGER PROCEDURE CALL

advertisement
Building BRF+ Rule
using Procedure Call
I811193
5/12/2011
2
Table of Contents
Building BRF+ Rule using Procedure Call ..................3
 Create Class and method for the rule matching ..3
 Code for HR_TRIGGER method ............................5
 In BRF+ Create Procedure Call HR_TRIGGER .......7
3
Building BRF+ Rule using Procedure Call
The existing HRTrigger BRFPlus Ruleset creation document shows how to build a BRF+ rule
using Decision Table. However, a decision table is only used for one line rule matching. In case
of multiline rules, it is not sufficient.
This document illustrates how to build a more complex HRTrigger rule using Procedure Call
Expression. Although it is possible to build rules exclusively in BRF+ itself, but it’s usually over
complicated, and hard to debug. So we suggest using the Procedure Call expression provided
in BRF+ and build the more complicated rule matching logic externally in Functions or method..
This document uses the following New Hire rule as example to illustrate of doing the multiline
rule matching logic.
 Create Class and method for the rule matching



In se80, create class and its method.
Class: ZCL_HR_TRIGGER_ACTION
Method: HR_TRIGGER. Static public method
4


Importing: it_hr_data TYPE GRAC_T_HR_TRIGGER_BRFP
Exporting: et_action type GRAC_T_HR_ACTION_ID_BRFP
5
 Code for HR_TRIGGER method
method HR_TRIGGER.
data: ls_action type GRAC_S_HR_ACTION_ID_BRFP,
ls_hr_data type grac_s_hr_trigger_brfp.
data: lv_line1_match type grac_boolean,
lv_line2_match type grac_boolean,
lv_line3_match type grac_boolean.
"case 1, new account
loop at it_hr_data into ls_hr_data where connector = 'SERCLNT210' . "line 1 match
if ls_hr_data-PARENT_TYPE = '0000' and ls_hr_data-SUB_TYPE = '' and
ls_hr_data-FIELD_NAME = 'MASSN' and ls_hr_data-NEW_FIELD_VALUE = '01'.
lv_line1_match = abap_true.
exit.
endif.
endloop.
loop at it_hr_data into ls_hr_data where connector = 'SERCLNT210' . "line 2 match
if ls_hr_data-PARENT_TYPE = '0105' and ls_hr_data-SUB_TYPE = '0001' and
ls_hr_data-FIELD_NAME = 'USRID' and ls_hr_data-NEW_FIELD_VALUE <> ls_hr_dataOLD_FIELD_VALUE.
lv_line2_match = abap_true.
exit.
endif.
endloop.
loop at it_hr_data into ls_hr_data where connector = 'SERCLNT210' . "line 3 match
if ls_hr_data-PARENT_TYPE = '0001' and ls_hr_data-SUB_TYPE = '' and
ls_hr_data-FIELD_NAME = 'PLANS' and ls_hr_data-NEW_FIELD_VALUE <> ls_hr_dataOLD_FIELD_VALUE.
lv_line3_match = abap_true.
exit.
endif.
endloop.
if lv_line1_match = abap_true and lv_line2_match = abap_true and lv_line3_match = abap_true.
ls_action-action_id = '1'.
append ls_action to et_action.
return. " return once we find a match
endif.
" continue working on other cases.
lv_line1_match = abap_false.
lv_line2_match = abap_false. "reset matching variables.
lv_line3_match = abap_false.
"case 2, terminate account
loop at it_hr_data into ls_hr_data where connector = 'SERCLNT210' .
if ls_hr_data-PARENT_TYPE = '0000' and
6
ls_hr_data-FIELD_NAME = 'MASSN' and ls_hr_data-NEW_FIELD_VALUE = '20'.
lv_line1_match = abap_true.
exit.
endif.
endloop.
loop at it_hr_data into ls_hr_data where connector = 'SERCLNT210' .
if ls_hr_data-PARENT_TYPE = '0001' and
ls_hr_data-FIELD_NAME = 'PLANS' and ls_hr_data-NEW_FIELD_VALUE = '99999999'.
lv_line2_match = abap_true.
exit.
endif.
endloop.
if lv_line1_match = abap_true and lv_line2_match = abap_true.
ls_action-action_id = '2'.
append ls_action to et_action.
endif.
lv_line1_match = abap_false.
lv_line2_match = abap_false.
lv_line3_match = abap_false. " reset matching variables
" case 3, modify account
loop at it_hr_data into ls_hr_data where connector = 'SERCLNT210' .
if ls_hr_data-PARENT_TYPE = '0001' and
ls_hr_data-FIELD_NAME = 'PLANS' and ls_hr_data-NEW_FIELD_VALUE <> ls_hr_dataOLD_FIELD_VALUE
and ls_hr_data-NEW_FIELD_VALUE <> '99999999' and ls_hr_dataNEW_FIELD_VALUE is not initial.
lv_line1_match = abap_true.
exit.
endif.
endloop.
if lv_line1_match = abap_true.
ls_action-action_id = '2'.
append ls_action to et_action.
return. " return once we find a match
endif.
loop at it_hr_data into ls_hr_data where connector = 'SERCLNT210' .
if ls_hr_data-PARENT_TYPE = '0002' and
ls_hr_data-FIELD_NAME = 'NACHN' and ls_hr_data-NEW_FIELD_VALUE <> ls_hr_dataOLD_FIELD_VALUE
and ls_hr_data-NEW_FIELD_VALUE is not initial.
lv_line2_match = abap_true.
exit.
endif.
7
endloop.
if lv_line2_match = abap_true.
ls_action-action_id = '2'.
append ls_action to et_action.
return. " return once we find a match
endif.
endmethod.
 In BRF+ Create Procedure Call HR_TRIGGER
 Put in the class name which we just created and Save
8

Click on the HR_TRIGGER on the left menu and into Edit mode (this is important
to show the next menu )
9

The Method Name input field becomes editable.

Select the HR_TRIGGER in the F4 help.

Save and Click on the HR_TRIGGER on the left menu again and into Edit Mode.
This time you should see “Add Parameter” button
10

Select the HR table (input table) as the parameter
11

Click on the Show Details link to bring in the detail screen

Click on Assigned Value and Select Context Parameter
12


Choose HR_Trigger_table
Click on the Add Parameter again (to add the output parameter)



Select ET_ACTION table
Click on the “Show Details” – Assigned Value
Select “Table Type for Action ID”
13

Click on Result Data Object


Select Table type for Action ID
Save and Activate
14

Create A new Rule: HR_TRIGGER_RULE
15

Choose HR_TRIGGER procedure call
16

Create or Modify the Rule Set HRTRIGGER_RS
17

Insert Rule

Select HR_TRIGGER_RULE
Note: Make sure your Rule set is tied with the function and everything is
Activated . Then you can start to simulate to test the rules.
18
Download