HU打包BAPI:外部给号 更新交货单

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HU打包BAPI:外部给号 更新交货单相关的知识,希望对你有一定的参考价值。


下面开始干货:


相关链接

​HU相关配置​

​HU打包 内外部给号 前台操作​

​HU打包BAPI:内部给号 更新交货单​

参考代码:

 

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     VALUE(INB_VBELN) TYPE  VBELN

*"  TABLES

*"      ET_CREATED_HUS STRUCTURE  BAPIHUIDENTIFICATION OPTIONAL

*"      RETURN STRUCTURE  BAPIRET2

*"----------------------------------------------------------------------

  TYPE-POOLS: pdt.


  DATA: lv_vbeln        TYPE vbeln.


  DATA: lv_error        TYPE c,

        lw_return       TYPE bapiret2.


  DATA: lw_koko         TYPE vbkok,

        lw_kopo         TYPE vbpok,

        lt_prot         TYPE TABLE OF prott,

        lw_prott        TYPE prott,

        lt_kopo         TYPE TABLE OF vbpok,

        lt_vsek         TYPE TABLE OF verko,

        lt_vsep         TYPE TABLE OF verpo,

        lv_pupd         TYPE c.


  DATA: lw_goods        TYPE packgood,

        lt_goods        TYPE pdt_packgoods,

        lw_object       TYPE pdt_object,

        lv_profile      TYPE pdt_profile,

        lv_application  TYPE pdt_application.


  DATA: lt_packitems    TYPE pdt_packitems,

        lt_packqty      TYPE pdt_t_packqty,

        lx_hus          TYPE pdt_hus,

        lt_hu_messages  TYPE huitem_messages_t,

        lv_objectkey    TYPE pdt_objkey,

        lv_packresult   TYPE pdt_autopackresult.


  DATA: lw_likp         TYPE likp,

        lw_lips         TYPE lips,

        lt_lips         TYPE TABLE OF lips.


  DATA: lv_vpobjkey  TYPE vpobjkey,

        ls_huhdr_proposal TYPE huhdr_proposal,

        lw_huitm_prop     TYPE huitm_proposal.


  DATA: lw_vbkok    TYPE vbkok,

        lt_verpo    TYPE TABLE OF verpo,

        ls_verpo    TYPE verpo,

        lt_verko    TYPE TABLE OF verko,

        ls_verko    TYPE verko,

        lw_created_hus TYPE vekpvb,

        lt_created_hus TYPE TABLE OF vekpvb,

        lw_inb_hu   TYPE bapihuidentification.


  DATA:lv_index TYPE int4.

  DATA:lv_lines_gn TYPE int4.

  DATA:lv_lines_ko TYPE int4.

  DATA:lt_gdata TYPE TABLE OF ztshgn.

  DATA:ls_gdata TYPE ztshgn.

  FIELD-SYMBOLS <ls_ko> LIKE LINE OF lt_verko.

  FIELD-SYMBOLS <ls_po> LIKE LINE OF lt_verpo.

  DATA:lv_exidv TYPE exidv.


  FIELD-SYMBOLS <fs_items> TYPE huitm_proposal.


  IF inb_vbeln IS NOT INITIAL.


    CALL FUNCTION CONVERSION_EXIT_ALPHA_INPUT

      EXPORTING

        input  = inb_vbeln

      IMPORTING

        output = lv_vbeln.

*&------------------------------------------------------------------

*             Auto Packing

*&------------------------------------------------------------------

    REFRESH: lt_packitems, lt_goods, lt_packqty, lt_hu_messages.

    CLEAR: lv_packresult, lv_objectkey, lw_object,lx_hus.

    SELECT * INTO TABLE lt_lips FROM lips WHERE vbeln = lv_vbeln.

    IF sy-subrc <> 0.

      CLEAR: lw_return.

      lw_return-id = VL.

      lw_return-type = E.

      lw_return-number = 331.

      APPEND lw_return TO return.

      EXIT.

    ENDIF.

    LOOP AT lt_lips INTO lw_lips.

      CLEAR: lw_goods.

      lw_goods-matnr     = lw_lips-matnr.

      lw_goods-kunag     = lw_likp-kunag.

      lw_goods-kunwe     = lw_likp-kunnr.

      lw_goods-vkorg     = lw_likp-vkorg.

      lw_goods-vtweg     = lw_lips-vtweg.

      lw_goods-spart     = lw_lips-spart.

      lw_goods-kunnr     = lw_likp-kunnr.

      lw_goods-ablad     = lw_likp-ablad.

      lw_goods-abrvw     = lw_lips-abrvw.

      lw_goods-route     = lw_likp-route.

      lw_goods-vstel     = lw_likp-vstel.

      lw_goods-versart   = lw_likp-vsart.

      lw_goods-werks     = lw_lips-werks.

      lw_goods-lgort     = lw_lips-lgort.

      lw_goods-charg     = lw_lips-charg.

      SELECT SINGLE xchpf INTO lw_goods-xchpf

      FROM marc

      WHERE matnr = lw_goods-matnr

      AND werks = lw_goods-werks.

      IF lw_goods-xchpf = X.

