ABAP-FB02修改抬头字段及行项目字段

FB02修改抬头字段函数:FI_DOCUMENT_CHANGE

DATA:lv_bukrs  TYPE bukrs,
         lv_belnr  TYPE belnr_d,
         lv_gjahr  TYPE gjahr,
         ls_accchg TYPE accchg,
         lt_accchg TYPE TABLE OF accchg.

lv_bukrs = ls_fprl_item-bukrs.
lv_belnr = ls_fprl_item-vblnr_pay.
lv_gjahr = ls_fprl_item-zaldt+0(4).

ls_accchg-fdname = 'BKTXT'. "可替换成其他字段
ls_accchg-newval = lv_sgtxt.
APPEND ls_accchg TO lt_accchg.

CALL FUNCTION 'FI_DOCUMENT_CHANGE'
  EXPORTING
    i_bukrs = lv_bukrs
    i_belnr = lv_belnr
    i_gjahr = lv_gjahr
  TABLES
    t_accchg = lt_accchg
  EXCEPTIONS
    no_reference         = 1
    no_document          = 2
    many_documents       = 3
    wrong_input          = 4
    overwrite_creditcard = 5
    OTHERS               = 6.

FB02修改行项目字段函数:FI_ITEMS_MASS_CHANGE

DATA:ls_bseg   TYPE bseg,
         ls_buztab TYPE tpit_buztab,
         lt_buztab TYPE TABLE OF tpit_buztab,
         ls_fldtab TYPE tpit_fname,
         lt_fldtab TYPE TABLE OF tpit_fname.
DATA:lt_return TYPE TABLE OF tpit_errdoc,
         ls_return TYPE tpit_errdoc.

LOOP AT lt_bseg INTO DATA(ls_bseg2).

    
  CLEAR:ls_buztab,lt_buztab,ls_fldtab,lt_fldtab,ls_return,lt_return.
  MOVE-CORRESPONDING ls_bseg2 TO ls_buztab.
  APPEND ls_buztab TO lt_buztab.

  ls_fldtab-fname = 'SGTXT'."可以追加或变更其他字段
  ls_fldtab-aenkz = 'X'.
  APPEND ls_fldtab TO lt_fldtab.

  "调取BAPI更改文本
  CALL FUNCTION 'FI_ITEMS_MASS_CHANGE'
    EXPORTING
      s_bseg     = ls_bseg
    IMPORTING
      errtab     = lt_return
    TABLES
      it_buztab  = lt_buztab
      it_fldtab  = lt_fldtab
    EXCEPTIONS
      bdc_errors = 1
      OTHERS     = 2.
    
  IF lt_return IS NOT INITIAL.
    READ TABLE lt_return INTO ls_return INDEX 1.
    CLEAR:l_text.
    CALL FUNCTION 'FORMAT_MESSAGE'
      EXPORTING
        id        = ls_return-err-msgid
        no       = ls_return-err-msgnr
        v1       = ls_return-err-msgv1
        v2       = ls_return-err-msgv2
        v3       = ls_return-err-msgv3
        v4       = ls_return-err-msgv4
      IMPORTING
        msg       = l_text
      EXCEPTIONS
        not_found = 1
        OTHERS    = 2.
  ENDIF.
  CLEAR:ls_bseg2.
  "等待2秒,防止凭证被锁
  WAIT UP TO 2 SECONDS.
ENDLOOP.

 

posted @ 2023-03-23 08:06  阿胖的阿多  阅读(458)  评论(0编辑  收藏  举报