ABAP EWM HU打包
Posted 想发财的小夏
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP EWM HU打包相关的知识,希望对你有一定的参考价值。
创建HU,分配DN并分配父HU
FUNCTION zewm_pack_hu.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(IV_LGNUM) TYPE /SCWM/LGNUM
*" REFERENCE(IV_VBELN) TYPE VBELN_VL
*" EXPORTING
*" REFERENCE(EV_SEVERITY) TYPE BAPI_MTYPE
*" REFERENCE(EV_MSG) TYPE BAPI_MSG
*" TABLES
*" IT_TABLE TYPE ZEWM_T_003
*"----------------------------------------------------------------------
TYPES: BEGIN OF ty_hu_guid,
huident TYPE zewmt001-huident,
guid_hu TYPE /scwm/guid_hu,
END OF ty_hu_guid.
DATA:lo_dlv_pack TYPE REF TO /scwm/cl_dlv_pack_ibdl,
ls_huhdr TYPE /scwm/s_huhdr_int,
lt_hu_guid TYPE TABLE OF ty_hu_guid,
ls_quan TYPE /scwm/s_quan,
ls_stock TYPE /scwm/s_pack_stock,
lv_id TYPE /scwm/de_matid,
lv_severity TYPE bapi_mtype,
lv_msg TYPE bapi_msg.
DEFINE set_msg.
ev_severity = &1.
ev_msg = &2.
END-OF-DEFINITION.
SELECT *
FROM /scdl/db_refdoc
INTO TABLE @DATA(lt_refdoc)
WHERE refdocno = @iv_vbeln " 根据交货单取值
AND refitemno <> ''
AND refdoccat = 'ERP'.
IF sy-subrc NE 0.
set_msg 'E' '未查询到交货单'.
EXIT.
ELSE.
SORT lt_refdoc BY refitemno.
READ TABLE lt_refdoc INTO DATA(ls_refdoc) INDEX 1.
ENDIF.
IF it_table[] IS INITIAL.
set_msg 'E' 'IT_TABLE必填'.
EXIT.
ENDIF.
/scwm/cl_tm=>cleanup( iv_lgnum = iv_lgnum ).
CREATE OBJECT lo_dlv_pack.
*----INIT
CALL METHOD lo_dlv_pack->init
EXPORTING
iv_lgnum = iv_lgnum
it_docid = VALUE /scwm/tt_docid( ( docid = ls_refdoc-docid ) )
iv_doccat = 'PDI'
iv_no_refresh = 'X'
iv_lock_dlv = 'X'.
/scwm/cl_dlv_pack_ibdl=>gv_online = 'X'.
CLEAR:lt_hu_guid,lv_severity,lv_msg.
" 创建父HU
LOOP AT it_table ASSIGNING FIELD-SYMBOL(<fs_table>) WHERE hu_dad NE ''
GROUP BY ( hu_dad = <fs_table>-hu_dad ). " 按照父HU分组
CLEAR:lv_id.
PERFORM frm_get_huid USING <fs_table>-hu_dad_typ CHANGING lv_id.
CLEAR:ls_huhdr.
CALL METHOD lo_dlv_pack->/scwm/if_pack_bas~create_hu
EXPORTING
iv_pmat = lv_id
iv_huident = <fs_table>-hu_dad
RECEIVING
es_huhdr = ls_huhdr
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc EQ 0 OR ( sy-msgno EQ '017' AND sy-msgid EQ '/SCWM/HU_WM' ).
"记录HU和GUID关系
APPEND INITIAL LINE TO lt_hu_guid ASSIGNING FIELD-SYMBOL(<fs_hu_guid>).
<fs_hu_guid>-guid_hu = ls_huhdr-guid_hu.
<fs_hu_guid>-huident = <fs_table>-hu_dad.
ELSE.
lv_severity = 'E'.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg.
LOOP AT GROUP <fs_table> ASSIGNING FIELD-SYMBOL(<fs_group>).
<fs_group>-mtype = 'E'.
<fs_group>-msg = |创建父HU报错: lv_msg |.
ENDLOOP.
ENDIF.
ENDLOOP.
SORT lt_hu_guid BY huident.
IF lv_severity NE 'E'.
" 创建子HU,并移入父HU下
LOOP AT it_table ASSIGNING <fs_table>.
CLEAR:lv_id,ls_refdoc.
PERFORM frm_get_huid USING <fs_table>-hu_typ CHANGING lv_id.
READ TABLE lt_refdoc INTO ls_refdoc WITH KEY refitemno = <fs_table>-posnr BINARY SEARCH.
IF sy-subrc NE 0.
<fs_table>-msg = '未查询到此交货单行数据,请检查'.
<fs_table>-mtype = 'E'.
CONTINUE.
ENDIF.
" 创建子HU
CLEAR:ls_huhdr.
CALL METHOD lo_dlv_pack->/scwm/if_pack_bas~create_hu
EXPORTING
iv_pmat = lv_id
iv_huident = <fs_table>-huident
RECEIVING
es_huhdr = ls_huhdr
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc EQ 0 OR ( sy-msgno EQ '017' AND sy-msgid EQ '/SCWM/HU_WM' )..
ls_stock-qdocid = ls_refdoc-docid.
ls_stock-qitmid = ls_refdoc-itemid.
ls_quan-unit = <fs_table>-unit.
ls_quan-quan = <fs_table>-quan.
"将库存移入HU中
CALL METHOD lo_dlv_pack->/scwm/if_pack_bas~pack_stock
EXPORTING
iv_dest_hu = ls_huhdr-guid_hu
is_material = ls_stock
is_quantity = ls_quan
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
lv_severity = 'E'.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg.
<fs_table>-msg = |物料移入HU报错: lv_msg |.
<fs_table>-mtype = 'E'.
ELSE.
IF <fs_table>-hu_dad IS NOT INITIAL.
READ TABLE lt_hu_guid INTO DATA(ls_hu_guid) WITH KEY huident = <fs_table>-hu_dad BINARY SEARCH.
IF sy-subrc = 0.
" 子HU移入父HU
CALL METHOD lo_dlv_pack->pack_hu
EXPORTING
iv_source_hu = ls_huhdr-guid_hu
iv_dest_hu = ls_hu_guid-guid_hu
EXCEPTIONS
OTHERS = 2.
IF sy-subrc <> 0.
lv_severity = 'E'.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg.
<fs_table>-msg = |子HU移入父HU报错: lv_msg |.
<fs_table>-mtype = 'E'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ELSE.
lv_severity = 'E'.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg.
<fs_table>-msg = |创建子HU报错: lv_msg |.
<fs_table>-mtype = 'E'.
ENDIF.
ENDLOOP.
ENDIF.
IF lv_severity NE 'E'.
" 保存HU
CALL METHOD lo_dlv_pack->/scwm/if_pack_bas~save
EXPORTING
iv_commit = 'X'
iv_wait = 'X'
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msg.
lv_msg = |打包失败: lv_msg |.
set_msg 'E' lv_msg.
ELSE.
set_msg 'S' '打包成功'.
ENDIF.
ELSE.
set_msg 'E' '打包失败,请检查行项目明细错误'.
ENDIF.
/scwm/cl_tm=>cleanup( iv_lgnum = iv_lgnum ).
ENDFUNCTION.
FORM frm_get_huid USING lv_type
CHANGING lv_id TYPE /scwm/de_matid.
DATA:lv_hu TYPE /scwm/de_matnr.
lv_hu = lv_type.
CALL FUNCTION 'CONVERSION_EXIT_MDLPD_INPUT'
EXPORTING
input = lv_hu
IMPORTING
output = lv_id.
ENDFORM.
以上是关于ABAP EWM HU打包的主要内容,如果未能解决你的问题,请参考以下文章