在EWM中很少有创建或者修改业务对象的BAPI存在,更多的是通过很多面向对象的类方法来实现。
以下这个简单的创建TU应该能很好的体现SCM平台中的OO特性。
REPORT yewm_tu_creation NO STANDARD PAGE HEADING.
TYPES:
BEGIN OF lty_key_wrk,
tu_num TYPE /scwm/de_tu_num,
tu_sr_act_num TYPE /scwm/de_tu_sr_act_num,
END OF lty_key_wrk.
DATA:
lo_tu_sp TYPE REF TO /scwm/cl_ui_tu_sp,
lt_aspect TYPE /scwm/tt_asp_tu,
ls_aspect TYPE /scwm/s_asp_tu,
lt_aspect_o TYPE /scwm/tt_asp_tu,
lt_return_codes TYPE /scmb/t_sp_return_code,
lv_rejected TYPE char01,
lo_attr_hndl TYPE REF TO /scmb/cl_attribute_handler,
lo_msg_hndl TYPE REF TO /scmb/cl_message_handler,
ls_key_wrk TYPE lty_key_wrk,
lt_key_wrk TYPE TABLE OF lty_key_wrk.
START-OF-SELECTION.
"创建TU对象
CREATE OBJECT:
lo_attr_hndl,
lo_msg_hndl,
lo_tu_sp EXPORTING io_attribute_handler = lo_attr_hndl
io_message_handler = lo_msg_hndl.
ls_aspect-act_dir = "1" inbound / "2" outbound —Direction of Shipping and Receiving Activity
ls_aspect-start_act_d = sy-datum.
ls_aspect-start_act_t = sy-uzeit.
ls_aspect-end_act_d = sy-datum.
ls_aspect-end_act_t = '235959'.
ls_aspect-mtr = Means of Transport
ls_aspect-pmat = TU Packaging Material
APPEND ls_aspect TO lt_aspect.
CLEAR ls_aspect.
"通过INSERT方法来创建TU
lo_tu_sp->insert( EXPORTING inrecords = lt_aspect
aspect = '/SCWM/S_ASP_TU'
IMPORTING outrecords = lt_aspect_o
rejected = lv_rejected
return_codes = lt_return_codes ).
READ TABLE lt_return_codes TRANSPORTING NO FIELDS WITH KEY failed = abap_true.
IF sy-subrc = 0 OR lv_rejected = abap_true.
"ERROR
ELSE.
READ TABLE lt_aspect_o INTO ls_aspect INDEX 1.
IF sy-subrc = 0.
ls_key_wrk-tu_num = ls_aspect-tu_num.
ls_key_wrk-tu_sr_act_num = ls_aspect-tu_sr_act_num.
APPEND ls_key_wrk TO lt_key_wrk.
CLEAR: ls_key_wrk, ls_aspect.
ENDIF.
"保存并提交
lo_tu_sp->save( ).
COMMIT WORK AND WAIT.
ENDIF.
"激活TU对象
/scwm/cl_sr_bom=>cleanup( ).
TRY.
/scwm/cl_sr_my_service=>switch_tu_active(
EXPORTING
iv_lgnum = 仓库号
it_aspk_tu = lt_key_wrk
IMPORTING
ev_rejected = lv_rejected ).
IF lv_rejected = abap_true.
"ERROR
ELSE.
lo_tu_sp->save( ).
COMMIT WORK AND WAIT.
ENDIF.
CATCH /scwm/cx_sr_error.
ENDTRY.