Practical use of BRF+ Application to design rules ... - SAP Community
Practical use of BRF+ Application to design rules ... - SAP Community
- SAP Community
m
m
Products and Technology Groups Partners Topics Events What's New Get Star
u
ni
t
y
SAP Community Products and Technology Technology Technology Blogs by Members
Practical use of BRF+ Application to design rules ...
SAP Community will be read-only this weekend (Saturday, August 31, through
Sunday, September 1). Activities requiring log-in won't be possible. Learn more in
this What's New post.
prabhjotsingh14
Active Participant
05-09-2021 8:59 AM
9 Kudos 8,924
This is the continuation of the Part-1 in the series "Practical use of BRF+ Application
in SAP"
https://blogs.sap.com/2020/06/27/practical-use-of-brf-application-to-design-the-rules-
in-sap/#
In this blog, we will discuss about another practical example where We integrated
BRF+ and also used some more exciting features provided by BRF+ Framework. New
features in the expressions that we will cover are as follow:
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 1/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
1. Procedure Call
2. Loop
Apart from the above functions, we will also cover the topics and use of other
expressions :
1. Decision Tables
2. DB Lookup
3. Formulas
Business Requirements:
On Invoice output, there is a section to display Item details with various columns. In
Item description column, there are various rules which we would like to integrate into
a BRF+ application.
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 2/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
Before starting all the items, there would be a header section under description
column where header information for the invoice document can be displayed.
Rule 3: Exclude Contract Validity period on header for specific Invoice types.
Rule 1.1: Line 1 should display Product description from Item structure
Rule 1.2: Line 2 should display the ISBN code from Item structure. For special direct
sales materials, It should be sales product ID.
Rule 1.3: Line 3 should display preceding sales document no. and the Item no.
Rule 1.4: Line 4 should display the initial sales document No.
Rule 1.5: Line 5 should display Contract Validity period for the corresponding Item
no. when the contract period ( start date & end date ) for Item is different than
contract period of header.
Rule 1.6: Next lines should display License ID/ Amendment ID/ Manuscript ID for the
corresponding Item no. when the License ID/ Amendment ID/ Manuscript ID for Item is
different than header.
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 3/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
Technical Design:
From part-1 of this series, we explained all the basic implementation steps to create a
BRF+ application.If you need any guidance in that, please refer the blog:
https://blogs.sap.com/2020/06/27/practical-use-of-brf-application-to-design-the-rules-
in-sap/#
Function:
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 4/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
This function would be called from external applications by passing Invoice header
and Item data.
Rule Set:
Rule set would contain all the rules defined in the business requirement. Based on
that, we would start implementing rules for header first and then we would implement
rules for items.
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 5/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
settings.
Procedure:
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 6/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
1 FUNCTION zsd_output_format_date.
2 *"---------------------------------------------------------
3 -------------
4 *"*"Local Interface:
5 *" IMPORTING
6 *" REFERENCE(IV_CONTRACT_NO) TYPE VBELN_VAUF
7 *" REFERENCE(IV_COUNTRY_KEY) TYPE LAND1
8 *" REFERENCE(IV_ITEMNO) TYPE POSNR OPTIONAL
9 *" EXPORTING
10 *" REFERENCE(ES_FORMATTED_DATES) TYPE
11 *" ZST_SD_OUTPUT_FORMATTED_DATES
12 *"---------------------------------------------------------
13 -------------
14 *FM to format the contract validity dates
IF iv_itemno IS INITIAL.
15 SELECT SINGLE vbegdat, venddat FROM veda INTO
@DATA(ls_veda) WHERE vbeln = @iv_contract_no
16
17 AND vposn = '000000'.
ELSE.
18 SELECT SINGLE vbegdat, venddat FROM veda INTO @ls_veda
WHERE vbeln = @iv_contract_no
19
20 AND vposn = @iv_itemno.
21 ENDIF.
22
IF ls_veda-vbegdat IS NOT INITIAL AND ls_veda-venddat IS
23 NOT INITIAL.
24 es_formatted_dates-start_date =
zcl_fi_outputs_utility=>format_date( iv_land1 =
25 iv_country_key iv_date = ls_veda-vbegdat ).
26
27 es_formatted_dates-end_date =
zcl_fi_outputs_utility=>format_date( iv_land1 =
iv_country_key iv_date = ls_veda-venddat ).
ENDIF.
ENDFUNCTION.
Method FORMAT_DATE would convert the dates in the required format based on
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 7/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
country key:
1 METHOD format_date.
2
3 SET COUNTRY iv_land1.
4 rv_result = |{ iv_date DATE = ENVIRONMENT }|.
5
6 ENDMETHOD.
Function would be required to trigger the procedure call . Signature of function should
be same as signature of ABAP Function module so we need to create different data
objects in function signature as import parameters and result object.
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 8/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
We can select the call type of a procedure ( Static method, Function module, DB
Procedure ). In our case, we can select "Function Module" and provide the ABAP FM
name created in Step 1.
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 9/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
This step is important to link the ABAP Function module signature with BRF+ Function
which in turn calls the procedure
By following the above steps, we can create different procedure calls in the BRF+
application whenever we need to add some complex logic.
Now, back to the Rule 1 to derive the contract validity text, we have created a
decision table to configure the constant text in different languages
Decision Table:
Formula:
Now, we have created a Formula to concatenate the constant text from Decision table
DT_CONTRACT_VALIDITY_TEXT and validity dates from Procedure
PR_GET_FORMATTED_DATE
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 10/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
At the end, after creating all the necessary expressions ( Decision table, Procedure
call, Formula ), we are all set to create a rule
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 11/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
All the lines highlighted within red border are description text lines for Header section.
Sequence no. would indicate the priority of each line to be displayed first.
Lets find out how we composed the Item lines. We need to derive the description lines
for each item in the Invoice document. As an import parameter , we passed Item data
as IT_DOCUMENT_ITEMS in the main BRF+ function. Now, we would need to read
each Item data in a Loop within BRF+ application. For that, BRF+ provides additional
expression called Loop.
Loop:
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 12/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
Result Data Object -> In case of returning value, provide result data object
Since we are preparing a result internal table with Item No., Sequence no.and Text,
each rule will have 2 parts. In part 1, we will fill the work area of type result table and
in part 2, we will simply append the work area in target internal table and clear the
work area to be filled from scratch from subsequent rules.
Get the Product description for each line in import parameter IT_DOCUMENT_ITEMS-
ARKTX
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 13/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
Similarly all the different lines can be appended into result table.
To call this Loop, we will add an additional rule in main rule set after processing all the
rules for header. From this rule, we can provide the Item Data from Function import
parameter and get the result data object filled from the Loop expression.
Now, after we complete this BRF+ application with all the different rules for Header
and Items description, we can now integrate it as a function call in ABAP. We have our
custom data provider class for Invoice Output. In the CONSTRUCTOR method, we
can call the BRF+ application via its function and get the result table in a private
attribute to be used across the output data class:
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 14/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
METHOD _get_description_from_brf.
CONSTANTS:lc_function_id TYPE if_fdt_types=>id VALUE
'005056A5F0F91EEBA0DFD379B4AB5FE1'.
DATA:lv_timestamp TYPE timestamp,
lt_name_value TYPE abap_parmbind_tab,
ls_name_value TYPE abap_parmbind,
lr_data TYPE REF TO data,
lx_fdt TYPE REF TO cx_fdt,
ls_doc_header TYPE vbdkr,
lr_it_document_items TYPE REF TO data,
lr_vbkdr_line TYPE REF TO data,
lv_language TYPE
if_fdt_types=>element_text.
FIELD-SYMBOLS: <ls_any> TYPE any,
<lt_document_items> TYPE STANDARD TABLE.
**************************************************************
* All method calls within one processing cycle calling the
same function must use the same timestamp.
* For subsequent calls of the same function, we recommend
to use the same timestamp for all calls.
* This is to improve the system performance.
**************************************************************
* If you are using structures or tables without DDIC
binding, you have to declare the respective types
* by yourself. Insert the according data type at the
respective source code line.
**************************************************************
GET TIME STAMP FIELD lv_timestamp.
**************************************************************
* Process a function without recording trace data, passing
context data objects via a name/value table.
**************************************************************
* Prepare function processing:
**************************************************************
* Let BRFplus convert your data into the type BRFplus
requires:
* Data object is bound to a DDIC type, so you can improve
performance by passing a variable of that type.
* If you pass a variable of this type, you should indicate
this by passing "abap_true" for parameter
"iv_has_ddic_binding".
**************************************************************
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 15/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
ls_name_value-name = 'IS_DOC_HEADER'.
iv_function_id = lc_function_id
iv_data_object = '005056A5F0F91EDBA0DFDA48F5688028'
"IS_DOC_HEADER
iv_timestamp = lv_timestamp
iv_trace_generation = abap_false
iv_has_ddic_binding = abap_true
lr_data = lr_it_document_items.
cl_fdt_function_process=>move_data_to_data_object(
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 16/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
iv_function_id = lc_function_id
iv_data_object = '005056A5F0F91EDBA0DFE94C0CE5E031'
"IT_DOCUMENT_ITEMS
iv_timestamp = lv_timestamp
iv_trace_generation = abap_false
iv_has_ddic_binding = abap_false
iv_data_object = '_V_RESULT'
iv_timestamp = lv_timestamp
iv_trace_generation = abap_false
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 17/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
iv_function_id = lc_function_id
iv_timestamp = lv_timestamp
IMPORTING
ea_result = rt_result"<ls_any>
CHANGING
ct_name_value = lt_name_value ).
CATCH cx_fdt INTO lx_fdt.
**************************************************************
* You can check CX_FDT->MT_MESSAGE for error handling.
**************************************************************
ENDTRY.
ENDMETHOD.
2 Comments
former_member745078
Discoverer
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 18/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
05-09-2021 9:45 AM
1 Kudo
rpscg
Explorer
09-18-2023 11:43 AM
0 Kudos
Something that strikes me as odd about BRF+ is that there is no example of actual
integration to the application platform in any of the official help docs I've read.
There's definitely nothing along the lines of the code template. Even if that is a new
thing, there's nothing about how to reach the rule from ABAP if coding from scratch.
Or, as a no-code option, assume that a BRF+ application can be accessed as a sort of
plug-in without custom ABAP. How would that even be done?
All I see explained in Help docs is how to simulate. Am I just missing something that is
documented in an odd location?
Comment
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 19/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
ABAP 7.4 1 ABAP API 1 ABAP CDS VIEW 1 ABAP CDS Views 10
ABAP CDS Views - BW Extraction 3 ABAP CDS Views - CDC (Change Data Capture) 2
ABAP class 2 ABAP Cloud 4 ABAP DDIC CDS view 1 ABAP Development 7
ABAP String functions 1 abap technical 1 ABAP test cokpit 1 abap to xml 1
abapGit 1 absl 2 access data from SAP Datasphere directly from Snowflake 1
Archiving 1
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 20/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
Related Content
Optimizing Multithreaded Data Insertion into SAP Data Lake: Seeking Guidance
and Best Practices
in Technology Q&A 6 hours ago
How to Prevent Deletion of Input Controls in Webi Reports While Allowing Usage?
in Technology Q&A a week ago
former_member200339
Participant
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 21/22
8/28/24, 8:07 PM Practical use of BRF+ Application to design rules ... - SAP Community
Follow
1141417 75 333
Trademark Support
Cookie Preferences
https://community.sap.com/t5/technology-blogs-by-members/practical-use-of-brf-application-to-design-rules-part-2/ba-p/13519880 22/22