*        IF lw_goods-charg IS INITIAL.

*          lw_goods-charg = 9999999999.

*        ENDIF.

      ENDIF.

      lw_goods-maxqua    = lw_lips-lfimg.

      lw_goods-qunit_a   = lw_lips-vrkme.

      APPEND lw_goods TO lt_goods.

    ENDLOOP.


    lw_object-objtype = 03.

    lw_object-objkey = inb_vbeln.

    lv_application = 1.

*   Assign packinstruction

    CALL FUNCTION VHUPILE_ASSIGN_PACKINSTRUCTION

      EXPORTING

        application         = lv_application

        object              = lw_object

        profile             = 0001

*       PDPARA              = PDPARA

        packgoods           = lt_goods

*       DIALOG_FLAG         = DIALOG_FLAG

      IMPORTING

        packitems           = lt_packitems

        t_packqty           = lt_packqty

        return_code         = lv_packresult

      EXCEPTIONS

        failure             = 1

        profile_not_found   = 2

        profile_wrong       = 3

        creation_failed     = 4

        no_packgood_found   = 5

        packinstr_deleted   = 6

        packinstr_not_found = 7

        OTHERS              = 8.

    IF sy-subrc <> 0.

      CLEAR lw_return.

      lw_return-id = sy-msgid.

      lw_return-type = sy-msgty.

      lw_return-number = sy-msgno.

      lw_return-message_v1 = sy-msgv1.

      lw_return-message_v2 = sy-msgv2.

      lw_return-message_v3 = sy-msgv3.

      lw_return-message_v4 = sy-msgv4.

      PERFORM frm_build_msgtext CHANGING lw_return.

      IF lw_return IS NOT INITIAL.

        APPEND lw_return TO return.

      ENDIF.

      EXIT.

    ENDIF.

**------------------------------------------

*       get proposals

**------------------------------------------

    CALL FUNCTION VHUPILE_CREATE_HU_PROPOSALS

      EXPORTING

        application         = lv_application

        object              = lw_object

        profile             = 0001

*       PDPARA              = PDPARA

        packitems           = lt_packitems

      IMPORTING

        s_mmdata            = lx_hus-s_mmdata

        t_hd_prp            = lx_hus-t_hd_prp

        t_hd_cap            = lx_hus-t_hd_cap

        t_hd_add            = lx_hus-t_hd_add

        t_hd_tra            = lx_hus-t_hd_tra

        t_items             = lx_hus-t_items

        t_srlnr             = lx_hus-t_srlnr

      EXCEPTIONS

        failure             = 1

        profile_not_found   = 2

        profile_wrong       = 3

        creation_failed     = 4

        no_packgood_found   = 5

        packinstr_deleted   = 6

        packinstr_not_found = 7

        OTHERS              = 8.

    IF sy-subrc <> 0.

      CLEAR lw_return.

      lw_return-id = sy-msgid.

      lw_return-type = sy-msgty.

      lw_return-number = sy-msgno.

      lw_return-message_v1 = sy-msgv1.

      lw_return-message_v2 = sy-msgv2.

      lw_return-message_v3 = sy-msgv3.

      lw_return-message_v4 = sy-msgv4.

      PERFORM frm_build_msgtext CHANGING lw_return.

      IF lw_return IS NOT INITIAL.

        APPEND lw_return TO return.

      ENDIF.

      EXIT.

    ENDIF.


*...To clear the memory before calling WS_UPDATE_DELIVERY..........

    CALL FUNCTION HU_PACKING_REFRESH.


*   General Header

    CLEAR: lw_vbkok.

    lw_vbkok-vbeln = lw_object-objkey.

    lw_vbkok-vbeln_vl = lw_object-objkey.

    lw_vbkok-vbtyp_vl = 7.   "Inbound Delivery


*   Items

    SORT lt_lips BY matnr.

    LOOP AT lx_hus-t_items ASSIGNING <fs_items>.

      READ TABLE lt_lips INTO lw_lips WITH KEY matnr = <fs_items>-matnr BINARY SEARCH.

      IF sy-subrc = 0.

        <fs_items>-belnr = lw_lips-vbeln.

        <fs_items>-posnr = lw_lips-posnr.

      ENDIF.

    ENDLOOP.

    REFRESH: lt_verpo.

    LOOP AT lx_hus-t_items[] INTO lw_huitm_prop.

      CLEAR: ls_verpo.

      MOVE lw_huitm_prop-matnr    TO ls_verpo-matnr.

      MOVE lw_huitm_prop-velin    TO ls_verpo-velin .

      MOVE lw_huitm_prop-exidv    TO ls_verpo-exidv_ob .

      MOVE lw_huitm_prop-lgort    TO ls_verpo-lgort.

      MOVE lw_huitm_prop-belnr    TO ls_verpo-rfbel.

      MOVE lw_huitm_prop-belnr    TO ls_verpo-vbeln.

      MOVE lw_huitm_prop-posnr    TO ls_verpo-rfpos.

      MOVE lw_huitm_prop-posnr    TO ls_verpo-posnr .

      MOVE lw_huitm_prop-quantity TO ls_verpo-tmeng.

      MOVE lw_huitm_prop-werks    TO ls_verpo-werks.

      MOVE lw_huitm_prop-charg    TO ls_verpo-charg.

      MOVE lw_huitm_prop-meins    TO ls_verpo-vrkme.

      APPEND ls_verpo TO lt_verpo.

    ENDLOOP.


