0% found this document useful (0 votes)
49 views10 pages

BRF+ Object Creation Using ABAP Z-Report

Uploaded by

Jaya Sankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views10 pages

BRF+ Object Creation Using ABAP Z-Report

Uploaded by

Jaya Sankar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 10

Introduction

When working with SAP BRF+ (Business Rule Framework Plus), Elements are the most basic building
blocks. They represent data fields such as numbers, text, or dates, and act as reusable components for
structures, tables, functions, and rules. Without elements, we cannot define or process rules effectively
in BRF+.

In this blog, we will learn how to create BRF+ Elements programmatically using ABAP. This provides a
scalable way to automate the creation of data objects and integrate them into larger rule frameworks.

Why Elements?

Describes data types of the variable. They are the data carriers helping in signature or context of a
function, variables in a rule or rulesets, building blocks for Decision tables, Etc. You can create data
objects by defining attributes like element type, length, decimals or you can directly bind to existing DDIC
elements.

Reusability: Once created, elements can be used in multiple structures and rules.

Flexibility: Programmatic creation ensures consistency across environments.

ABAP Program to Create Elements

Below is a sample ABAP program (ZDEMO_BRF_APP) that:

Creates a BRF+ Application.

Defines three Elements (ELEMENT_1, ELEMENT_2, and CARRID).

*&---------------------------------------------------------------------*
*& Report ZDEMO_BRF_APP

*&---------------------------------------------------------------------*

*&

*&---------------------------------------------------------------------*

REPORT zdemo_brf_app.

DATA: lo_factory TYPE REF TO if_fdt_factory,

lo_application TYPE REF TO if_fdt_application,

lt_message TYPE if_fdt_types=>t_message,

lv_message TYPE string,

lv_boolean TYPE abap_bool,

lv_demo_appl_id TYPE if_fdt_types=>id,

lv_string TYPE string,

lo_element_1 TYPE REF TO if_fdt_element,

lo_element_2 TYPE REF TO if_fdt_element,

lo_element_3 TYPE REF TO if_fdt_element,

lo_table TYPE REF TO if_fdt_table,

lo_table_1 TYPE REF TO if_fdt_table,

lo_structure TYPE REF TO if_fdt_structure,

lv_element1_id TYPE if_fdt_types=>id,

lv_element2_id TYPE if_fdt_types=>id,

lv_element3_id TYPE if_fdt_types=>id,

lv_input_number_id TYPE if_fdt_types=>id,

lv_result_counter_id TYPE if_fdt_types=>id,


FIELD-SYMBOLS:

<ls_message> TYPE if_fdt_types=>s_message,

<lv_value> TYPE any.

PARAMETERS: pv_lcl TYPE abap_bool RADIOBUTTON GROUP r00 DEFAULT 'X',

pv_sys TYPE abap_bool RADIOBUTTON GROUP r00,

pv_mstr TYPE abap_bool RADIOBUTTON GROUP r00,

pv_name TYPE char30.

* p_ele_01 TYPE i DEFAULT 5,

* p_ele_02 TYPE i DEFAULT 4,

* p_ele_03 TYPE i DEFAULT 8,

* p_ele_04 TYPE i DEFAULT 3,

* p_ele_05 TYPE i DEFAULT 13,

* p_ele_06 TYPE i DEFAULT 2.

* pv_ele TYPE char20,

* pv_str TYPE char20,

* pv_tab TYPE char20.

IF pv_name IS NOT INITIAL AND pv_lcl IS NOT INITIAL OR pv_sys IS NOT INITIAL OR pv_mstr IS NOT
INITIAL.

* get a reference to the instance of the factory

lo_factory = cl_fdt_factory=>if_fdt_factory~get_instance( ).
* =============================================================

* definition of the new application:

* get an initial application object from the factory

lo_application = lo_factory->get_application( ).

lo_application->if_fdt_transaction~enqueue( ).

* set values for the application, especially the name is important

* You need to have a unique name for each application, here we use the

* FDT Service class method to get the unique name.

lo_application->set_application_component( 'BC' ). "#EC NOTEXT

lo_application->set_software_component( 'SAP_BASIS' ). "#EC NOTEXT

lo_application->set_development_package( '$TMP' ). "#EC NOTEXT

*lo_application->if_fdt_admin_data~set_name( cl_fdt_services=>get_unique_name( ) ).

lo_application->if_fdt_admin_data~set_name( pv_name ).

* In FDT terms there are 3 different type of Applications, Local application,

* system pplication and MasterData Application. The following lines shows how you

* can create local Application, masterdata Application and system Application.

IF pv_lcl EQ abap_true.

lo_application->create_local_application( ).

ELSEIF pv_sys EQ abap_true.

lo_application->create_system_application( ).

ELSEIF pv_mstr EQ abap_true.

lo_application->create_masterdata_application( ).

ENDIF.
lo_application->if_fdt_transaction~activate(

IMPORTING et_message = lt_message

ev_activation_failed = lv_boolean ).

IF lv_boolean EQ abap_true.

* for some reason the activation failed -> individual handling needed

lo_application->if_fdt_transaction~dequeue( ).

ELSE.

lo_application->if_fdt_transaction~save( ).

lo_application->if_fdt_transaction~dequeue( ).

* usually it makes sense to store the id for later access to the application

lv_demo_appl_id = lo_application->mv_id.

ENDIF.

WRITE: 'The ID of the application created is: ', lv_demo_appl_id. "#EC NOTEXT

