ABAP:VF11销售发票冲销增强
VF11销售发票冲销增强
SMOD:增强V60A0001
****ADD BY ZJ 20221026 销售发票增强校验 START IF sy-tcode = 'VF11'. LOOP AT xkomfk ASSIGNING FIELD-SYMBOL(<fs_xkomfk>). SELECT SINGLE * FROM zsdt017 INTO @DATA(ls_zsdt017) WHERE objkey = @<fs_xkomfk>-vbeln AND objtype = 'BL' AND fksto = ''. IF sy-subrc = 0. IF ls_zsdt017-canum = '0010'. SELECT SINGLE vkorg INTO @DATA(lv_vkorg) FROM vbrk WHERE vbeln = @<fs_xkomfk>-vbeln. IF sy-subrc = 0. SELECT SINGLE * FROM zsdt031 INTO @DATA(ls_zsdt031) WHERE bukrs = @lv_vkorg AND objtype = 'BS'. IF sy-subrc = 0 AND ls_zsdt031-zbs = 'Y'. MESSAGE '发票是自动创建的,不能冲销' TYPE 'E'. ENDIF. ENDIF. ELSE. SELECT SINGLE * INTO @DATA(ls_zsdt017_2) FROM zsdt017 WHERE zrfc_logid = @ls_zsdt017-zrfc_logid AND canum = '0010'. IF sy-subrc = 0. SELECT SINGLE bukrs INTO @DATA(lv_bukrs) FROM rbkp WHERE belnr = @ls_zsdt017_2-objkey AND gjahr = @ls_zsdt017_2-gjahr. IF sy-subrc = 0. SELECT SINGLE zbs INTO @DATA(lv_zbs) FROM zsdt031 WHERE bukrs = @lv_bukrs AND objtype = 'IS'. IF sy-subrc = 0 AND lv_zbs = 'Y'. MESSAGE '发票是自动创建的,不能冲销' TYPE 'E'. ENDIF. ENDIF. ENDIF. ENDIF. ENDIF. * SELECT SINGLE vkorg INTO @DATA(lv_vkorg) FROM vbrk WHERE vbeln = @<fs_xkomfk>-vbeln. * IF sy-subrc = 0. * SELECT SINGLE * FROM zsdt031 INTO @DATA(ls_zsdt031) WHERE bukrs = @lv_vkorg * AND objtype = 'BS'. * IF ls_zsdt031-zbs = 'Y'. * SELECT SINGLE * FROM zsdt017 INTO @DATA(ls_zsdt017) WHERE objkey = @<fs_xkomfk>-vbeln * AND objtype = 'BS'. * IF sy-subrc = 0. * MESSAGE '发票是自动创建的,不能冲销' TYPE 'E'. * ENDIF. * ENDIF. * ENDIF. ENDLOOP. ENDIF. ****ADD BY ZJ 20221026 销售发票增强校验 END
CMOD:
全部激活
上述增强在VF11界面点保存可以进去,或者点击回车也会进去,但是在VF11点击回车以后,再点保存以后就进不去了,因此可以考虑下述增强点:
需要报错误消息的话在一代增强:SE38--->RV60AFZC-->FROM:USEREXIT_SAVE_DOCUMENT_PREPARE,此FORM不存在的话可以自行创建
*{ INSERT DS4K904274 1 *&---------------------------------------------------------------------* *& FORM USEREXIT_SAVE_DOCUMENT_PREPARE *&---------------------------------------------------------------------* *& 标准没有这个子例程,但是,标准有这个子例程的调用 *& (调用位置在函数RV_INVOICE_DOCUMENT_ADD) *& 所以在SAPLV60A程序内加入该子例程,即可开放该出口 *& 从而在发票保存前进行客制化的操作 *& 可以通过T180-TRTYP进行判断,并对XVBRK、XVBRP进行修改 *& (我并没找到SAP关于该出口的说明,慎用) *&---------------------------------------------------------------------* FORM USEREXIT_SAVE_DOCUMENT_PREPARE. IF sy-tcode EQ 'VF01'. LOOP AT xvbrp. SELECT SINGLE zsign_date FROM zlikp INTO @DATA(lv_zzsgdt) WHERE vbeln = @xvbrp-vgbel. IF sy-subrc EQ 0 AND lv_zzsgdt IS INITIAL. MESSAGE '交货单:' && xvbrp-vgbel && '没有签收日期,请确认' TYPE 'E'. ENDIF. ENDLOOP. ENDIF. DATA: ls_return TYPE zshr0004, lv_result TYPE string. TYPES:BEGIN OF ty_data,"定义表类型 invoice_no TYPE string, is_cancel TYPE string, END OF ty_data, lty_data TYPE TABLE OF ty_data. DATA:BEGIN OF ls_result, code TYPE string, text TYPE string, data TYPE lty_data, page_limit TYPE string, END OF ls_result. TYPES:lty_data1 TYPE TABLE OF string. DATA:BEGIN OF ls_data1, sys_id_list TYPE lty_data1, END OF ls_data1. DATA:lt_vbeln TYPE lty_data1, ls_vbeln LIKE LINE OF lt_vbeln. IF sy-tcode = 'VF11' AND sy-uname = 'SC10382'. LOOP AT xvbrk INTO DATA(ls_xvbrk) WHERE vbtyp NE 'N'. ls_vbeln = ls_xvbrk-vbeln. APPEND ls_vbeln TO lt_vbeln. ls_data1-sys_id_list = lt_vbeln. CALL FUNCTION 'ZCOMM_INTERFACE_SEND2' EXPORTING data = ls_data1 ifid = '020' host = 'X' IMPORTING es_return = ls_return ev_response = lv_result. "JSON转ABAP /ui2/cl_json=>deserialize( EXPORTING json = lv_result CHANGING data = ls_result ). IF ls_return-code = '200'. READ TABLE ls_result-data INTO DATA(ls_data) WITH KEY invoice_no = ls_xvbrk-vbeln. IF sy-subrc NE 0 OR ls_data-is_cancel = 'FALSE'. MESSAGE 'CDC已开票或核销,请勿冲销' TYPE 'E'. ENDIF. ELSE. IF ls_return-code = 'E'. MESSAGE '发送CDC查询失败,' && ls_return-message TYPE 'E'. ELSE. MESSAGE '发送CDC查询失败,' && ls_result-text TYPE 'E'. ENDIF. ENDIF. CLEAR:ls_return,lv_result,ls_vbeln,lt_vbeln,ls_data1. ENDLOOP. ENDIF. ENDFORM.
SE18:BADI:SD_CIN_LV60AU02 注:此增强中不能报错误消息,无法阻止凭证冲销
METHOD if_ex_sd_cin_lv60au02~excise_invoice_create. IF sy-uname EQ 'BASIS2' AND sy-tcode EQ 'VF11'. LOOP AT xvbrk INTO DATA(ls_xvbrk) WHERE vbtyp NE 'N'. SELECT COUNT(*) FROM zsdt051 WHERE vbeln_vf EQ ls_xvbrk-vbeln AND fksto = ''. IF sy-subrc EQ 0. UPDATE zsdt051 SET fksto = 'X' aedat = sy-datum aenam = sy-uname aezet = sy-uzeit WHERE vbeln_vf = ls_xvbrk-vbeln AND fksto EQ ''. COMMIT WORK AND WAIT. ENDIF. CLEAR:ls_xvbrk. ENDLOOP. ENDIF. ENDMETHOD.