fb02修改凭证

函数 FI_ITEMS_MASS_CHANGE

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

*& Report ZTEST_4727

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

*&

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

REPORT ZTEST_4727.

TYPE-POOLS : TPIT.

DATA : W_BSEG    TYPE BSEG,

      W_MESSAGE TYPE T100-TEXT.

DATA : IT_ERRTAB TYPE TPIT_T_ERRDOC WITH HEADER LINE,

      IT_FLDTAB TYPE TPIT_T_FNAME WITH HEADER LINE,

      IT_BUZTAB TYPE TPIT_T_BUZTAB WITH HEADER LINE.

* Field name to be changed

IT_FLDTAB-FNAME = 'ZUONR'.

APPEND IT_FLDTAB.

CLEAR IT_FLDTAB.

IT_FLDTAB-FNAME = 'RSTGR'.

APPEND IT_FLDTAB.

CLEAR IT_FLDTAB.

* Field value

W_BSEG-ZUONR = 'BLL测试11'.

W_BSEG-RSTGR = '415'.

* ITEM 7

SELECT SINGLE

BUKRS

BELNR

GJAHR

BUZEI

KOART

UMSKZ

BSCHL

MWART

MWSKZ

FROM BSEG

INTO CORRESPONDING FIELDS OF IT_BUZTAB

WHERE BELNR = '1900000597'

  AND BUZEI = '3'

  AND BUKRS = '1701'

  AND GJAHR = '2017'.

IF SY-SUBRC = 0.

  APPEND IT_BUZTAB.

  CLEAR IT_BUZTAB.

ENDIF.

CALL FUNCTION 'FI_ITEMS_MASS_CHANGE'

  EXPORTING

    S_BSEG    = W_BSEG

  IMPORTING

    ERRTAB    = IT_ERRTAB[]

  TABLES

    IT_BUZTAB  = IT_BUZTAB

    IT_FLDTAB  = IT_FLDTAB

  EXCEPTIONS

    BDC_ERRORS = 1

    OTHERS    = 2.

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  PERFORM GENERATE_MESSAGE.

  WRITE : W_MESSAGE.

ELSE.

  WRITE : 'Updated successfully'.

ENDIF.

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

* & Form generate_message

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

FORM GENERATE_MESSAGE .

  CLEAR W_MESSAGE.

  READ TABLE IT_ERRTAB INDEX 1.

  IF SY-SUBRC = 0.

    CALL FUNCTION 'FORMAT_MESSAGE'

      EXPORTING

        ID        = IT_ERRTAB-ERR-MSGID

        LANG      = SY-LANGU

        NO        = IT_ERRTAB-ERR-MSGNR

        V1        = IT_ERRTAB-ERR-MSGV1

        V2        = IT_ERRTAB-ERR-MSGV2

        V3        = IT_ERRTAB-ERR-MSGV3

        V4        = IT_ERRTAB-ERR-MSGV4

      IMPORTING

        MSG      = W_MESSAGE

      EXCEPTIONS

        NOT_FOUND = 1

        OTHERS    = 2.

  ENDIF.

ENDFORM. " generate_message


由于这个函数是一行一行改数据的,可能会出现凭证被锁,解决方法:拷贝原函数出来,原函数中的:


fb02修改凭证_第1张图片
fb02修改凭证_第2张图片

你可能感兴趣的:(fb02修改凭证)