ELSE.

MESSAGE 'Provide all the required information' TYPE 'E'.

ENDIF.

*for creating Element,Structure,Table by Data Object

lo_factory = cl_fdt_factory=>if_fdt_factory~get_instance( lv_demo_appl_id ).

* if_fdt_constants=>gc_application_tmp ).

* Note, that you are not required to use an application as input; however,

* we recommend to do so and work with a specific application instead of

* the generic local FDT applications.

*------------Element
lo_element_1 ?= lo_factory->get_data_object(

iv_data_object_type = if_fdt_constants=>gc_data_object_type_element ).

lo_element_1->if_fdt_transaction~enqueue( ).

lo_element_1->if_fdt_admin_data~set_name( 'ELEMENT_1' ).

* set the element-type (see if_fdt_constants=>gc_element_type_* for

* a list of available element types)

lo_element_1->set_element_type( if_fdt_constants=>gc_element_type_number ).

******************************************************************************

* Alternately user can create an element using the service clas method

* CL_FDT_CONVENIENCE=>CREATE_ELEMENT as follows.

* cl_fdt_convenience=>create_element( EXPORTING iv_name = 'DEMO_ELEMENT_1'

* iv_application_id = if_fdt_constants=>gc_application_tmp

* iv_element_type = if_fdt_constants=>gc_element_type_number

* iv_activate = ABAP_false

* IMPORTING

* eo_element = lo_element ).

*******************************************************************************

* Set some attributes for the element.

lo_element_1->set_element_type_attributes(

EXPORTING

iv_length =6

iv_decimals =2
iv_only_positive = abap_false ).

lo_element_1->if_fdt_transaction~activate(

IMPORTING

et_message = lt_message

ev_activation_failed = lv_boolean ).

IF lv_boolean EQ abap_true.

* for some reason the activation failed -> individual handling needed

lo_element_1->if_fdt_transaction~dequeue( ).

ELSE.

lo_element_1->if_fdt_transaction~save( ).

lo_element_1->if_fdt_transaction~dequeue( ).

* usually it makes sense to store the id for later access

lv_element1_id = lo_element_1->mv_id.

ls_element-position = 1.

ls_element-element_id = lv_element1_id.

APPEND ls_element TO lts_element.

ENDIF.

* Create another element

lo_element_2 ?= lo_factory->get_data_object(

iv_data_object_type = if_fdt_constants=>gc_data_object_type_element ).

lo_element_2->if_fdt_transaction~enqueue( ).

lo_element_2->if_fdt_admin_data~set_name( 'ELEMENT_2' ).
* set the element-type (see if_fdt_constants=>gc_element_type_* for

* a list of available element types)

lo_element_2->set_element_type( if_fdt_constants=>gc_element_type_number ).

lo_element_2->if_fdt_transaction~activate(

IMPORTING

et_message = lt_message

ev_activation_failed = lv_boolean ).

IF lv_boolean EQ abap_true.

* for some reason the activation failed -> individual handling needed

lo_element_2->if_fdt_transaction~dequeue( ).

ELSE.

lo_element_2->if_fdt_transaction~save( ).

lo_element_2->if_fdt_transaction~dequeue( ).

* usually it makes sense to store the id for later access to the application

lv_element2_id = lo_element_2->mv_id.

ls_element-position = 2.

ls_element-element_id = lv_element2_id.

APPEND ls_element TO lts_element.

ENDIF.

* create a third element


lo_element_3 ?= lo_factory->get_data_object(

iv_data_object_type = if_fdt_constants=>gc_data_object_type_element ).

lo_element_3->if_fdt_transaction~enqueue( ).

lo_element_3->if_fdt_admin_data~set_name( ' CARRID ' ).

lo_element_3->set_element_type( if_fdt_constants=>gc_element_type_number ).

lo_element_3->if_fdt_transaction~activate(

IMPORTING

et_message = lt_message

ev_activation_failed = lv_boolean ).

IF lv_boolean EQ abap_true.

* for some reason the activation failed -> individual handling needed

lo_element_3->if_fdt_transaction~dequeue( ).

ELSE.

lo_element_3->if_fdt_transaction~save( ).

lo_element_3->if_fdt_transaction~dequeue( ).

* usually it makes sense to store the id for later access to the application

lv_element3_id = lo_element_3->mv_id.

ls_element-position = 3.

ls_element-element_id = lv_element3_id.

APPEND ls_element TO lts_element.

ENDIF.

* WRITE: / lo_element->mv_id .

lv_string = lo_element_1->if_fdt_admin_data~to_string( iv_mode =


if_fdt_constants=>gc_tostring_mode_complete ).

WRITE : / 'The result of to string method call Element: ' , lv_string. "#EC NOTEXT
Execution & Output

When you execute the above ABAP report, the newly created Application and Elements will immediately
be reflected in the BRF+ Workbench (/nBRF+). You can navigate to the workbench to verify that the
application ZDEMO_APP and its elements have been created successfully.

Screenshot 2025-09-17 183254.pngScreenshot 2025-09-17 183237.pngScreenshot 2025-09-17


183157.pngScreenshot 2025-09-17 183106.png

After running the program, you will see system-generated IDs for each element created. These IDs are
crucial when referencing the elements in Structures, Rules, or Functions.

Conclusion

In the next part of this blog series, we will explore how to create Structures using these Elements.
Subsequent blogs will also cover Table, DB Lookup, Loop, Formula, Rule, and Function in detail.

You might also like