DATA: IS_MKPF TYPE MKPF,
IS_MSEG TYPE MSEG,
IT_MKPF LIKE TABLE OF IS_MKPF,
IT_MSEG LIKE TABLE OF MSEG.
GS_DATA-MSG = ''.
MODIFY GT_DATA FROM GS_DATA TRANSPORTING MSG WHERE MBLNR NE ''.
CLEAR:IT_MKPF[],GT_LOG[].
SELECT *
FROM MKPF
WHERE EXISTS ( SELECT * FROM @GT_DATA AS A WHERE A~MBLNR = MKPF~MBLNR AND A~SEL = 'X' )
INTO CORRESPONDING FIELDS OF TABLE @IT_MKPF.
IF LINES( IT_MKPF ) > 1000.
MESSAGE '单次最多修改一千行' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
LOOP AT IT_MKPF INTO IS_MKPF.
GS_LOG-MBLNR = IS_MKPF-MBLNR.
GS_LOG-XBLNR = IS_MKPF-XBLNR.
GS_LOG-CPUDT = SY-DATUM.
GS_LOG-CPUTM = SY-UZEIT.
GS_LOG-USNAM = SY-UNAME.
GS_LOG-BKTXT_OLD = IS_MKPF-BKTXT.
READ TABLE GT_DATA INTO GS_DATA WITH KEY MBLNR = IS_MKPF-MBLNR.
IF SY-SUBRC = 0.
IS_MKPF-BKTXT = GS_DATA-BKTXT.
ENDIF.
GS_LOG-BKTXT_NEW = IS_MKPF-BKTXT.
MODIFY IT_MKPF FROM IS_MKPF.
APPEND GS_LOG TO GT_LOG.
CLEAR:IS_MKPF,GS_LOG.
ENDLOOP.
CALL FUNCTION 'MB_CHANGE_DOCUMENT'
TABLES
ZMKPF = IT_MKPF
ZMSEG = IT_MSEG.
IF SY-SUBRC = 0.
GS_DATA-MSG = '更新成功'.
MODIFY GT_DATA FROM GS_DATA TRANSPORTING MSG WHERE SEL = 'X'.
modify ZMMF112_LOG FROM TABLE GT_LOG.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
GS_DATA-MSG = '更新失败'.
MODIFY GT_DATA FROM GS_DATA TRANSPORTING MSG WHERE SEL = 'X'.
ENDIF.