Create Determination – BOPF
As a pre-requisite, Go through the blog with title Custom BOPF Business Object
By the end of this blog, you will be able to..
- Understand the concept of Determination
- Create “Determination” on node
- Understand different patterns available while creating determination
A determination is an entity assigned to a node, which describes internal business logic that changes the business object. Like a database trigger, a determination is automatically executed by Business Object Processing Framework (BOPF) as soon as the trigger condition is fulfilled. This trigger condition is checked by BOPF at different points during the transaction, depending on the pattern of the determination. For each determination, it is necessary to specify the changes that form the trigger condition. Changes can include creating, updating, deleting, or loading node instances.
You can use a determination primarily to compute data that are derived from the values of other attributes. The determined attribute and the determining attributes of the trigger condition either belong to the same node or to different nodes. Furthermore, there are values that do not depend on other values but still must automatically be determined during the creation or modification of a node instance
Right click on the ROOT node to create determination..
Enter Determination name and description:
Implementation class will be proposed by the wizard:
Below section is very important..
- “Derive dependent data immediately after modification”
This pattern allows us to react to changes made to a given BO node. For example, we might use this event to go clean up some related data.
- “Derive dependent data before saving”
This pattern allows us to hang some custom logic on a given BO node before it is saved. This could be as simple as using a number range object to assign an ID value to a node attribute or as complex as triggering an interface.
- “Fill transient attributes of persistent nodes”
This pattern is often used in conjunction with UI development. Here, we might want to load labels and descriptive texts into a series of transient attributes to be displayed on the screen.
- “Derive instances of transient nodes”
This pattern allows us to load transient nodes into memory on demand. Here, for example, we might lookup real-time status data from a Web service and load it into the attributes of a transient node from downstream consumption.
- “Create Properties”
This pattern allows us to control the attributes (making fields Mandatory, Read only) of UI fields.
I will proceed with pattern 3 as Quote Status Text field is transient field of persistent node ROOT
Place below code in the class ZCL_RZ_D_FILL_QUOTE_STATUS_TXT, generated by the wizard
DATA : lt_data TYPE zrz_t_root, lr_data TYPE REF TO zrz_s_root, lt_change TYPE /bobf/t_frw_name. *--Retrive method will pull the data related to specific node CALL METHOD io_read->retrieve EXPORTING iv_node = zif_rz_sales_quote_c=>sc_node-root it_key = it_key iv_fill_data = abap_true IMPORTING eo_message = eo_message et_data = lt_data et_failed_key = et_failed_key. READ TABLE lt_data ASSIGNING FIELD-SYMBOL(<fs_data>) INDEX 1. IF <fs_data> IS ASSIGNED. CREATE DATA lr_data. IF <fs_data>-quote_status EQ 'N'. lr_data->quote_status_txt = 'New'. ELSEIF <fs_data>-quote_status EQ 'P'. lr_data->quote_status_txt = 'Published'. ENDIF. APPEND INITIAL LINE TO lt_change ASSIGNING FIELD-SYMBOL(<fs_change>). <fs_change> = zif_rz_sales_quote_c=>sc_node_attribute-root-quote_status_txt. *--Update method is used to modify data of the node CALL METHOD io_modify->update EXPORTING iv_node = zif_rz_sales_quote_c=>sc_node-root iv_key = <fs_data>-key is_data = lr_data it_changed_fields = lt_change. ENDIF.
Test the changes in BOBT, You can notice that status text got populate in the below screenshot.
As QUOTE_STATUS_TXT is editable, I will create another determination to control the properties of node attribute.
This time, I will select last option “Create Properties” to control the attributes (making fields Mandatory, Read only) of UI fields.
Place below code in EXECUTE method to make QUOTE_STATUS_TXT as Read only field.
READ TABLE it_key ASSIGNING FIELD-SYMBOL(<fs_key>) INDEX 1. IF <fs_key> IS ASSIGNED. CALL METHOD io_property->set_attribute_read_only EXPORTING iv_attribute_name = zif_rz_sales_quote_c=>sc_node_attribute-root-quote_status_txt iv_key = <fs_key>-key iv_value = abap_true. ENDIF.
When I tested the changes in BOBT, QUOTE_STATUS_TXT is non-editable.