SAP Help BOBF update individual object field









update individual object field using BOBF techniques




also see @@trigger-bopf-action


One of the benefits of BOPF functionality is that most functionality is already built and available, you just need to learn an entirly new ABAP skill set to
be able to access it:-). I guess the theory is lots of it can be configured in the front end but often you just want to create some code that updates a single field in an object and
because it is access via the NWBC you can't use BDC recording and you obviously can't update the database directly...well you could be you obvioiusly shouldn't :-)

This is when you need to start thinking a bit differently and embracing the Business object framework, and using the BOPF built in update functionality. See example below.

You can also add code within a enhancement determination to update fields during execution.



ABAP code to update BOPF field


Please see code below for how to update a specifc field directly, using the BOPF functionality

DATA lo_svc_mngr TYPE REF TO /bobf/if_tra_service_manager.
DATA lo_txn_mngr TYPE REF TO /bobf/if_tra_transaction_mgr.
FIELD-SYMBOLS: TYPE /scmtms/s_tor_item_tr_k.
DATA: lt_mod TYPE /bobf/t_frw_modification,
ls_mod TYPE /bobf/s_frw_modification,
lo_chg TYPE REF TO /bobf/if_tra_change,
lo_message TYPE REF TO /bobf/if_frw_message,
lv_rejected TYPE abap_bool,
lt_rej_bo_key TYPE /bobf/t_frw_key2.


CALL METHOD /bobf/cl_tra_serv_mgr_factory=>get_service_manager
EXPORTING
iv_bo_key = /scmtms/if_tor_c=>sc_bo_key " Business Object
* iv_create_sync_notifications = ABAP_FALSE " Switch on/off sync notifications
* iv_create_assoc_notifications = ABAP_FALSE " Switch on/off association change notifications
* iv_create_prop_notifications = ABAP_FALSE " Switch on/off property change notifications
RECEIVING
eo_service_manager = lo_svc_mngr. " Interface for (Proxy) Service Manager


*Auto complete is ctrl+space, select, tab, ctrl+space, select, tab
CALL METHOD /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager
RECEIVING
eo_transaction_manager = lo_txn_mngr. " Standalone Transaction Manager Instance

CLEAR: gd_save_chk.
LOOP AT it_report INTO wa_report WHERE upd_field EQ 'X'. LOOP AT lt_item ASSIGNING WHERE item_id = wa_report-item_id .

*---------------------------------------------------------------------------------*
REFRESH lt_mod.
CREATE DATA ls_mod-data TYPE /scmtms/s_tor_item_tr_k. ASSIGN ls_mod-data->* TO . -res_seq = -res_seq.
APPEND /scmtms/if_tor_c=>sc_node_attribute-item_tr-res_seq TO ls_mod-changed_fields.

"Update all fields " MOVE-CORRESPONDING to .

" ls_mod-node = /scmtms/if_tor_c=>sc_node-root. "item_tr.
ls_mod-node = /scmtms/if_tor_c=>sc_node-item_tr. ".
ls_mod-key = -key. "ITEM_PARENT_KEY. "key.
ls_mod-association = /scmtms/if_tor_c=>sc_association-root-item_tr.
ls_mod-change_mode = /bobf/if_frw_c=>sc_modify_update. ">sc_modify_update.
ls_mod-source_node = /scmtms/if_tor_c=>sc_node-root. "-item_tr. "ls_mod-source_key = -key. ls_mod-root_key = -root_key.

APPEND ls_mod TO lt_mod.

lo_svc_mngr->modify(
EXPORTING
it_modification = lt_mod
IMPORTING
eo_change = lo_chg
eo_message = lo_message ).

DATA: it_key TYPE /bobf/t_frw_key,
lv_key TYPE /bobf/s_frw_key.
lv_key-key = -key. "-root_key.
APPEND lv_key TO it_key.


** Call the SAVE method of the transaction manager
lo_txn_mngr->save(
IMPORTING
ev_rejected = lv_rejected
eo_change = lo_chg
eo_message = lo_message
et_rejecting_bo_key = lt_rej_bo_key
).
*
ENDLOOP.
ENDLOOP.