*   Header

    REFRESH: lt_verko.

    LOOP AT lx_hus-t_hd_prp[] INTO ls_huhdr_proposal.

      CLEAR: ls_verko.

      MOVE-CORRESPONDING ls_huhdr_proposal TO  ls_verko.

      APPEND ls_verko TO lt_verko.

    ENDLOOP.

    REFRESH: lt_prot[], lt_created_hus[].

    CLEAR: lv_error.

*外部给号部分
*根据交货单号获取自建表中HU号省略

 LOOP AT lt_verko ASSIGNING <ls_ko>.


      lv_index = sy-tabix.

      READ TABLE lt_gdata INTO ls_gdata INDEX lv_index.


      <ls_ko>-exida = F.


      lv_exidv = <ls_ko>-exidv.


      READ TABLE lt_verpo ASSIGNING <ls_po> INDEX lv_index.

      IF sy-subrc = 0.
      -exidv = ls_gdata-exidv . "外部HU号内表
-exidv = ls_gdata-exidv . "外部HU号内表
        <ls_ko>-exidv_ob = ls_gdata-exidv . 
"外部HU号内表
      ENDIF.

    ENDLOOP.
* end

    CALL FUNCTION WS_DELIVERY_UPDATE
      EXPORTING
        vbkok_wa                     = lw_vbkok
        synchron                     = X
        commit                       = X
        delivery                     = lw_vbkok-vbeln
        nicht_sperren                = space
        if_no_generic_system_service = X
      TABLES
        verko_tab                    = lt_verko
        verpo_tab                    = lt_verpo
        prot                         = lt_prot
        et_created_hus               = lt_created_hus
      EXCEPTIONS
        communication_failure        = 1
        system_failure               = 2.
    IF sy-subrc <> 0.
      lv_error = X.
    ENDIF.

    IF lt_prot IS NOT INITIAL.
      LOOP AT lt_prot INTO lw_prott WHERE msgno IS NOT INITIAL.
      ENDLOOP.
      IF sy-subrc = 0.
        lv_error = X.
      ENDIF.
    ENDIF.

    IF lv_error = X.
      CLEAR lw_return.
      lw_return-id = sy-msgid.
      lw_return-type = sy-msgty.
      lw_return-number = sy-msgno.
      lw_return-message_v1 = sy-msgv1.
      lw_return-message_v2 = sy-msgv2.
      lw_return-message_v3 = sy-msgv3.
      lw_return-message_v4 = sy-msgv4.
      PERFORM frm_build_msgtext CHANGING lw_return.
      IF lw_return IS NOT INITIAL.
        APPEND lw_return TO return.
      ENDIF.
      ROLLBACK WORK.
      DELETE return[] WHERE type IS INITIAL.
      EXIT.
    ELSE.
      lw_return-type = S.
      lw_return-message = Success.
      APPEND lw_return TO return.
      COMMIT WORK AND WAIT.
      LOOP AT lt_created_hus INTO lw_created_hus.
        CLEAR: lw_inb_hu.
        lw_inb_hu-hu_id = lw_created_hus-venum.
        lw_inb_hu-hu_exid = lw_created_hus-exidv.
        APPEND lw_inb_hu TO et_created_hus.
      ENDLOOP.
    ENDIF.
  ENDIF.



ENDFUNCTION.

*&---------------------------------------------------------------------*
*&      Form  frm_build_msgtext
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->BAPIMSG    text
*----------------------------------------------------------------------*
FORM frm_build_msgtext CHANGING bapimsg TYPE bapiret2.

  CALL FUNCTION MESSAGE_TEXT_BUILD
    EXPORTING
      msgid               = bapimsg-id
      msgnr               = bapimsg-number
      msgv1               = bapimsg-message_v1
      msgv2               = bapimsg-message_v2
      msgv3               = bapimsg-message_v3
      msgv4               = bapimsg-message_v4
    IMPORTING
      message_text_output = bapimsg-message.

ENDFORM.                    "frm_build_msgtext



以上是关于HU打包BAPI:外部给号 更新交货单的主要内容,如果未能解决你的问题,请参考以下文章

交货单BAPI_OUTB_DELIVERY_CHANGE附加增强字段

◆◆0[BAPI]外向交货单按批次拆分[BAPI_OUTB_DELIVERY_CHANGE]

交货单批次拆分

SAP BAPI创建交货单拆单原因调查

SAP BAPI创建交货单拆单原因调查

SAP BAPI创建交货单拆单原因调查