EWM时库内打包接口
进入之前需要清空仓库的全局缓存,不然执行第二条时接口会DUMP
代码如下:
FUNCTION zfm_repack_stock.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(GS_IN) TYPE ZEWMS_REPACK_STOCK OPTIONAL
*" EXPORTING
*" VALUE(O_RETURN) TYPE ZST_FM_EXPMSG
*"----------------------------------------------------------------------
DATA lv_hu TYPE zewmbarcode-huident.
DATA et_num TYPE STANDARD TABLE OF zscms006.
DATA it_num TYPE STANDARD TABLE OF zscms007.
DATA gt_lgpla TYPE rseloption.
* DATA gt_hu_result TYPE /scwm/tt_guid_hu.
* DATA gt_huhdr_sel TYPE /scwm/tt_huhdr_int.
DATA:et_huhdr TYPE /scwm/tt_huhdr_int .
DATA:et_huitm TYPE /scwm/tt_huitm_int .
DATA lv_source_hu TYPE /scwm/guid_hu.
DATA lv_guid_stock TYPE /lime/guid_stock.
DATA ls_quan TYPE /scwm/s_quan.
*获取条码号
it_num[] = VALUE #( ( pacty = '09' count = 1 ) ).
CALL FUNCTION 'ZFM_SRM_NUM'
TABLES
et_num = et_num
it_num = it_num.
lv_hu = et_num[ 1 ]-numbe.
lv_hu = |{ lv_hu ALPHA = IN }|.
DATA: iv_lgnum TYPE /scwm/lgnum.
DATA(lo_pack) = NEW /scwm/cl_wm_packing( ).
iv_lgnum = gs_in-lgnum .
/scwm/cl_tm=>cleanup( iv_lgnum = iv_lgnum )."仓库号清空必须加仓库号
*配置的固定参数 BOX
SELECT SINGLE scm_matid_guid16 FROM mara
WHERE matnr EQ 'BOX' INTO @DATA(lv_hu_id).
* 仓库初始化
CALL METHOD lo_pack->init
EXPORTING
iv_lgnum = gs_in-lgnum.
* 在线检查
/scwm/cl_dlv_pack_ibdl=>gv_online = 'X'.
SET UPDATE TASK LOCAL.
*创建HU
CALL METHOD lo_pack->/scwm/if_pack_bas~create_hu(
EXPORTING
iv_pmat = lv_hu_id ""HU
i_location = gs_in-lgpla
iv_huident = lv_hu
RECEIVING
es_huhdr = DATA(es_huhdr)
EXCEPTIONS
error = 1
OTHERS = 2 ).
IF sy-subrc EQ 0.
* 保存
lo_pack->/scwm/if_pack_bas~save( ).
lo_pack->/scwm/if_pack_bas~cleanup( ).
gt_lgpla = VALUE #( ( sign = 'I' option = 'EQ' low = gs_in-lgpla ) ).
* 获取仓位条码
CALL FUNCTION '/SCWM/HU_SELECT_GEN'
EXPORTING
iv_lgnum = gs_in-lgnum
iv_hierarchy = 'L'
ir_lgpla = gt_lgpla
IMPORTING
et_huhdr = et_huhdr[]
et_huitm = et_huitm[]
EXCEPTIONS
wrong_input = 1
not_possible = 2
OTHERS = 3.
RANGES r_guid FOR /scwm/quan-guid_parent.
DATA lv_matid TYPE /scwm/quan-guid_parent.
CALL FUNCTION 'CONVERSION_EXIT_MDLPD_INPUT'
EXPORTING
input = gs_in-matnr
IMPORTING
output = lv_matid.
* 获取批次ID
SELECT SINGLE * FROM mch1 WHERE charg = @gs_in-charg AND matnr = @gs_in-matnr INTO @DATA(v_wa_mch1).
r_guid[] = VALUE #( BASE r_guid[] FOR v_wa_hu IN et_huhdr
WHERE ( huident EQ gs_in-lgpla )
( sign = 'I' option = 'EQ' low = v_wa_hu-guid_hu ) ).
DELETE et_huitm WHERE guid_parent NOT IN r_guid .
READ TABLE et_huitm WITH KEY
matid = lv_matid
batchid = v_wa_mch1-batch_id
cat = gs_in-cat
stock_doccat = gs_in-stock_doccat
INTO DATA(ls_huitm).
IF sy-subrc = 0.
lv_source_hu = ls_huitm-guid_parent.
* lv_source_hu = es_huhdr-GUID_HU.
lv_guid_stock = ls_huitm-guid_stock..
ELSE.
o_return-zztype = 'E'.
o_return-zzmessage = |库存不存在!请检查数据!|.
CALL METHOD lo_pack->/scwm/if_pack_bas~delete_hu(
EXPORTING
iv_hu = es_huhdr-guid_hu
EXCEPTIONS
error = 1 ).
RETURN .
ENDIF.
ls_quan-unit = gs_in-unit.
ls_quan-quan = gs_in-quan.
CALL FUNCTION '/SCWM/TO_INIT_NEW'
EXPORTING
iv_lgnum = gs_in-lgnum.
SET UPDATE TASK LOCAL.
* 库存打包
CALL METHOD lo_pack->/scwm/if_pack_bas~repack_stock(
EXPORTING
iv_dest_hu = es_huhdr-guid_hu
iv_source_hu = lv_source_hu
iv_stock_guid = lv_guid_stock
is_quantity = ls_quan
EXCEPTIONS
error = 1 ).
IF sy-subrc = 0.
lo_pack->/scwm/if_pack_bas~save( ).
lo_pack->/scwm/if_pack_bas~cleanup( ).
o_return-zztype = 'S'.
o_return-zzmessage = |打包成功,条码号({ lv_hu ALPHA = OUT })| .
o_return-zvalue1 = lv_hu.
ELSE.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
INTO DATA(mtext)
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
o_return-zztype = 'E'.
IF lv_source_hu IS INITIAL .
o_return-zzmessage = |库存不足,请检查数据!|.
ELSE.
o_return-zzmessage = |打包失败,原因:{ mtext }|.
ENDIF.
o_return-zvalue1 = lv_hu.
CALL METHOD lo_pack->/scwm/if_pack_bas~delete_hu(
EXPORTING
iv_hu = es_huhdr-guid_hu
EXCEPTIONS
error = 1 ).
IF sy-subrc = 0.
lo_pack->/scwm/if_pack_bas~save( ).
lo_pack->/scwm/if_pack_bas~cleanup( ).
ENDIF.
RETURN.
ENDIF .
ELSE.
IF sy-msgid IS NOT INITIAL.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
INTO mtext
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
o_return-zztype = 'E'.
o_return-zzmessage = '创建HU失败,原因:' && mtext.
o_return-zvalue1 = lv_hu.
RETURN.
ENDIF .
ENDFUNCTION.