Delivery note posting: BAPI_OUTB_DELIVERY_CONFIRM_DEC, WS_DELIVERY_UPDATE

 

WS_DELIVERY_UPDATE 

You can fill in the posting date, etc.

 

BAPI_OUTB_DELIVERY_CONFIRM_DEC

The posting date cannot be transferred, and the field needs to be updated for reversal. There are specific enhancement methods behind

 

Take the posted material voucher

    select max( vbeln )

             into @data(lv_vbeln)

             from vbfa

             where vbelv   = @uv_vbeln

               and vbtyp_n = 'R'

               and rfmng   > 0.

 

DEMO1

form frm_dn_post using uv_vbeln.

  data:

       ls_vbkok_wa type vbkok.

 

  data:

    lv_er_any type c,

    lv_er_itm type c,

    lv_er_upd type c,

    lv_er_inf type c,

    lv_er_gss type c,

    lv_er_fch type c,

    lv_er_par type c,

    lv_er_ser type c,

    ls_return like bapireturn1.

  data:

    lv_wadat_ist like likp-wadat_ist, "post date

    lt_prot      like table of prott with header line,

    lt_vbpok_tab like table of vbpok with header line,

    lv_msg(255).

 

**an examination

*  select single lcnum

*    into @data(lv_lcnum)

*    from likp

*    where vbeln = @uv_vbeln.

*  if lv_lcnum is initial.

* gt_out2-message ='The financial document number of the delivery note cannot be empty'.

*    gt_out2-rtype = 'E'.

*  else.

*    select single *

*      into @data(ls_akkp)

*      from akkp

*      where lcnum = @lv_lcnum and aidat <= @gt_out2-wadat_istc and axdat >= @gt_out2-wadat_istc.

* if sy-subrc ne 0.

* gt_out2-message ='The posting date is not within the validity period of the credit'.

*      gt_out2-rtype = 'E'.

*    endif.

*  endif.

 

  if gt_out2-rtype = 'E' or uv_vbeln is initial.

    return.

  endif.

 

  clear ls_vbkok_wa.

  ls_vbkok_wa-vbeln_vl = uv_vbeln.

  ls_vbkok_wa-wadat_ist = gt_out2-wadat_ist.

  ls_vbkok_wa-wabuc ='X'.

 

  call function'WS_DELIVERY_UPDATE' "Start posting

    exporting

      vbkok_wa = ls_vbkok_wa

      synchron                    = 'X'

      update_picking              = 'X'

      commit                      = 'X'

      delivery                    = uv_vbeln

      not_lock = 'X'

      if_error_messages_send_0    = 'X'

    importing

      ef_error_any_0              = lv_er_any

      ef_error_in_item_deletion_0 = lv_er_itm

      ef_error_in_pod_update_0    = lv_er_upd

      ef_error_in_interface_0     = lv_er_inf

      ef_error_in_goods_issue_0   = lv_er_gss

      ef_error_in_final_check_0   = lv_er_fch

      ef_error_partner_update = lv_er_par

      ef_error_sernr_update = lv_er_ser

    tables

      prot                        = lt_prot

    exceptions

      error_message               = 1

      others                      = 2.

 

  if lt_prot[] is not initial or lv_er_any = 'X' "过账失败

                           or lv_er_itm = 'X'

                           or lv_er_upd = 'X'

                           or lv_er_inf = 'X'

                           or lv_er_gss = 'X'

                           or lv_er_fch = 'X'

                           or sy-subrc ne 0.

 

    call function 'BAPI_TRANSACTION_ROLLBACK'.

 

    gt_out2-rtype = 'E'.

    gt_out2-message = gt_out2-message &&'DN posting failed:' && lv_msg.

    loop at lt_prot where msgty eq 'E' or msgty eq 'A'.

      message id lt_prot-msgid type lt_prot-msgty number lt_prot-msgno

            with lt_prot-msgv1 lt_prot-msgv2 lt_prot-msgv3 lt_prot-msgv4

            into lv_msg.

      gt_out2-message = gt_out2-message && ',' && lv_msg.

      shift gt_out2-message left by 1 places.

    endloop.

 

  else.

    call function 'BAPI_TRANSACTION_COMMIT'

      exporting

        wait = 'X'.

    gt_out2-rtype = 'S'.

*    import cv_mblnr from memory id 'BORGR_MATDOC'.

  endif.

 

 

 

endform.

 

DEMO2

FUNCTION ZMM004_POST_DN.

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

*"*"Local interface:

*" IMPORTING

*" REFERENCE(I_VBELN) TYPE LIKP-VBELN

*" EXPORTING

*" REFERENCE(E_VBELN) TYPE VBFA-VBELN

*" TABLES

*" LT_RETURN STRUCTURE BAPIRET2

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

 

* Global data declarations

 

DATA:

LS_HEADER_DATA LIKE BAPIOBDLVHDRCON,

LS_HEADER_CONTROL LIKE BAPIOBDLVHDRCTRLCON.

DATA LT_ITEM LIKE TABLE OF BAPIOBDLVITEMCON WITH HEADER LINE. "Delivery order item

 

LS_HEADER_DATA-DELIV_NUMB = I_VBELN. "Delivery note number

 

LS_HEADER_CONTROL-DELIV_NUMB = I_VBELN. "Delivery note number

LS_HEADER_CONTROL-POST_GI_FLG ='X'. "Automatically post goods movement

LS_HEADER_CONTROL-VOLUME_FLG ='X'. "Confirmation of volume

LS_HEADER_CONTROL-DELIV_DATE_FLG ='X'. "Confirm delivery date

 

CALL FUNCTION 'BAPI_OUTB_DELIVERY_CONFIRM_DEC'

EXPORTING

HEADER_DATA = LS_HEADER_DATA

HEADER_CONTROL = LS_HEADER_CONTROL

DELIVERY = I_VBELN

TABLES

RETURN = LT_RETURN.

 

READ TABLE LT_RETURN WITH KEY TYPE = 'E'.

IF SY-SUBRC = 0.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'.

 

*Reversal needs to update the standard table

UPDATE LIKP SET VLSTK = '' ANZPK = '0' WHERE VBELN = I_VBELN.

COMMIT WORK AND WAIT.

 

*Return the material certificate

SELECT SINGLE VBELN

INTO E_VBELN

FROM VBFA

WHERE VBELV = I_VBELN AND VBTYP_N ='R' AND BWART NE'' AND RFMNG NE 0 "R Goods movement (posting material voucher)

AND NOT EXISTS

( SELECT *

FROM M_MBMPS "View has more conditions than MSEG

WHERE SMBLN = VBFA~VBELN OR MBLNR = VBFA~VBELN ). "Non-offset and offset

 

ENDIF.

 

ENDFUNCTION.

 

Note:

Another way to solve the reversal of the delivery note posted by bapi

 

 

 

Guess you like

Origin blog.csdn.net/cylcylcylcylwo/article/details/114014928