FI_ITEMS_MASS_CHANGE 修改会计凭证行项目

FI_ITEMS_MASS_CHANGE 里是

    call transaction 'FB02'  using    bdcdata

                             mode     bdcmode

                             update   'A'

                             messages into msgtab.

所以如果在Loop里更新一张凭证的多行会有锁定问题。

解决方法:等锁(另外手动解锁应该也可以)

    data lt_seqg3 like table of seqg3 with header line.

    data lv_garg like lt_seqg3-garg.

    lv_garg = sy-mandt && ls_bseg-bukrs && ls_bseg-belnr && ls_bseg-gjahr.

    do.

      call function 'ENQUEUE_READ'

        exporting

          guname = sy-uname

        tables

          enq    = lt_seqg3.

      read table lt_seqg3 with key gname = 'BKPF' garg = lv_garg.

      if sy-subrc ne 0.

        exit.

      endif.

    enddo.

 

 

DEMO(一次一张凭证的,锁的问题参考上面)

function zfi_items_mass_change.

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

*"*"本地接口:

*"  IMPORTING

*"     VALUE(BELNR) TYPE  BELNR_D

*"     VALUE(GJAHR) TYPE  GJAHR

*"     VALUE(BUKRS) TYPE  BUKRS_D

*"     VALUE(SGTXT) TYPE  SGTXT

*"     VALUE(ZFBDT) TYPE  DZFBDT OPTIONAL

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

 

  data: l_bseg type bseg.

  data: lt_buztab type standard table of tpit_buztab.

  data: ls_buztab type tpit_buztab.

  data: lt_fldtab type standard table of tpit_fname.

  data: ls_fldtab type tpit_fname.

  data: lt_bseg type standard table of bseg.

  data: ls_bseg type bseg.

 

  wait up to 3 seconds.

 

  refresh lt_bseg.

  select *

    into corresponding fields of table lt_bseg

    from bseg

    where bukrs = bukrs and belnr = belnr and gjahr = gjahr and rebzg ne '' "发票参考号不为空,即为清账新生成的行

    order by bukrs gjahr belnr.

 

*要设置的值

  if sgtxt is not initial.

    l_bseg-sgtxt = sgtxt.

  endif.

  if zfbdt is not initial.

    l_bseg-zfbdt = zfbdt.

  endif.

 

  clear lt_buztab[].

  clear lt_fldtab[].

 

  loop at lt_bseg into ls_bseg.

    clear ls_buztab.

    move-corresponding ls_bseg to ls_buztab.

    append ls_buztab to lt_buztab.

 

    clear ls_fldtab.

    if sgtxt is not initial.

      ls_fldtab-fname = 'SGTXT'.

      append ls_fldtab to lt_fldtab.

    endif.

 

    clear ls_fldtab.

    if zfbdt is not initial.

      ls_fldtab-fname = 'ZFBDT'.

      append ls_fldtab to lt_fldtab.

    endif.

  endloop.

 

  call function 'FI_ITEMS_MASS_CHANGE'

    exporting

      s_bseg     = l_bseg

    tables

      it_buztab  = lt_buztab

      it_fldtab  = lt_fldtab

    exceptions

      bdc_errors = 1

      others     = 2.

 

  if sy-subrc eq 0.

    call function 'BAPI_TRANSACTION_COMMIT'.

  else.

    message id sy-msgid type 'S' number sy-msgno

         with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into data(lv_msg).

  endif.

 

*  "解锁会计凭证

*  call function 'DEQUEUE_EFBKPF'

*    exporting

*      bukrs = i_bukrs

*      belnr = i_belnr

*      gjahr = i_gjahr.

 

 

 

 

endfunction.

 

猜你喜欢

转载自blog.csdn.net/cylcylcylcylwo/article/details/114078988