BRF Plus- A real time example – 2
This is a continuation of my first blog BRF Plus-A real time example
In my last blog I shown you on how to create a BRF Plus application and how to simulate the same. Here we will see how we can send the result of the BRF Plus application as an email and how we can execute the same from CRM WebUI or from an ABAP reprot.
1) Creation of actions:
In the previous blog, we saw that the result of salary is put into the table called ‘Salary table’ after executing certain rules. Now if I want to send a mail with the result to a recipient, that can be achieved with actions.
Here in recipients list, we can give the value from context parameter. For instance you are evaluating something for a BP and the result is to be sent to the email ID of the BP. In that case you can create context parameter email and get the BP’s email id using a function and assign that email here in recipients.
In Subject, you can give the title and then can give the body of the mail. In order to bring the context parameters to the mail, you can give them like &1, &2, &3 etc. After giving the parameter names, press on ‘Refresh message palceholders’ button and then you will see the option to assign the values from &, &2 etc.
Here you can assign the values and send the mail. Save the action and activate it.
We are done with sending of mails. Now we have to assign the action to the function.
Go to the rule set where you have created all other rules.
Choose the action we have created. Now the bottom side of rule set will look like this.
Simulate the application and see the result.
Keep in mind that, in simulation mode the actions won’t get executed. You should have a COMMIT for actions to get executed.
Now let’s see how can we bring this BRF Plus application to a program/BADI/event handler etc.
The first thing to be got is the id of the function which you can get from the ‘General’ tab.
Now write the following code (I am considering the example of a report).
PARAMETERS:p_comp TYPE CHAR40, p_years TYPE char2. DATA: lo_fuction TYPE REF TO if_fdt_function, lo_context TYPE REF TO if_fdt_context, lo_result TYPE REF TO if_fdt_result, lt_salary TYPE zsalary_tt, lo_message TYPE REF TO cx_fdt. FIELD-SYMBOLS:<fs_salary> TYPE zsalary. START-OF-SELECTION. TRY . " Get BRFplus function lo_fuction ?= cl_fdt_factory=>if_fdt_factory~get_instance( )->get_function( '2C44FD80B9EC1ED4A9F31B316E69AE7A' ). " Set the BRFplus function context ( input variables ) lo_context = lo_fuction->get_process_context( ). lo_context->set_value( iv_name = 'COMPANY_NAME' ia_value = p_comp ). lo_context->set_value( iv_name = 'YEARS_OF_EXP' ia_value = p_years ). " Process the BRFplus function lo_fuction->process( EXPORTING io_context = lo_context IMPORTING eo_result = lo_result ). " Retrieve the BRFplus function result lo_result->get_value( IMPORTING ea_value = lt_salary ). CATCH cx_fdt INTO lo_message. ENDTRY. READ TABLE lt_salary ASSIGNING <fs_salary> INDEX 1. IF sy-subrc = 0. COMMIT WORK. WRITE: 'Your level is ', <fs_salary>-zlevel, 'And the salary you can get is ', <fs_Salary>-salary.
Everything is done now. Go and execute your report.
Please let me know if you have any queries.