SELECT * INTO TABLE LT_AFVC FROM afvc
FOR ALL ENTRIES IN GT_DATA
WHERE aufpl = GT_DATA-aufpl AND APLZL = GT_DATA-APLZL.
DATA: GT_DATA_DEL TYPE TABLE OF TYP_DATA.
CLEAR:GT_DATA_DEL[].
LOOP AT GT_DATA ASSIGNING <GS_DATA> WHERE CHECKBOX = 'X'.
APPEND <GS_DATA> TO GT_DATA_DEL.
ENDLOOP.
LOOP AT GT_DATA_DEL ASSIGNING <GS_DATA>.
AT NEW AUFNR.
* ON CHANGE OF <GS_DATA>-AUFNR.
CLEAR:it_afvgkeys_to_delete[].
IF <GS_DATA>-AUFNR <> ''.
SELECT SINGLE aufpl INTO l_aufpl
FROM afko
WHERE aufnr = <GS_DATA>-AUFNR.
UPDATE afko SET atrkz = ''
WHERE aufnr = <GS_DATA>-AUFNR
AND atrkz = 'U'.
COMMIT WORK AND WAIT.
ENDIF.
* ENDON.
ENDAT.
DEFINE MODIFY_ALV.
MODIFY &1 FROM &2 TRANSPORTING &3 WHERE AUFNR = <GS_DATA>-aufnr and checkbox = 'X'.
END-OF-DEFINITION.
CLEAR it_afvgkeys_to_delete[].
READ TABLE LT_AFVC INTO LS_AFVC WITH KEY aufpl = <GS_DATA>-aufpl APLZL = <GS_DATA>-APLZL.
IF SY-SUBRC = 0.
MOVE-CORRESPONDING LS_AFVC TO ls_afvgdget.
ls_afvgdget-aufnrd = <GS_DATA>-AUFNR.
APPEND ls_afvgdget to it_afvgkeys_to_delete.
ENDIF.
AT END OF AUFNR.
IF it_afvgkeys_to_delete[] IS NOT INITIAL.
PERFORM order_read IN PROGRAM ('SAPLCOXT')
USING <GS_DATA>-AUFNR
CHANGING cs_bapireturn e_error.
IF e_error IS NOT INITIAL .
<GS_DATA>-MSG = '读取订单失败'.
MODIFY GT_DATA FROM <GS_DATA> TRANSPORTING MSG WHERE AUFNR = <GS_DATA>-aufnr and checkbox = 'X'.
CONTINUE.
ELSE.
"调用删除
CLEAR e_error.
CLEAR ct_bapireturn[].
CALL FUNCTION 'CO_XT_OPERATIONS_DELETE' "删除工序
EXPORTING
it_afvgkeys_to_delete = it_afvgkeys_to_delete
* I_DEL_COMPONENTS = 'X'
i_del_physical = 'X'
IMPORTING
e_error_occurred = e_error
TABLES
ct_bapireturn = ct_bapireturn
EXCEPTIONS
delete_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-msgid TYPE sy-MSGTY NUMBER SY-msgNO INTO <GS_DATA>-MSG
WITH sy-MSGV1 sy-MSGV2 sy-MSGV3 sy-MSGV4.
MODIFY_ALV GT_DATA <GS_DATA> MSG. "更新内表
CONTINUE.
ENDIF.
IF e_error IS NOT INITIAL .
LOOP AT ct_bapireturn INTO cs_bapireturn WHERE TYPE = 'E' OR TYPE = 'A'.
CONCATENATE <GS_DATA>-MSG cs_bapireturn-MESSAGE ';' INTO <GS_DATA>-MSG.
ENDLOOP.
MODIFY_ALV GT_DATA <GS_DATA> MSG. "更新内表
CONTINUE.
ELSE.
CLEAR e_error.
CALL FUNCTION 'CO_XT_ORDER_PREPARE_COMMIT'
IMPORTING
e_error_occurred = e_error
es_bapireturn = cs_bapireturn.
IF e_error IS NOT INITIAL .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. "错误回滚
LOOP AT ct_bapireturn INTO cs_bapireturn WHERE TYPE = 'E' OR TYPE = 'A'.
CONCATENATE <GS_DATA>-MSG cs_bapireturn-MESSAGE ';' INTO <GS_DATA>-MSG.
ENDLOOP.
MODIFY_ALV GT_DATA <GS_DATA> MSG. "更新内表
CONTINUE.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' "成功提交
EXPORTING
WAIT = 'X'.
<GS_DATA>-MSG = '删除成功'.
MODIFY_ALV GT_DATA <GS_DATA> MSG. "更新内表
CONTINUE.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDAT.
ENDLOOP.