Each action in BOPF must implement the execute method of the action interface /BOBF/IF_FRW_ACTION.
The listing below is used to implement the SET_TO_PAID action of the generated business object ZDEMO_I_SALESORDER_TX. A consumer can use this action to mark the status of the sales order as paid.
CLASS zcl_demo_a_set_to_paid DEFINITION PUBLIC INHERITING FROM /bobf/cl_lib_a_supercl_simple FINAL CREATE PUBLIC . PUBLIC SECTION. METHODS /bobf/if_frw_action~execute REDEFINITION . PROTECTED SECTION. PRIVATE SECTION. ENDCLASS. CLASS zcl_demo_a_set_to_paid IMPLEMENTATION. METHOD /bobf/if_frw_action~execute. " Typed with node's combined table type DATA(lt_sales_order) = VALUE ztdemo_i_salesorder_tx( ). " READING BO data ---------------------------------------------- " Retrieve the data of the requested node instance io_read->retrieve( EXPORTING iv_node = is_ctx-node_key it_key = it_key IMPORTING et_data = lt_sales_order ). " WRITING BO data --------------------------------------------- LOOP AT lt_sales_order ASSIGNING FIELD-SYMBOL(<s_sales_order>). " Set the attribue billing_status to new value <s_sales_order>-billingstatus = 'P'. " PAID " Set the attribue overall_status to new value IF <s_sales_order>-overallstatus = 'N' OR <s_sales_order>-overallstatus = ' '. <s_sales_order>-overallstatus = 'P'. " PAID ENDIF. " Update the changed data (billig_status) of the node instance io_modify->update( EXPORTING iv_node = is_ctx-node_key iv_key = <s_sales_order>-key iv_root_key = <s_sales_order>-root_key is_data = REF #( <s_sales_order>-node_data ) it_changed_fields = VALUE #( ( zif_demo_i_salesorder_tx_c=>sc_node_attribute-zdemo_i_salesorder_tx-billingstatus ) ( zif_demo_i_salesorder_tx_c=>sc_node_attribute-zdemo_i_salesorder_tx-overallstatus ) ) ). ENDLOOP. ENDMETHOD. ENDCLASS.
The SET_TO_PAID action is carried out by the execute method. As in most cases, the first step within the execute method is to retrieve relevant data of those node instances that are going to be changed. Remember, all attributes of the root node are represented by the combined structure’s component.
For reading BO data, a data reference lt_sales_order is used, where lt_sales_order refers to the combined table type ztdemo_i_salesorder_tx. It contains the keys and data of all node instances on which the action should be applied. This enables you to access the root node attribute billing_status and then set a new value P that indicates that the node instance is set to status PAID.
For each relevant node instance, the update method of the access object io_modify is called. Here the internal table it_changed_fields is populated with attributes that are going to be updated. Like all other entity names, the attribute names, too, are available through the Constants Interface ZIF_DEMO_I_SALESORDER_TX_C. As result of the method call, the node instance is updated in the database.