cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Create a FWO by BOPF code.

ronaldo_aparecido
Contributor
1,540

Hi guys i'm using /SCMTMS/CL_CPX_TPNRQ_REQ class to create a FWO by code ,

but to fill the parameters is very hard work.

I want to know if there is an other class more easily to do it.

Or other way.

Thanks.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member

Hi Ronaldo,

Keep it very simple, Create your own class or report for FWO creation and you can test with below code.

REPORT ztm_code.
DATA lt_trq_root     TYPE /scmtms/t_trq_root_k.
DATA lt_trq_item     TYPE /scmtms/t_trq_item_k.
DATA lr_trq_root     TYPE REF TO /scmtms/s_trq_root_k.
DATA lr_trq_item     TYPE REF TO /scmtms/s_trq_item_k.
DATA lt_modify       TYPE /bobf/t_frw_modification.
DATA ls_modify       TYPE /bobf/s_frw_modification.


* Get BO Service Manager - /SCMTMS/TRQ Business Object
DATA(lr_trq_srvmgr) = /bobf/cl_tra_serv_mgr_factory=>get_service_manager(
                                iv_bo_key = /scmtms/if_trq_c=>sc_bo_key ).


***************************** Create ***********************************
*&---> Create Root Node Instance


* Fill Root Data
CREATE DATA lr_trq_root.
lr_trq_root->key      = lr_trq_srvmgr->get_new_key( ).
lr_trq_root->trq_cat  = '03'. " Forwarding Order
lr_trq_root->trq_type = 'ZFWO'.
* Fill Other Attributes
*


* Fill Modification Structure
ls_modify-node        = /scmtms/if_trq_c=>sc_node-root.
ls_modify-change_mode = /bobf/if_frw_c=>sc_modify_create.
ls_modify-data        = lr_trq_root.
ls_modify-key         = lr_trq_root->key.
INSERT ls_modify INTO TABLE lt_modify.


*&---> Create Item Node Instance ( Subnode )
* Fill Item Data
CREATE DATA lr_trq_item.
lr_trq_item->key        = lr_trq_srvmgr->get_new_key( ).
lr_trq_item->item_cat   = 'PRD'. " Product
lr_trq_item->item_descr = 'demo'.
* Fill Other Attributes
*


* Fill Modification Structure
CLEAR ls_modify.
ls_modify-node        = /scmtms/if_trq_c=>sc_node-item.
ls_modify-change_mode = /bobf/if_frw_c=>sc_modify_create.
ls_modify-source_node = /scmtms/if_trq_c=>sc_node-root.
ls_modify-association = /scmtms/if_trq_c=>sc_association-root-item.
ls_modify-source_key  = lr_trq_root->key.
ls_modify-root_key    = lr_trq_root->root_key.
ls_modify-data        = lr_trq_item.
ls_modify-key         = lr_trq_item->key.
INSERT ls_modify INTO TABLE lt_modify.




* Modify
IF lt_modify IS NOT INITIAL.
  CALL METHOD lr_trq_srvmgr->modify
    EXPORTING
      it_modification = lt_modify    " Changes
    IMPORTING
      eo_change       = DATA(lo_change)    " Interface of Change Object
      eo_message      = DATA(lo_message).    " Interface of Message Object
ENDIF.


*Save
IF lo_change IS BOUND AND lo_change->has_failed_changes( ) EQ abap_false.
  DATA(lr_tra_mgr) = /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager( ).


  CALL METHOD lr_tra_mgr->save
    EXPORTING
      iv_transaction_pattern = /bobf/if_tra_c=>gc_tp_save_and_continue   
    IMPORTING
      ev_rejected            = DATA(lv_rejected)
      eo_change              = lo_change
      eo_message             = lo_message.
  lo_message->get_messages(
    IMPORTING
      et_message              = DATA(lt_message) ).
ENDIF.