***INCLUDE MV45AFZZ .
************************************************************************
* *
* This include is reserved for user modifications *
* *
* Forms for sales document processing *
* *
* The name of modification modules should begin with 'ZZ'. *
* *
************************************************************************
*---------------------------------------------------------------------*
* FORM ZZEXAMPLE *
*---------------------------------------------------------------------*
* text...................................... *
*---------------------------------------------------------------------*
*FORM ZZEXAMPLE.
* ...
*ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_DELETE_DOCUMENT *
*---------------------------------------------------------------------*
* This userexit can be used to delete data in additional tables *
* when a sales document is deleted. *
* *
* This form is called in dialog at the end of form BELEG_LOESCHEN*
* just before form BELEG_SICHERN is performed to delete the *
* datas on the database. *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_DELETE_DOCUMENT.
ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_FIELD_MODIFICATION *
*---------------------------------------------------------------------*
* This userexit can be used to modify the attributes of *
* screen fields. *
* This form is processed for each field in the screen. *
* *
* The use of the fields screen-group1 to screen-group4 is: *
* *
* Screen-group1: Automatic modification contolles by transaction*
* MFAW. *
* Screen-group2: Contents 'LOO' for steploop-fields. *
* Screen-group3: Used for modififaction, which are dependent on *
* control tables or other fix information. *
* Screen-group4: Unused *
* *
* For field mofifications, which are dependent on the document *
* status, you can use the status field in the workareas *
* XVBAP for item status and XVBUK for header status. *
* *
* This form is called from module FELDAUSWAHL. *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_FIELD_MODIFICATION.
* CASE SCREEN-GROUP3.
* WHEN '900'.
* IF VBAK-VBTYP NE 'A'.
* SCREEN-ACTIVE = 0.
* ENDIF.
* ENDCASE.
* CASE SCREEN-NAME.
* WHEN 'VBAK-VBELN'.
* SCREEN-ACTIVE = 0.
* ENDCASE.
*{ INSERT SGDK900103 1
IF SY-TCODE = 'VA02' OR SY-TCODE = 'VA22'
AND ( VBAK-AUART = 'ZOR1' OR VBAK-AUART = 'ZRE1'
OR VBAK-AUART = 'ZQT1' ).
if sy-dynnr <> '0102' .
DATA : OBJNR TYPE JSTO-OBJNR .
DATA : LV_STONR TYPE TJ30-STONR .
data: slcol like line of tctrl_u_erf_auftrag-cols.
CONCATENATE 'VB' VBAK-VBELN '000000' INTO OBJNR .
CALL FUNCTION 'STATUS_READ'
EXPORTING
CLIENT = SY-MANDT
OBJNR = OBJNR
IMPORTING
STONR = LV_STONR
EXCEPTIONS
OBJECT_NOT_FOUND = 1
OTHERS = 2.
IF LV_STONR <> '10' AND LV_STONR <> ''.
SCREEN-input = 0.
loop at tctrl_u_erf_auftrag-cols into slcol.
slcol-screen-input = 0.
modify tctrl_u_erf_auftrag-cols from slcol.
endloop.
IF sy-dynnr = '4305' and screen-name = 'BT_KSTC'.
screen-input = 1.
ENDIF.
ELSE .
loop at tctrl_u_erf_auftrag-cols into slcol.
slcol-screen-input = 1.
modify tctrl_u_erf_auftrag-cols from slcol.
endloop.
ENDIF .
EXPORT LV_STONR TO MEMORY ID 'ZKONV' .
endif .
ENDIF .
* if sy-tcode = 'VA02'.
*
* IF screen-name = 'KOMV-KBETR' OR SCREEN-NAME = 'RV61A-KOEIN'
* OR screen-name = 'KOMV-KPEIN' OR SCREEN-NAME = 'KOMV-KMEIN' .
** if screen-name = 'KOMV-KBETR' or screen-name = 'VBAP-NETPR' or
** screen-name = 'KOMV-NETWR'.
* screen-input = 0.
*
* ENDIF.
* endif .
*} INSERT
ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_MOVE_FIELD_TO_VBAK *
*---------------------------------------------------------------------*
* This userexit can be used to move some fields into the sales *
* dokument header workaerea VBAK. *
* *
* SVBAK-TABIX = 0: Create header *
* SVBAK-TABIX > 0: Change header *
* *
* This form is called at the end of form VBAK_FUELLEN. *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_MOVE_FIELD_TO_VBAK.
* vbak-zzfield = xxxx-zzfield2.
*{ INSERT SGDK900778 1
IF SY-TCODE = 'VA01' AND GV_MARKJ = ''
AND VBAK-KUNNR <> ''."AND VBAK-KUNWE <> ''.
IF VBAK-AUART = 'ZTP1' OR VBAK-AUART = 'ZCS1'
OR VBAK-AUART = 'ZOR1' .
DATA : LWA_KNVP TYPE KNVP .
DATA : LWA_BSID TYPE BSID .
DATA : LWA_BSID_Y TYPE BSID .
DATA : LIT_KNV1 TYPE TABLE OF KNVP .
DATA : LIT_BSID TYPE TABLE OF BSID .
DATA : LIT_BSID_Y TYPE TABLE OF BSID .
DATA : LWA_BKPF TYPE BKPF .
DATA : LIT_BKPF TYPE TABLE OF BKPF .
DATA : LWA_VBRK TYPE VBRK .
DATA : LIT_VBRK TYPE TABLE OF VBRK .
" DATA :LIT_KNV2 TYPE TABLE OF KNVP .
DATA : LV_KLIMK TYPE KNKK-KLIMK ."信用总额
DATA : LV_KLIMC(16) TYPE C ."信用总额
DATA : LV_SKFOR TYPE KNKK-KLIMK ."已使用信用总额
DATA : LV_SKFOC(16) TYPE C ."已使用信用总额
DATA : LV_LINE1 TYPE STRING .
DATA : LV_LINE2 TYPE STRING .
DATA : LV_TITEL TYPE STRING .
DATA : LV_LOCAL TYPE VBAK-WAERK.
DATA : LV_FOREI TYPE VBAK-WAERK.
"获取信用额度
SELECT SINGLE KLIMK
INTO LV_KLIMK
FROM KNKK
WHERE KUNNR = VBAK-KUNNR .
IF SY-SUBRC = 0 .
"获取售达方对应的付款方
SELECT *
INTO TABLE LIT_KNV1
FROM KNVP
WHERE KUNNR = VBAK-KUNNR
AND PARVW = 'RG' .
SORT LIT_KNV1 BY KUNN2 .
DELETE ADJACENT DUPLICATES FROM LIT_KNV1
COMPARING KUNN2 .
SELECT *
INTO TABLE LIT_BSID
FROM BSID
FOR ALL ENTRIES IN LIT_KNV1
WHERE KUNNR = LIT_KNV1-KUNN2
AND BLART IN ('SA','RV') .
IF LIT_BSID[] IS NOT INITIAL .
SELECT *
INTO TABLE LIT_BSID_Y
FROM BSID
FOR ALL ENTRIES IN LIT_BSID
WHERE BUKRS = LIT_BSID-BUKRS
AND BLART NOT IN ('SA','RV')
AND REBZG = LIT_BSID-BELNR
AND REBZJ = LIT_BSID-GJAHR
AND REBZZ = LIT_BSID-BUZEI."SA为收款凭证
CLEAR LIT_BKPF[] .
SELECT *
INTO TABLE LIT_BKPF
FROM BKPF
FOR ALL ENTRIES IN LIT_BSID
WHERE BUKRS = LIT_BSID-BUKRS
AND BELNR = LIT_BSID-BELNR
AND GJAHR = LIT_BSID-GJAHR .
IF SY-SUBRC = 0 .
SELECT *
INTO TABLE LIT_VBRK
FROM VBRK
FOR ALL ENTRIES IN LIT_BKPF
WHERE VBELN = LIT_BKPF-AWKEY+0(10)
AND KUNAG = VBAK-KUNNR .
ENDIF .
ENDIF .
* CASE VBAK-BUKRS_VF .
* WHEN '3100' .
* LV_LOCAL = 'CNY' .
* WHEN '3200' .
* LV_LOCAL = 'CAD' .
* WHEN '3300' .
* LV_LOCAL = 'USD' .
* ENDCASE .
SELECT SINGLE WAERS
INTO LV_LOCAL
FROM KNVV
WHERE KUNNR = VBAK-KUNNR
AND VKORG = VBAK-VKORG
AND VTWEG = VBAK-VTWEG
AND SPART = VBAK-SPART .
IF LV_LOCAL <> 'CNY' .
LV_FOREI = 'CNY' .
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
DATE = SY-DATUM
FOREIGN_AMOUNT = LV_KLIMK
FOREIGN_CURRENCY = LV_FOREI
LOCAL_CURRENCY = LV_LOCAL
IMPORTING
LOCAL_AMOUNT = LV_KLIMK
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6 .
CLEAR LV_FOREI .
ENDIF .
CLEAR LWA_BSID .
LOOP AT LIT_BSID INTO LWA_BSID .
IF LWA_BSID-BUDAT >= '20150401' .
CLEAR LWA_BKPF .
READ TABLE LIT_BKPF INTO LWA_BKPF
WITH KEY BUKRS = LWA_BSID-BUKRS
BELNR = LWA_BSID-BELNR
GJAHR = LWA_BSID-GJAHR .
CLEAR LWA_VBRK .
READ TABLE LIT_VBRK INTO LWA_VBRK
WITH KEY VBELN = LWA_BKPF-AWKEY+0(10) .
IF LWA_BSID-FILKD = VBAK-KUNNR OR
LWA_VBRK-VBELN <> '' .
CASE LWA_BSID-BUKRS .
WHEN '3100' .
LV_FOREI = 'CNY' .
WHEN '3200' .
LV_FOREI = 'CAD' .
WHEN '3300' .
LV_FOREI = 'USD' .
ENDCASE .
if LV_FOREI <> LV_LOCAL .
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
DATE = LWA_BSID-BUDAT
FOREIGN_AMOUNT = LWA_BSID-DMBTR
FOREIGN_CURRENCY = LV_FOREI
LOCAL_CURRENCY = LV_LOCAL
IMPORTING
LOCAL_AMOUNT = LWA_BSID-DMBTR
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6 .
ENDIF .
IF LWA_BSID-SHKZG = 'S'.
LV_SKFOR = LV_SKFOR + LWA_BSID-DMBTR .
ELSE .
LV_SKFOR = LV_SKFOR - LWA_BSID-DMBTR .
ENDIF.
"已核销金额
CLEAR LWA_BSID_Y .
LOOP AT LIT_BSID_Y INTO LWA_BSID_Y
WHERE REBZG = LWA_BSID-BELNR
AND REBZJ = LWA_BSID-GJAHR"会计年度
AND REBZZ = LWA_BSID-BUZEI."
IF LV_FOREI <> LV_LOCAL .
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
DATE = LWA_BSID_Y-BUDAT
FOREIGN_AMOUNT = LWA_BSID_Y-DMBTR
FOREIGN_CURRENCY = LV_FOREI
LOCAL_CURRENCY = LV_LOCAL
IMPORTING
LOCAL_AMOUNT = LWA_BSID_Y-DMBTR
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6.
ENDIF .
IF LWA_BSID_Y-SHKZG = 'S' .
LV_SKFOR = LV_SKFOR + LWA_BSID_Y-DMBTR.
ELSE .
LV_SKFOR = LV_SKFOR - LWA_BSID_Y-DMBTR.
ENDIF .
CLEAR LWA_BSID_Y .
ENDLOOP .
ENDIF .
ELSE .
DATA : LV_KUNAG TYPE KNA1-KUNNR .
LV_KUNAG = LWA_BSID-XBLNR+0(10) .
CONDENSE LV_KUNAG NO-GAPS.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LV_KUNAG
IMPORTING
OUTPUT = LV_KUNAG.
IF LV_KUNAG = VBAK-KUNNR .
CASE LWA_BSID-BUKRS .
WHEN '3100' .
LV_FOREI = 'CNY' .
WHEN '3200' .
LV_FOREI = 'CAD' .
WHEN '3300' .
LV_FOREI = 'USD' .
ENDCASE .
IF LV_FOREI <> LV_LOCAL .
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
DATE = LWA_BSID-BUDAT
FOREIGN_AMOUNT = LWA_BSID-DMBTR
FOREIGN_CURRENCY = LV_FOREI
LOCAL_CURRENCY = LV_LOCAL
IMPORTING
LOCAL_AMOUNT = LWA_BSID-DMBTR
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6.
ENDIF .
IF LWA_BSID-SHKZG = 'S'.
LV_SKFOR = LV_SKFOR + LWA_BSID-DMBTR .
ELSE .
LV_SKFOR = LV_SKFOR - LWA_BSID-DMBTR .
ENDIF.
"已核销金额
CLEAR LWA_BSID_Y .
LOOP AT LIT_BSID_Y INTO LWA_BSID_Y
WHERE REBZG = LWA_BSID-BELNR
AND REBZJ = LWA_BSID-GJAHR"会计年度
AND REBZZ = LWA_BSID-BUZEI."
IF LV_FOREI <> LV_LOCAL .
CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
DATE = LWA_BSID_Y-BUDAT
FOREIGN_AMOUNT = LWA_BSID_Y-DMBTR
FOREIGN_CURRENCY = LV_FOREI
LOCAL_CURRENCY = LV_LOCAL
IMPORTING
LOCAL_AMOUNT = LWA_BSID_Y-DMBTR
EXCEPTIONS
NO_RATE_FOUND = 1
OVERFLOW = 2
NO_FACTORS_FOUND = 3
NO_SPREAD_FOUND = 4
DERIVED_2_TIMES = 5
OTHERS = 6.
ENDIF .
IF LWA_BSID_Y-SHKZG = 'S' .
LV_SKFOR = LV_SKFOR + LWA_BSID_Y-DMBTR.
ELSE .
LV_SKFOR = LV_SKFOR - LWA_BSID_Y-DMBTR.
ENDIF .
CLEAR LWA_BSID_Y .
ENDLOOP .
ENDIF .
ENDIF .
CLEAR LWA_BSID .
ENDLOOP.
LV_KLIMC = LV_KLIMK .
LV_SKFOC = LV_SKFOR .
IF SY-LANGU = '1' .
LV_TITEL = '信贷检查' .
CONCATENATE '售达方信贷额度 :' LV_KLIMC LV_LOCAL
INTO LV_LINE1 .
CONCATENATE '售达方已使用额度:' LV_SKFOC LV_LOCAL
INTO LV_LINE2 .
ELSE .
LV_TITEL = 'Gredit Check' .
CONCATENATE 'Gredit Value :' LV_KLIMC LV_LOCAL
INTO LV_LINE1 .
CONCATENATE 'Outstanding Value:' LV_SKFOC LV_LOCAL
INTO LV_LINE2 .
ENDIF .
IF LV_KLIMK < LV_SKFOR .
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
TITEL = LV_TITEL
TEXTLINE1 = LV_LINE1
TEXTLINE2 = LV_LINE2
* START_COLUMN = 25
* START_ROW = 6
.
ENDIF .
ELSE .
IF SY-LANGU = '1' .
LV_TITEL = '信贷检查' .
LV_LINE1 = '该售达方不存在信贷主数据。' .
ELSE .
LV_TITEL = 'Gredit Check' .
LV_LINE1 = '该售达方不存在信贷主数据。' .
ENDIF .
CALL FUNCTION 'POPUP_TO_DISPLAY_TEXT'
EXPORTING
TITEL = LV_TITEL
TEXTLINE1 = LV_LINE1
* TEXTLINE2 = ' '
* START_COLUMN = 25
* START_ROW = 6
.
ENDIF .
GV_MARKJ = 'X' .
ENDIF .
ENDIF .
*} INSERT
ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_MOVE_FIELD_TO_VBAP *
*---------------------------------------------------------------------*
* This userexit can be used to move some fields into the sales *
* dokument item workaerea VBAP *
* *
* SVBAP-TABIX = 0: Create item *
* SVBAP-TABIX > 0: Change item *
* *
* This form is called at the end of form VBAP_FUELLEN. *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_MOVE_FIELD_TO_VBAP.
* VBAP-zzfield = xxxx-zzfield2.
ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_MOVE_FIELD_TO_VBEP *
*---------------------------------------------------------------------*
* This userexit can be used to move some fields into the sales *
* dokument schedule line workaerea VBEP *
* *
* SVBEP-TABIX = 0: Create schedule line *
* SVBEP-TABIX > 0: Change schedule line *
* *
* This form is called at the end of form VBEP_FUELLEN. *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_MOVE_FIELD_TO_VBEP.
* VBEP-zzfield = xxxx-zzfield2.
ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_MOVE_FIELD_TO_VBKD *
*---------------------------------------------------------------------*
* This userexit can be used to move some fields into the sales *
* dokument business data workaerea VBKD *
* *
* SVBKD-TABIX = 0: Create data *
* SVBKD-TABIX > 0: Change data *
* *
* This form is called at the end of form VBKD_FUELLEN. *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_MOVE_FIELD_TO_VBKD.
* VBKD-zzfield = xxxx-zzfield2.
*{ INSERT SGDK900103 1
IF VBKD-BSARK_E <> '' .
DATA : LV_TYPE(100) TYPE C .
AUTHORITY-CHECK OBJECT 'Z_BSARK' ID 'BSARK' FIELD VBKD-BSARK_E.
" ID 'ACTVT' FIELD '03'.
IF SY-SUBRC <> 0.
" SET CURSOR FIELD 'P_VKORG'.
IF SY-LANGU = '1' .
CLEAR LV_TYPE .
CONCATENATE '没有改采购订单类型的权限:'
VBKD-BSARK_E INTO LV_TYPE .
MESSAGE LV_TYPE TYPE 'E' .
ELSE .
CLEAR LV_TYPE .
CONCATENATE 'You are not authorized to use purchase order type:'
VBKD-BSARK_E INTO LV_TYPE .
MESSAGE LV_TYPE TYPE 'E' .
ENDIF .
CLEAR VBKD-BSARK_E .
"无权限查看销售组织& 数据,请确认。
ENDIF.
ENDIF .
*} INSERT
ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_NUMBER_RANGE *
*---------------------------------------------------------------------*
* This userexit can be used to determine the numberranges for *
* the internal document number. *
* *
* US_RANGE_INTERN - internal number range *
* *
* This form is called from form BELEG_SICHERN *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_NUMBER_RANGE USING US_RANGE_INTERN.
* Example: Numer range from TVAK like in standard
* US_RANGE_INTERN = TVAK-NUMKI.
ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_PRICING_PREPARE_TKOMK *
*---------------------------------------------------------------------*
* This userexit can be used to move additional fields into the *
* communication table which is used for pricing: *
* *
* TKOMK for header fields *
* *
* This form is called from form PREISFINDUNG_VORBEREITEN. *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_PRICING_PREPARE_TKOMK.
* TKOMK-zzfield = xxxx-zzfield2.
*{ INSERT SGDK900103 1
IF TKOMK-ZZKUKLA IS INITIAL
AND ( SY-TCODE = 'VA01' OR SY-TCODE = 'VA02'
OR SY-TCODE = 'VA21' OR SY-TCODE = 'VA22' ).
DATA : LV_KUKLA TYPE KNA1-KUKLA .
SELECT SINGLE KUKLA
INTO LV_KUKLA
FROM KNA1
WHERE KUNNR = VBAK-KUNNR .
TKOMK-ZZKUKLA = LV_KUKLA .
ENDIF .
IF GIT_XKOMV_OLD[] IS INITIAL AND GIT_XKOMV[] IS INITIAL
AND XKOMV[] IS NOT INITIAL .
GIT_XKOMV_OLD[] = XKOMV[] .
ENDIF .
IF SY-DYNNR = '5002' .
IF SY-TCODE = 'VA01' OR SY-TCODE = 'VA02'.
*******************定价条件****************
DATA : LV_KBETR1 TYPE KOMV-KBETR .
DATA : LV_KBETR2 TYPE KOMV-KBETR .
DATA : LWA_KOMV1 TYPE KOMV .
DATA : LWA_KOMV2 TYPE KOMV .
DATA : LV_MESS(30) TYPE C .
*CLEAR LWA_KOMV1 .
*READ TABLE XKOMV INTO LWA_KOMV1
* WITH KEY KPOSN = TKOMP-KPOSN
* KSCHL = 'ZA00'.
* IF SY-SUBRC = 0 .
* LV_KBETR1 = LWA_KOMV1-KBETR .
* CLEAR LWA_KOMV2 .
* READ TABLE XKOMV INTO LWA_KOMV2
* WITH KEY KPOSN = LWA_KOMV1-KPOSN
* KSCHL = 'ZA01'.
* LV_KBETR2 = LWA_KOMV2-KBETR .
*
* IF LV_KBETR2 < LV_KBETR1 .
* CONCATENATE '行项目' LWA_KOMV1-KPOSN
* ':定价条件ZA00大于ZA01' INTO LV_MESS .
* MESSAGE LV_MESS TYPE 'E' .
* ENDIF .
*
* ENDIF .
*****************赠送额度**********************
TYPES : BEGIN OF ls_zfit006 ,
belny TYPE zfit006-belny,
WRBT2 TYPE zfit006-WRBT2,
END OF ls_zfit006 .
data : lwa_zfit006 TYPE ls_ZFIT006 .
DATA : LIT_ZFIT006 TYPE TABLE OF LS_ZFIT006 .
DATA : LIT_ZFIT006_01 TYPE TABLE OF LS_ZFIT006 .
DATA : LWA_XKOMV TYPE KOMV .
DATA : LWA_XKOMV_01 TYPE KOMV .
DATA : LWA_XVBPA TYPE VBPA .
DATA : LWA_ZFIT002 TYPE ZFIT002 .
DATA : LWA_ZFIT021 TYPE ZFIT021 .
DATA : LWA_ZFIT002_01 TYPE ZFIT002 .
DATA : LIT_ZFIT002 TYPE TABLE OF ZFIT002 .
DATA : LIT_ZFIT021 TYPE TABLE OF ZFIT021 .
DATA : LIT_ZFIT002_01 TYPE TABLE OF ZFIT002 .
DATA : LV_KBETR TYPE KOMV-KBETR ."zkto金额
DATA : LV_KBETR_01 TYPE KOMV-KBETR .
DATA : LV_KBETR_02 TYPE KOMV-KBETR .
DATA : LV_KBETR_03 TYPE KOMV-KBETR ."剩余的赠送额度
DATA : LV_MARK(1) TYPE C ."赠送额度减少标识
***************修改 by 蓝景存 20150818begin**********************************·
****************由单行改为汇总*********************************·
* CLEAR LWA_XKOMV_01 .
* READ TABLE GIT_XKOMV_OLD INTO LWA_XKOMV_01
* WITH KEY KPOSN = '000000'
* KSCHL = 'ZKTO' .
* LWA_XKOMV_01-KBETR = 0 - LWA_XKOMV_01-KBETR .
* CLEAR LWA_XKOMV .
* READ TABLE XKOMV INTO LWA_XKOMV
* WITH KEY KPOSN = '000000'
* KSCHL = 'ZKTO' .
CLEAR LWA_XKOMV_01 .
CLEAR LV_KBETR_01 .
LOOP AT GIT_XKOMV_OLD INTO LWA_XKOMV_01
WHERE KPOSN = '000000'
AND KSCHL = 'ZKTO' .
LV_KBETR_01 = LV_KBETR_01 - LWA_XKOMV_01-KBETR .
CLEAR LWA_XKOMV_01 .
ENDLOOP .
LWA_XKOMV_01-KBETR = LV_KBETR_01 .
CLEAR LV_KBETR_01 .
CLEAR LWA_XKOMV .
LOOP AT XKOMV INTO LWA_XKOMV
WHERE KPOSN = '000000'
AND KSCHL = 'ZKTO' .
LV_KBETR_01 = LV_KBETR_01 - LWA_XKOMV-KBETR .
CLEAR LWA_XKOMV .
ENDLOOP .
LWA_XKOMV-KBETR = LV_KBETR_01.
CLEAR LV_KBETR_01 .
****************由单行改为汇总*********************************·
***************修改 by 蓝景存 20150818end*********************************·
IF SY-SUBRC = 0 OR LWA_XKOMV-KBETR = 0 .
" LWA_XKOMV-KBETR = 0 - LWA_XKOMV-KBETR .
LV_KBETR_01 = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
IF LV_KBETR_01 > 0 .
"LWA_XKOMV-KBETR = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
LV_KBETR = LWA_XKOMV-KBETR .
IF SY-SUBRC = 0 .
READ TABLE XVBPA INTO LWA_XVBPA
WITH KEY POSNR = '000000'
PARVW = 'RG' .
IF SY-SUBRC = 0 .
"取出赠送额度
LV_KBETR_02 = 0 .
SELECT *
FROM ZFIT002
INTO TABLE LIT_ZFIT002
WHERE KUNNK = LWA_XVBPA-KUNNR
* AND WRBYY = LV_KBETR_02 "预存款核销余额为0 才可以使用赠送
AND KUNNS = XVBAK-KUNNR
******************修改by蓝景存20150919*********************************
******************已使用完的也要参与运算*********************************
" AND markz = ''"赠送额度余额标识 为空为未用完
*******************************************************
and MARKR = ''."删除标识
IF SY-SUBRC = 0 .
LIT_ZFIT002_01[] = LIT_ZFIT002[] .
"一个发票可能对应多个收款凭证清除相同项
SORT LIT_ZFIT002_01 BY BELNY ASCENDING.
DELETE ADJACENT DUPLICATES FROM LIT_ZFIT002_01
COMPARING BELNY .
"计算预存款发票是否已使用完
IF LIT_ZFIT002_01[] IS NOT INITIAL .
CLEAR LIT_ZFIT006[] .
SELECT
BELNY
WRBT2
FROM ZFIT006
INTO TABLE LIT_ZFIT006
FOR ALL ENTRIES IN LIT_ZFIT002_01
WHERE BELNY = LIT_ZFIT002_01-BELNY
AND ( MARKX = '' OR MARKD = '' )
and MARKF = '' .
CLEAR LIT_ZFIT006_01[] .
CLEAR LWA_ZFIT006 .
LOOP AT LIT_ZFIT006 INTO LWA_ZFIT006 .
COLLECT LWA_ZFIT006 INTO LIT_ZFIT006_01 .
CLEAR LWA_ZFIT006 .
ENDLOOP .
CLEAR LIT_ZFIT006[] .
LIT_ZFIT006[] = LIT_ZFIT006_01[] .
ENDIF .
"取出已使用额度
CLEAR LIT_ZFIT021[] .
SELECT *
FROM ZFIT021
INTO TABLE LIT_ZFIT021
WHERE KUNAG = XVBAK-KUNNR
and KUNRG = LWA_XVBPA-KUNNR
and VBELN <> XVBAK-VBELN .
CLEAR LWA_ZFIT002_01 .
"检查赠送额度是否够用
CLEAR LV_KBETR_03 .
****************** 剩余可用赠送额度
LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 ."zfit002中总的剩余赠送额度
* 剩余总的赠送金额 累加 = 赠送金额-已经赠送金额
LV_KBETR_03 = LV_KBETR_03 +
( LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH )."此次使用赠送 减去 预存款合同对应剩余赠送金额
CLEAR LWA_ZFIT002_01 .
ENDLOOP .
****************** 剩余可用赠送额度
CLEAR LWA_ZFIT021 .
LOOP AT LIT_ZFIT021 INTO LWA_ZFIT021 ."ZFIT021已使用金额??
* 剩余赠送额度 = 剩余赠送额度 - 已使用额度
LV_KBETR_03 = LV_KBETR_03 - LWA_ZFIT021-KBETR .
CLEAR LWA_ZFIT021 .
ENDLOOP .
*****************************本次需要赠送-可用赠送额度
LWA_XKOMV-KBETR = LWA_XKOMV-KBETR - LV_KBETR_03 .
IF LWA_XKOMV-KBETR <= 0 ."赠送额度足够
"检查预存款全用完后的赠送额度是否够用
CLEAR LWA_ZFIT002_01 .
LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 ." 预存款 赠送 清单
CLEAR LWA_ZFIT006 .
READ TABLE LIT_ZFIT006 INTO LWA_ZFIT006"已使用预存款金额
WITH KEY BELNY = LWA_ZFIT002_01-BELNY .
CHECK LWA_ZFIT002_01-WRBTY + LWA_ZFIT006-WRBT2 = 0 ."预存款金额 - 已使用预存款金额 = 0 说明已经使用完预存款 ,可以使用赠送金额
LV_KBETR = LV_KBETR -
( LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH )."此次使用赠送 减去 预存款合同对应剩余赠送金额
CLEAR LWA_ZFIT021 .
LOOP AT LIT_ZFIT021 INTO LWA_ZFIT021 WHERE BELNY = LWA_ZFIT002_01-BELNY ."ZFIT021已使用金额
LV_KBETR = LV_KBETR + LWA_ZFIT021-KBETR .
CLEAR LWA_ZFIT021 .
ENDLOOP .
IF LV_KBETR <= 0 .
EXIT .
ENDIF .
CLEAR LWA_ZFIT002_01 .
ENDLOOP .
IF LV_KBETR > 0 .
MESSAGE '存在预存款未使用完的赠送额度' TYPE 'S' DISPLAY LIKE 'W' .
ENDIF .
GV_MARKZ = 'X' .
ELSE .
GV_MARKZ = '' .
MESSAGE '赠送额度不够使用' TYPE 'S' DISPLAY LIKE 'E' .
DELETE XKOMV WHERE KPOSN = TKOMP-KPOSN
AND KSCHL = 'ZKTO' .
ENDIF .
ELSE .
GV_MARKZ = '' .
MESSAGE '没有可使用的赠送额度' TYPE 'S' DISPLAY LIKE 'E'.
DELETE XKOMV WHERE KPOSN = TKOMP-KPOSN
AND KSCHL = 'ZKTO' .
ENDIF .
ENDIF .
ENDIF .
ELSEIF LV_KBETR_01 = 0 ."相等不处理
GV_MARKZ = '' .
ELSE ."小于0减少
LWA_XKOMV-KBETR = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
LWA_XKOMV-KBETR = 0 - LWA_XKOMV-KBETR .
LV_KBETR = LWA_XKOMV-KBETR .
LV_MARK = 'X' .
GV_MARKZ = 'X' .
ENDIF .
ELSE .
IF LWA_XKOMV_01-KBETR <> 0 ."赠送额度不需要了
LV_KBETR = LWA_XKOMV_01-KBETR .
LV_MARK = 'X' .
GV_MARKZ = 'X' .
ENDIF .
ENDIF .
ENDIF .
ENDIF .
*} INSERT
ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_PRICING_PREPARE_TKOMP *
*---------------------------------------------------------------------*
* This userexit can be used to move additional fields into the *
* communication table which is used for pricing: *
* *
* TKOMP for item fields *
* *
* This form is called from form PREISFINDUNG_VORBEREITEN. *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_PRICING_PREPARE_TKOMP.
* TKOMP-zzfield = xxxx-zzfield2.
*{ INSERT SGDK900103 1
*IF GIT_XKOMV_OLD[] IS INITIAL AND GIT_XKOMV[] IS INITIAL
* AND XKOMV[] IS NOT INITIAL .
* GIT_XKOMV_OLD[] = XKOMV[] .
*ENDIF .
*IF SY-DYNNR = '5003' .
* IF SY-TCODE = 'VA01' OR SY-TCODE = 'VA02'.
********************定价条件****************
*DATA : LV_KBETR1 TYPE KOMV-KBETR .
*DATA : LV_KBETR2 TYPE KOMV-KBETR .
*DATA : LWA_KOMV1 TYPE KOMV .
*DATA : LWA_KOMV2 TYPE KOMV .
*DATA : LV_MESS(30) TYPE C .
*
**CLEAR LWA_KOMV1 .
**READ TABLE XKOMV INTO LWA_KOMV1
** WITH KEY KPOSN = TKOMP-KPOSN
** KSCHL = 'ZA00'.
** IF SY-SUBRC = 0 .
** LV_KBETR1 = LWA_KOMV1-KBETR .
** CLEAR LWA_KOMV2 .
** READ TABLE XKOMV INTO LWA_KOMV2
** WITH KEY KPOSN = LWA_KOMV1-KPOSN
** KSCHL = 'ZA01'.
** LV_KBETR2 = LWA_KOMV2-KBETR .
**
** IF LV_KBETR2 < LV_KBETR1 .
** CONCATENATE '行项目' LWA_KOMV1-KPOSN
** ':定价条件ZA00大于ZA01' INTO LV_MESS .
** MESSAGE LV_MESS TYPE 'E' .
** ENDIF .
**
** ENDIF .
*
*
*
******************赠送额度**********************
* DATA : LWA_XKOMV TYPE KOMV .
* DATA : LWA_XKOMV_01 TYPE KOMV .
* DATA : LWA_XVBPA TYPE VBPA .
* DATA : LWA_ZFIT002 TYPE ZFIT002 .
* DATA : LWA_ZFIT002_01 TYPE ZFIT002 .
* DATA : LIT_ZFIT002 TYPE TABLE OF ZFIT002 .
* DATA : LIT_ZFIT002_01 TYPE TABLE OF ZFIT002 .
* DATA : LV_KBETR TYPE KOMV-KBETR .
* DATA : LV_KBETR_01 TYPE KOMV-KBETR .
* DATA : LV_KBETR_02 TYPE KOMV-KBETR .
* DATA : LV_MARK(1) TYPE C ."赠送额度减少标识
* CLEAR LWA_XKOMV_01 .
* READ TABLE GIT_XKOMV_OLD INTO LWA_XKOMV_01
* WITH KEY KPOSN = TKOMP-KPOSN
* KSCHL = 'ZKTO' .
* LWA_XKOMV_01-KBETR = 0 - LWA_XKOMV_01-KBETR .
* READ TABLE XKOMV INTO LWA_XKOMV
* WITH KEY KPOSN = TKOMP-KPOSN
* KSCHL = 'ZKTO' .
* IF SY-SUBRC = 0.
* LWA_XKOMV-KBETR = 0 - LWA_XKOMV-KBETR .
* LV_KBETR_01 = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
* IF LV_KBETR_01 > 0 .
* LWA_XKOMV-KBETR = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
* LV_KBETR = LWA_XKOMV-KBETR .
* IF SY-SUBRC = 0 .
* READ TABLE XVBPA INTO LWA_XVBPA
* WITH KEY POSNR = '000000'
* PARVW = 'RG' .
* IF SY-SUBRC = 0 .
* "取出赠送额度
* LV_KBETR_02 = 0 .
* SELECT *
* FROM ZFIT002
* INTO TABLE LIT_ZFIT002
* WHERE KUNNK = LWA_XVBPA-KUNNR
** AND WRBYY = LV_KBETR_02 "预存款核销余额为0 才可以使用赠送
* AND KUNNS = XVBAK-KUNNR
* AND markz = ''"赠送额度余额标识 为空为未用完
* and MARKR = ''."删除标识
* IF SY-SUBRC = 0 .
* LIT_ZFIT002_01[] = LIT_ZFIT002[] .
* "一个发票可能对应多个收款凭证清除相同项
* SORT LIT_ZFIT002_01 BY BELNY ASCENDING.
* DELETE ADJACENT DUPLICATES FROM LIT_ZFIT002_01
* COMPARING BELNY .
*
* CLEAR LWA_ZFIT002_01 .
* "检查赠送额度是否够用
* LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 .
* LWA_XKOMV-KBETR = LWA_XKOMV-KBETR -
* ( LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH )."此次使用赠送 减去 预存款合同对应剩余赠送金额
* IF LWA_XKOMV-KBETR <= 0 .
* EXIT .
* ENDIF .
* CLEAR LWA_ZFIT002_01 .
* ENDLOOP .
*
* IF LWA_XKOMV-KBETR <= 0 ."赠送额度足够
*
* "检查预存款全用完后的赠送额度是否够用
* CLEAR LWA_ZFIT002_01 .
*
* LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 WHERE WRBYY = 0 .
* LV_KBETR = LV_KBETR -
* ( LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH )."此次使用赠送 减去 预存款合同对应剩余赠送金额
* IF LV_KBETR <= 0 .
* EXIT .
* ENDIF .
* CLEAR LWA_ZFIT002_01 .
* ENDLOOP .
* IF LV_KBETR > 0 .
* MESSAGE '存在预存款未使用完的赠送额度' TYPE 'S' DISPLAY LIKE 'W' .
* ENDIF .
** LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 .
** IF LV_KBETR <= 0 .
** EXIT .
** ENDIF .
** IF LV_KBETR >= LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH ."
** LV_KBETR = LV_KBETR - ( LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH ).
** LWA_ZFIT002_01-WRBZH = LWA_ZFIT002_01-WRBTZ ."预存款全都核销完
** LWA_ZFIT002_01-WRBZY = 0 .
** LWA_ZFIT002_01-MARKZ = 'X' .
** MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
** TRANSPORTING WRBZH WRBZY MARKZ
** WHERE BELNY = LWA_ZFIT002_01-BELNY .
** ELSE .
**
** LWA_ZFIT002_01-WRBZH = LWA_ZFIT002_01-WRBZH + LV_KBETR .
** LWA_ZFIT002_01-WRBZY = LWA_ZFIT002_01-WRBZY - LV_KBETR .
** MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
** TRANSPORTING WRBZH WRBZY MARKZ
** WHERE BELNY = LWA_ZFIT002_01-BELNY .
** LV_KBETR = 0 .
**
** ENDIF.
** CLEAR LWA_ZFIT002_01 .
** ENDLOOP .
**
** MODIFY ZFIT002 FROM TABLE LIT_ZFIT002 .
** COMMIT WORK AND WAIT .
* GV_MARKZ = 'X' .
* ELSE .
* GV_MARKZ = '' .
* MESSAGE '赠送额度不够使用' TYPE 'S' DISPLAY LIKE 'E' .
* DELETE XKOMV WHERE KPOSN = TKOMP-KPOSN
* AND KSCHL = 'ZKTO' .
* " EXIT .
* ENDIF .
* ELSE .
* GV_MARKZ = '' .
* MESSAGE '没有可使用的赠送额度' TYPE 'S' DISPLAY LIKE 'E'.
* DELETE XKOMV WHERE KPOSN = TKOMP-KPOSN
* AND KSCHL = 'ZKTO' .
* " LEAVE LIST-PROCESSING .
* " EXIT .
* ENDIF .
* ENDIF .
*
* ENDIF .
* ELSEIF LV_KBETR_01 = 0 ."相等不处理
* GV_MARKZ = '' .
* ELSE ."小于0减少
* LWA_XKOMV-KBETR = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
* LWA_XKOMV-KBETR = 0 - LWA_XKOMV-KBETR .
* LV_KBETR = LWA_XKOMV-KBETR .
* LV_MARK = 'X' .
* GV_MARKZ = 'X' .
* ENDIF .
*
* ELSE .
* IF LWA_XKOMV_01-KBETR <> 0 ."赠送额度不需要了
* LV_KBETR = LWA_XKOMV_01-KBETR .
* LV_MARK = 'X' .
* GV_MARKZ = 'X' .
* ENDIF .
*
* ENDIF .
*
**********************************************
** IF LV_MARK = 'X' .
** READ TABLE XVBPA INTO LWA_XVBPA
** WITH KEY POSNR = '000000'
** PARVW = 'RG' .
** IF SY-SUBRC = 0 .
** SELECT *
** FROM ZFIT002
** INTO TABLE LIT_ZFIT002
** WHERE KUNNK = LWA_XVBPA-KUNNR
** AND WRBZH <> 0 .
** IF SY-SUBRC = 0 .
** LIT_ZFIT002_01[] = LIT_ZFIT002[] .
** SORT LIT_ZFIT002_01 BY BELNY DESCENDING.
** DELETE ADJACENT DUPLICATES FROM LIT_ZFIT002_01
** COMPARING BELNY .
** CLEAR LWA_ZFIT002_01 .
** LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 .
** IF LV_KBETR <= 0 .
** EXIT .
** ENDIF .
** IF LV_KBETR >= LWA_ZFIT002_01-WRBZH ."LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH
** LV_KBETR = LV_KBETR - LWA_ZFIT002_01-WRBZH .
** LWA_ZFIT002_01-WRBZH = 0 ."预存款核销为0
** LWA_ZFIT002_01-WRBZY = LWA_ZFIT002_01-WRBTZ .
** LWA_ZFIT002_01-MARKZ = '' .
** MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
** TRANSPORTING WRBZH WRBZY MARKZ
** WHERE BELNY = LWA_ZFIT002_01-BELNY .
** ELSE .
**
** LWA_ZFIT002_01-WRBZH = LWA_ZFIT002_01-WRBZH - LV_KBETR .
** LWA_ZFIT002_01-WRBZY = LWA_ZFIT002_01-WRBZY + LV_KBETR .
** MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
** TRANSPORTING WRBZH WRBZY MARKZ
** WHERE BELNY = LWA_ZFIT002_01-BELNY .
** LV_KBETR = 0 .
**
** ENDIF.
** CLEAR LWA_ZFIT002_01 .
** ENDLOOP .
**
** ENDIF .
**
** ENDIF .
**
** ENDIF.
*******************************8
*ENDIF .
*ENDIF .
*} INSERT
ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_READ_DOCUMENT *
*---------------------------------------------------------------------*
* This userexit can be used to read data in additional tables *
* when the program reads a sales document. *
* *
* This form is called at the end of form BELEG_LESEN. *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_READ_DOCUMENT.
ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_SAVE_DOCUMENT *
*---------------------------------------------------------------------*
* This userexit can be used to save data in additional tables *
* when a document is saved. *
* *
* If field T180-TRTYP contents 'H', the document will be *
* created, else it will be changed. *
* *
* This form is called at from form BELEG_SICHERN, before COMMIT *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_SAVE_DOCUMENT.
* Example:
* CALL FUNCTION 'ZZ_EXAMPLE'
* IN UPDATE TASK
* EXPORTING
* ZZTAB = ZZTAB.
*{ INSERT SGDK900103 1
DATA : GWA_ZSDT002 TYPE ZSDT002 .
IF SY-TCODE = 'VA02' OR SY-TCODE = 'VA01' .
FIELD-SYMBOLS: <ASSTX> TYPE ANY.
ASSIGN ('(SAPMV45A)RV45A-ASTTX') TO <ASSTX>.
IF SY-SUBRC = 0 .
IF <ASSTX> = 'Z20' OR <ASSTX> = 'Z30'
OR <ASSTX> = 'Z40'.
" DATA : GWA_ZSDT002 TYPE ZSDT002 .
GWA_ZSDT002-VBELN = VBAK-VBELN .
CASE <ASSTX> .
WHEN 'Z20' .
GWA_ZSDT002-STONR = '20' .
WHEN 'Z30' .
GWA_ZSDT002-STONR = '30' .
WHEN 'Z40' .
GWA_ZSDT002-STONR = '40' .
ENDCASE .
MODIFY ZSDT002 FROM GWA_ZSDT002 .
COMMIT WORK AND WAIT .
CALL FUNCTION 'BP_EVENT_RAISE'
EXPORTING
eventid = 'Z_VA02'
* EVENTPARM = ' '
* TARGET_INSTANCE = ' '
* TARGET_MODE = ' '
EXCEPTIONS
BAD_EVENTID = 1
EVENTID_DOES_NOT_EXIST = 2
EVENTID_MISSING = 3
RAISE_FAILED = 4
OTHERS = 5 .
endif .
ENDIF .
ENDIF .
**************************************************
*if SY-TCODE = 'VA21' OR SY-TCODE = 'VA22' .
*DATA : LV_KBETR11 TYPE KOMV-KBETR .
*DATA : LV_KBETR22 TYPE KOMV-KBETR .
*DATA : LWA_KOMV11 TYPE KOMV .
*DATA : LWA_KOMV22 TYPE KOMV .
*DATA : LV_mark33(1) TYPE c .
*
*CLEAR LWA_KOMV11 .
*LOOP AT XKOMV INTO LWA_KOMV11
* WHERE KSCHL = 'PR01'.
*
* LV_KBETR11 = LWA_KOMV11-KBETR .
* CLEAR LWA_KOMV22 .
* LOOP AT XKOMV INTO LWA_KOMV22
* WHERE KPOSN = LWA_KOMV11-KPOSN
* AND KSCHL = 'ZRA2'.
* LV_KBETR22 = LWA_KOMV22-KBETR .
*
* IF LV_KBETR22 > LV_KBETR11 .
* LV_mark33 = 'X' .
* ENDIF .
* CLEAR LWA_KOMV22.
* ENDLOOP .
* CLEAR LWA_KOMV11 .
*ENDLOOP .
*
*
*if LV_mark33 = '' .
* "DATA : GWA_ZSDT002 TYPE ZSDT002 .
* GWA_ZSDT002-VBELN = VBAK-VBELN .
* GWA_ZSDT002-STONR = '20' .
* MODIFY ZSDT002 FROM GWA_ZSDT002 .
* COMMIT WORK AND WAIT .
* CALL FUNCTION 'BP_EVENT_RAISE'
* EXPORTING
* eventid = 'Z_VA02'
** EVENTPARM = ' '
** TARGET_INSTANCE = ' '
** TARGET_MODE = ' '
* EXCEPTIONS
* BAD_EVENTID = 1
* EVENTID_DOES_NOT_EXIST = 2
* EVENTID_MISSING = 3
* RAISE_FAILED = 4
* OTHERS = 5 .
*ENDIF .
*endif .
***************************************************
IF GV_MARKZ = 'X' .
TYPES : BEGIN OF ls_zfit006 ,
belny TYPE zfit006-belny,
WRBT2 TYPE zfit006-WRBT2,
END OF ls_zfit006 .
data : lwa_zfit006 TYPE ls_ZFIT006 .
DATA : LIT_ZFIT006 TYPE TABLE OF LS_ZFIT006 .
DATA : LIT_ZFIT006_01 TYPE TABLE OF LS_ZFIT006 .
DATA : LWA_XKOMV TYPE KOMV .
DATA : LWA_XKOMV_01 TYPE KOMV .
DATA : LWA_XVBPA TYPE VBPA .
DATA : LWA_ZFIT002 TYPE ZFIT002 .
DATA : LWA_ZFIT002_01 TYPE ZFIT002 .
DATA : LIT_ZFIT002 TYPE TABLE OF ZFIT002 .
DATA : LIT_ZFIT002_01 TYPE TABLE OF ZFIT002 .
DATA : LIT_ZFIT002_02 TYPE TABLE OF ZFIT002 .
DATA : LV_KBETR TYPE KOMV-KBETR .
DATA : LV_KBETR_01 TYPE KOMV-KBETR .
DATA : LV_KBETR_02 TYPE KOMV-KBETR .
DATA : LV_KBETR_03 TYPE KOMV-KBETR .
DATA : LV_MARK(1) TYPE C ."赠送额度减少标识
DATA : LWA_ZFIT021 TYPE ZFIT021 .
DATA : LIT_ZFIT021 TYPE TABLE OF ZFIT021 .
DATA : LIT_ZFIT021_01 TYPE TABLE OF ZFIT021 ."检查删除有本订单的记录
DATA : LIT_ZFIT021_02 TYPE TABLE OF ZFIT021 ."新增的记录记录
DATA : LIT_KOMP TYPE TABLE OF KOMP .
DATA : LWA_KOMP TYPE KOMP .
IF SY-TCODE = 'VA01' OR SY-TCODE = 'VA02'.
CLEAR LWA_XKOMV_01 .
" LIT_KOMP[] = TKOMP[] .
* SORT LIT_KOMP BY KPOSN .
* DELETE ADJACENT DUPLICATES FROM LIT_KOMP
* COMPARING KPOSN .
" DELETE LIT_KOMP WHERE KPOSN <> '000000' .
" DELETE LIT_KOMP WHERE KSCHL <> 'ZKTO' .
" CLEAR LWA_KOMP .
" LOOP AT LIT_KOMP INTO LWA_KOMP .
***************修改 by 蓝景存 20150818begin**********************************·
****************由单行改为汇总*********************************·
* CLEAR LWA_XKOMV_01 .
* READ TABLE GIT_XKOMV_OLD INTO LWA_XKOMV_01
* WITH KEY KPOSN = '000000'
* KSCHL = 'ZKTO' .
* LWA_XKOMV_01-KBETR = 0 - LWA_XKOMV_01-KBETR .
* CLEAR LWA_XKOMV .
* READ TABLE XKOMV INTO LWA_XKOMV
* WITH KEY KPOSN = '000000'
* KSCHL = 'ZKTO' .
CLEAR LWA_XKOMV_01 .
CLEAR LV_KBETR_01 .
LOOP AT GIT_XKOMV_OLD INTO LWA_XKOMV_01
WHERE KPOSN = '000000'
AND KSCHL = 'ZKTO' .
LV_KBETR_01 = LV_KBETR_01 - LWA_XKOMV_01-KBETR .
CLEAR LWA_XKOMV_01 .
ENDLOOP .
LWA_XKOMV_01-KBETR = LV_KBETR_01 .
CLEAR LV_KBETR_01 .
CLEAR LWA_XKOMV .
LOOP AT XKOMV INTO LWA_XKOMV
WHERE KPOSN = '000000'
AND KSCHL = 'ZKTO' .
LV_KBETR_01 = LV_KBETR_01 - LWA_XKOMV-KBETR .
CLEAR LWA_XKOMV .
ENDLOOP .
LWA_XKOMV-KBETR = LV_KBETR_01.
CLEAR LV_KBETR_01 .
****************由单行改为汇总*********************************·
***************修改 by 蓝景存 20150818end*****************************
IF SY-SUBRC = 0 OR LWA_XKOMV-KBETR = 0.
" LWA_XKOMV-KBETR = 0 - LWA_XKOMV-KBETR .
LV_KBETR_01 = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
IF LV_KBETR_01 > 0 .
LWA_XKOMV-KBETR = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
LV_KBETR = LWA_XKOMV-KBETR .
IF SY-SUBRC = 0 .
READ TABLE XVBPA INTO LWA_XVBPA
WITH KEY POSNR = '000000'
PARVW = 'RG' .
IF SY-SUBRC = 0 .
"取出赠送额度
LV_KBETR_02 = 0 .
SELECT *
FROM ZFIT002
INTO TABLE LIT_ZFIT002
WHERE KUNNK = LWA_XVBPA-KUNNR
" AND WRBYY = LV_KBETR_02 "预存款核销余额为0 才可以使用赠送
AND KUNNS = VBAK-KUNNR
******************修改by蓝景存20150919*********************************
******************已使用完的也要参与运算*********************************
" AND markz = ''"赠送额度余额标识 为空为未用完
*******************************************************
and MARKR = ''."删除标识
IF SY-SUBRC = 0 .
LIT_ZFIT002_01[] = LIT_ZFIT002[] .
"一个发票可能对应多个收款凭证清除相同项
SORT LIT_ZFIT002_01 BY BELNY ASCENDING.
DELETE ADJACENT DUPLICATES FROM LIT_ZFIT002_01
COMPARING BELNY .
"计算预存款发票是否已使用完
IF LIT_ZFIT002_01[] IS NOT INITIAL .
CLEAR LIT_ZFIT006[] .
SELECT
BELNY
WRBT2
FROM ZFIT006
INTO TABLE LIT_ZFIT006
FOR ALL ENTRIES IN LIT_ZFIT002_01
WHERE BELNY = LIT_ZFIT002_01-BELNY
AND ( MARKX = '' OR MARKD = '' )
and MARKF = '' .
CLEAR LIT_ZFIT006_01[] .
CLEAR LWA_ZFIT006 .
LOOP AT LIT_ZFIT006 INTO LWA_ZFIT006 .
COLLECT LWA_ZFIT006 INTO LIT_ZFIT006_01 .
CLEAR LWA_ZFIT006 .
ENDLOOP .
CLEAR LIT_ZFIT006[] .
LIT_ZFIT006[] = LIT_ZFIT006_01[] .
ENDIF .
"取出已使用额度
CLEAR LIT_ZFIT021[] .
SELECT *
FROM ZFIT021
INTO TABLE LIT_ZFIT021
WHERE KUNAG = VBAK-KUNNR
and KUNRG = LWA_XVBPA-KUNNR
and VBELN <> XVBAK-VBELN .
"获取要删除本订单
LIT_ZFIT021_01[] = LIT_ZFIT021[] ."
DELETE LIT_ZFIT021_01 WHERE VBELN <> XVBAK-VBELN .
delete zfit021 FROM TABLE LIT_ZFIT021_01 .
COMMIT WORK .
"获取不包含本单的已核销数据
delete LIT_ZFIT021 WHERE VBELN = XVBAK-VBELN .
****************************修改by蓝景存 20151004*************************************
****************************处理优先级问题 begin*************************************
* CLEAR LWA_ZFIT002_01 .
* "检查赠送额度是否够用
* LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 ."检查预存款使用情况
* CLEAR LWA_ZFIT006 .
* READ TABLE LIT_ZFIT006 INTO LWA_ZFIT006
* WITH KEY BELNY = LWA_ZFIT002_01-BELNY .
* LWA_ZFIT002_01-WRBYY = LWA_ZFIT002_01-WRBTY + LWA_ZFIT006-WRBT2 .
* APPEND LWA_ZFIT002_01 to Lit_ZFIT002_02 .
* CLEAR LWA_ZFIT002_01 .
* ENDLOOP .
* CLEAR LIT_ZFIT002_01[] .
* LIT_ZFIT002_01[] = LIT_ZFIT002_02[] .
* SORT LIT_ZFIT002_01 BY WRBYY ASCENDING BELNY ASCENDING."优先使用预存款使用完的赠送金额
CLEAR LWA_ZFIT002_01 .
"检查赠送额度是否够用
loop at lit_zfit002_01 into lwa_zfit002_01 ."检查预存款使用情况
clear lwa_zfit006 .
" 计算已核销 找发票是否核销过 ,1核销为0的,金额小的先,按小到大
lwa_zfit002_01-WRBYH = 0."拿来排序用leo
loop at lit_zfit006 into lwa_zfit006
where belny = lwa_zfit002_01-belny .
lwa_zfit002_01-WRBYH = lwa_zfit002_01-WRBYH + lwa_zfit006-wrbt2 .
* lwa_zfit002_01-wrbyy = lwa_zfit002_01-wrbty + lwa_zfit006-wrbt2 .
clear lwa_zfit006 .
endloop .
"计算已使用 找发票是否赠送过,已经赠送过的先选,那么按大到小
clear lwa_zfit021 .
lwa_zfit002_01-WRBSH = 0 ."拿来排序用leo
loop at lit_zfit021 into lwa_zfit021
where belny = lwa_zfit002_01-belny .
* lwa_zfit002_01-wrbzh = lwa_zfit002_01-wrbzh + lwa_zfit021-kbetr .
lwa_zfit002_01-WRBSH = lwa_zfit002_01-WRBSH + lwa_zfit021-kbetr .
clear lwa_zfit021 .
endloop .
append lwa_zfit002_01 to lit_zfit002_02 .
clear lwa_zfit002_01 .
endloop .
CLEAR LIT_ZFIT002_01[] .
LIT_ZFIT002_01[] = LIT_ZFIT002_02[] .
* SORT LIT_ZFIT002_01 BY WRBZH DESCENDING WRBYY ASCENDING BELNY ASCENDING."优先使用已使用过后是预存款使用完的赠送金额
sort lit_zfit002_01 by WRBSH descending WRBYH ascending belny ascending."优先使用已使用过后是预存款使用完的赠送金额leo
****************************修改by蓝景存 20151004*************************************
****************************处理优先级问题end*************************************
LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 .
LWA_XKOMV-KBETR = LWA_XKOMV-KBETR -
( LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH )."此次使用赠送 减去 预存款合同对应剩余赠送金额
CLEAR LWA_ZFIT021 .
LOOP AT LIT_ZFIT021 INTO LWA_ZFIT021 WHERE BELNY = LWA_ZFIT002_01-BELNY ."ZFIT021已使用金额
LWA_XKOMV-KBETR = LWA_XKOMV-KBETR + LWA_ZFIT021-KBETR .
CLEAR LWA_ZFIT021 .
ENDLOOP .
IF LWA_XKOMV-KBETR <= 0 .
EXIT .
ENDIF .
CLEAR LWA_ZFIT002_01 .
ENDLOOP .
IF LWA_XKOMV-KBETR <= 0 ."赠送额度足够
***************LV_KBETR 原为差异值 现给当前值***********************
****************修改 BY 蓝景存 20150813*****************************
CLEAR LV_KBETR .
LOOP AT XKOMV
WHERE KPOSN = '000000'
AND KSCHL = 'ZKTO' .
LV_KBETR = LV_KBETR - XKOMV-KBETR .
CLEAR LWA_XKOMV .
ENDLOOP .
*******************************************************************
LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 .
IF LV_KBETR <= 0 .
EXIT .
ENDIF .
LV_KBETR_03 = LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH ."这张发票可用的赠送金额
CLEAR LWA_ZFIT021 .
LOOP AT LIT_ZFIT021 INTO LWA_ZFIT021 WHERE BELNY = LWA_ZFIT002_01-BELNY ."ZFIT021已使用金额
LV_KBETR_03 = LV_KBETR_03 - LWA_ZFIT021-KBETR .
CLEAR LWA_ZFIT021 .
ENDLOOP .
CHECK LV_KBETR_03 <> 0."可用赠送金额 等于0,跳过这张发票
CLEAR LWA_ZFIT021 .
IF LV_KBETR >= LV_KBETR_03 ."
LV_KBETR = LV_KBETR - LV_KBETR_03.
LWA_ZFIT002_01-MARKZ = 'X' .
MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
TRANSPORTING MARKZ
WHERE BELNY = LWA_ZFIT002_01-BELNY .
LWA_ZFIT021-KBETR = LV_KBETR_03 .
ELSE .
* LWA_ZFIT002_01-WRBZH = LWA_ZFIT002_01-WRBZH + LV_KBETR .
* LWA_ZFIT002_01-WRBZY = LWA_ZFIT002_01-WRBZY - LV_KBETR .
* MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
* TRANSPORTING WRBZH WRBZY MARKZ
* WHERE BELNY = LWA_ZFIT002_01-BELNY .
LWA_ZFIT021-KBETR = LV_KBETR .
LV_KBETR = 0 .
ENDIF.
LWA_ZFIT021-MANDT = sy-mandt .
LWA_ZFIT021-BELNY = LWA_ZFIT002_01-BELNY .
LWA_ZFIT021-VBELN = VBAK-VBELN .
LWA_ZFIT021-POSNR = '000000'.
LWA_ZFIT021-KUNAG = VBAK-kunnr .
LWA_ZFIT021-KUNRG = LWA_XVBPA-KUNNR .
LWA_ZFIT021-WAERS = VBAK-waerk .
LWA_ZFIT021-ERDAT = SY-datum."新建时间
APPEND LWA_ZFIT021 to Lit_ZFIT021_02 .
CLEAR LWA_ZFIT002_01 .
ENDLOOP .
MODIFY ZFIT002 FROM TABLE LIT_ZFIT002 .
COMMIT WORK AND WAIT .
MODIFY zfit021 FROM TABLE LIT_ZFIT021_02 .
COMMIT WORK .
ELSE .
MESSAGE '赠送额度不够使用' TYPE 'E' .
EXIT .
ENDIF .
ENDIF .
ENDIF .
ENDIF .
ELSEIF LV_KBETR_01 = 0 ."相等不处理
ELSE ."小于0减少
* LWA_XKOMV-KBETR = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
* LWA_XKOMV-KBETR = 0 - LWA_XKOMV-KBETR .
* LV_KBETR = LWA_XKOMV-KBETR .
* LV_MARK = 'X' .
SELECT *
FROM zfit021
INTO TABLE lit_zfit021
WHERE vbeln = vbak-vbeln .
IF SY-SUBRC = 0 .
"减少的金额: 最后更新金额 减去 老金额
LWA_XKOMV-KBETR = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
SORT lit_zfit021 BY KBETR DESCENDING ."优先减去金额大的
CLEAR LWA_ZFIT021 .
LOOP AT lit_zfit021 INTO LWA_ZFIT021.
LWA_XKOMV-KBETR = LWA_ZFIT021-KBETR + LWA_XKOMV-KBETR .
IF LWA_XKOMV-KBETR > 0 .
LWA_ZFIT021-KBETR = LWA_XKOMV-KBETR .
APPEND LWA_ZFIT021 TO lit_zfit021_02 ."需要更改的表
EXIT .
ELSE .
APPEND LWA_ZFIT021 TO lit_zfit021_01 ."需要删除的表
ENDIF .
ENDLOOP .
CLEAR LIT_ZFIT021[] .
IF lit_zfit021_01[] IS NOT INITIAL .
DELETE ZFIT021 FROM TABLE lit_zfit021_01 ."删除已核销的记录
COMMIT WORK .
APPEND LINES OF lit_zfit021_01 TO lit_zfit021 .
ENDIF .
IF lit_zfit021_02[] IS NOT INITIAL .
MODIFY ZFIT021 FROM TABLE lit_zfit021_02 ."更改已核销的记录
COMMIT WORK .
APPEND LINES OF lit_zfit021_01 TO lit_zfit021 .
ENDIF .
SORT lit_zfit021 BY BELNY .
DELETE ADJACENT DUPLICATES FROM lit_zfit021
COMPARING BELNY .
SELECT *
FROM ZFIT002
INTO TABLE LIT_ZFIT002
FOR ALL ENTRIES IN lit_zfit021
WHERE BELNY = lit_zfit021-BELNY
AND MARKZ = 'X'.
IF SY-SUBRC = 0 .
CLEAR LWA_ZFIT002 .
CLEAR LIT_ZFIT002_01[] .
LOOP AT LIT_ZFIT002 INTO LWA_ZFIT002 .
LWA_ZFIT002-MARKZ = ''.
APPEND LWA_ZFIT002 TO LIT_ZFIT002_01 .
CLEAR LWA_ZFIT002 .
ENDLOOP .
MODIFY ZFIT002 FROM TABLE LIT_ZFIT002_01 .
COMMIT WORK .
ENDIF .
ENDIF .
ENDIF .
ELSE .
IF LWA_XKOMV_01-KBETR <> 0 ."赠送额度不需要了
* LV_KBETR = LWA_XKOMV_01-KBETR .
* LV_MARK = 'X' .
SELECT *
FROM zfit021
INTO TABLE lit_zfit021_01
WHERE vbeln = vbak-vbeln .
IF SY-SUBRC = 0 .
DELETE ZFIT021 FROM TABLE lit_zfit021_01 ."删除已核销的记录
COMMIT WORK .
SORT lit_zfit021_01 BY BELNY .
DELETE ADJACENT DUPLICATES FROM lit_zfit021_01
COMPARING BELNY .
SELECT *
FROM ZFIT002
INTO TABLE LIT_ZFIT002
FOR ALL ENTRIES IN lit_zfit021_01
WHERE BELNY = lit_zfit021_01-BELNY
AND MARKZ = 'X'.
IF SY-SUBRC = 0 .
CLEAR LWA_ZFIT002 .
CLEAR LIT_ZFIT002_01[] .
LOOP AT LIT_ZFIT002 INTO LWA_ZFIT002 .
LWA_ZFIT002-MARKZ = ''.
APPEND LWA_ZFIT002 TO LIT_ZFIT002_01 .
CLEAR LWA_ZFIT002 .
ENDLOOP .
MODIFY ZFIT002 FROM TABLE LIT_ZFIT002_01 .
COMMIT WORK .
ENDIF .
ENDIF .
ENDIF .
ENDIF .
**********************************************
* IF LV_MARK = 'X' .
* READ TABLE XVBPA INTO LWA_XVBPA
* WITH KEY POSNR = '000000'
* PARVW = 'RG' .
* IF SY-SUBRC = 0 .
* SELECT *
* FROM ZFIT002
* INTO TABLE LIT_ZFIT002
* WHERE KUNNK = LWA_XVBPA-KUNNR
* AND WRBZH <> 0 .
* IF SY-SUBRC = 0 .
* LIT_ZFIT002_01[] = LIT_ZFIT002[] .
* SORT LIT_ZFIT002_01 BY BELNY DESCENDING.
* DELETE ADJACENT DUPLICATES FROM LIT_ZFIT002_01
* COMPARING BELNY .
* CLEAR LWA_ZFIT002_01 .
* SORT LIT_ZFIT002_01 BY MARKZ ASCENDING ."优先使用未清的赠送额度
* LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 .
* IF LV_KBETR <= 0 .
* EXIT .
* ENDIF .
* IF LV_KBETR >= LWA_ZFIT002_01-WRBZH ."LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH
* LV_KBETR = LV_KBETR - LWA_ZFIT002_01-WRBZH .
* LWA_ZFIT002_01-WRBZH = 0 ."预存款核销为0
* LWA_ZFIT002_01-WRBZY = LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH.
* LWA_ZFIT002_01-MARKZ = '' .
* MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
* TRANSPORTING WRBZH WRBZY MARKZ
* WHERE BELNY = LWA_ZFIT002_01-BELNY .
* ELSE .
*
* LWA_ZFIT002_01-WRBZH = LWA_ZFIT002_01-WRBZH - LV_KBETR .
* "LWA_ZFIT002_01-WRBZY = LWA_ZFIT002_01-WRBZY + LV_KBETR .
* LWA_ZFIT002_01-WRBZY = LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH.
* IF LWA_ZFIT002_01-WRBZY = 0 .
* LWA_ZFIT002_01-MARKZ = 'X' .
* ELSE .
* LWA_ZFIT002_01-MARKZ = '' .
* ENDIF .
* MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
* TRANSPORTING WRBZH WRBZY MARKZ
* WHERE BELNY = LWA_ZFIT002_01-BELNY .
* LV_KBETR = 0 .
*
* ENDIF.
* MODIFY ZFIT002 FROM TABLE LIT_ZFIT002 .
* COMMIT WORK AND WAIT .
* CLEAR LWA_ZFIT002_01 .
* ENDLOOP .
*
* ENDIF .
*
* ENDIF .
*
* ENDIF.
" CLEAR LWA_KOMP .
" ENDLOOP .
******************************8
ENDIF .
CLEAR GIT_XKOMV_OLD[] .
CLEAR GIT_XKOMV[] .
CLEAR gv_markz .
* DATA : LWA_XKOMV TYPE KOMV .
* DATA : LWA_XKOMV_01 TYPE KOMV .
* DATA : LWA_XVBPA TYPE VBPA .
* DATA : LWA_ZFIT002 TYPE ZFIT002 .
* DATA : LWA_ZFIT002_01 TYPE ZFIT002 .
* DATA : LIT_ZFIT002 TYPE TABLE OF ZFIT002 .
* DATA : LIT_ZFIT002_01 TYPE TABLE OF ZFIT002 .
* DATA : LV_KBETR TYPE KOMV-KBETR .
* DATA : LV_KBETR_01 TYPE KOMV-KBETR .
* DATA : LV_KBETR_02 TYPE KOMV-KBETR .
* DATA : LV_KBETR_03 TYPE KOMV-KBETR .
* DATA : LV_MARK(1) TYPE C ."赠送额度减少标识
*
* DATA : LIT_KOMP TYPE TABLE OF KOMP .
* DATA : LWA_KOMP TYPE KOMP .
*
* IF SY-TCODE = 'VA01' OR SY-TCODE = 'VA02'.
*
* CLEAR LWA_XKOMV_01 .
* LIT_KOMP[] = TKOMP[] .
* SORT LIT_KOMP BY KPOSN .
* DELETE ADJACENT DUPLICATES FROM LIT_KOMP
* COMPARING KPOSN .
* CLEAR LWA_KOMP .
* LOOP AT LIT_KOMP INTO LWA_KOMP .
* READ TABLE GIT_XKOMV_OLD INTO LWA_XKOMV_01
* WITH KEY KPOSN = LWA_KOMP-KPOSN
* KSCHL = 'ZKTO' .
* LWA_XKOMV_01-KBETR = 0 - LWA_XKOMV_01-KBETR .
* READ TABLE XKOMV INTO LWA_XKOMV
* WITH KEY KPOSN = LWA_KOMP-KPOSN
* KSCHL = 'ZKTO' .
* IF SY-SUBRC = 0.
* LWA_XKOMV-KBETR = 0 - LWA_XKOMV-KBETR .
* LV_KBETR_01 = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
* IF LV_KBETR_01 > 0 .
* LWA_XKOMV-KBETR = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
* LV_KBETR = LWA_XKOMV-KBETR .
* IF SY-SUBRC = 0 .
* READ TABLE XVBPA INTO LWA_XVBPA
* WITH KEY POSNR = '000000'
* PARVW = 'RG' .
* IF SY-SUBRC = 0 .
* "取出赠送额度
* LV_KBETR_02 = 0 .
* SELECT *
* FROM ZFIT002
* INTO TABLE LIT_ZFIT002
* WHERE KUNNK = LWA_XVBPA-KUNNR
* " AND WRBYY = LV_KBETR_02 "预存款核销余额为0 才可以使用赠送
* AND KUNNS = XVBAK-KUNNR
* AND markz = ''"赠送额度余额标识 为空为未用完
* and MARKR = ''."删除标识
* IF SY-SUBRC = 0 .
* LIT_ZFIT002_01[] = LIT_ZFIT002[] .
* "一个发票可能对应多个收款凭证清除相同项
* SORT LIT_ZFIT002_01 BY BELNY ASCENDING.
* DELETE ADJACENT DUPLICATES FROM LIT_ZFIT002_01
* COMPARING BELNY .
*
* CLEAR LWA_ZFIT002_01 .
* "检查赠送额度是否够用
* SORT LIT_ZFIT002_01 BY WRBYY ASCENDING ."优先使用预存款使用完的赠送金额
* LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 .
* LWA_XKOMV-KBETR = LWA_XKOMV-KBETR -
* ( LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH )."此次使用赠送 减去 预存款合同对应剩余赠送金额
* IF LWA_XKOMV-KBETR <= 0 .
* EXIT .
* ENDIF .
* CLEAR LWA_ZFIT002_01 .
* ENDLOOP .
*
* IF LWA_XKOMV-KBETR <= 0 ."赠送额度足够
*
* LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 .
* IF LV_KBETR <= 0 .
* EXIT .
* ENDIF .
* LV_KBETR_03 = LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH .
* IF LV_KBETR >= LV_KBETR_03 ."
* LV_KBETR = LV_KBETR - ( LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH ).
* LWA_ZFIT002_01-WRBZH = LWA_ZFIT002_01-WRBTZ ."预存款全都核销完
* LWA_ZFIT002_01-WRBZY = 0 .
* LWA_ZFIT002_01-MARKZ = 'X' .
* MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
* TRANSPORTING WRBZH WRBZY MARKZ
* WHERE BELNY = LWA_ZFIT002_01-BELNY .
* ELSE .
*
* LWA_ZFIT002_01-WRBZH = LWA_ZFIT002_01-WRBZH + LV_KBETR .
* LWA_ZFIT002_01-WRBZY = LWA_ZFIT002_01-WRBZY - LV_KBETR .
* MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
* TRANSPORTING WRBZH WRBZY MARKZ
* WHERE BELNY = LWA_ZFIT002_01-BELNY .
* LV_KBETR = 0 .
*
* ENDIF.
* CLEAR LWA_ZFIT002_01 .
* ENDLOOP .
*
* MODIFY ZFIT002 FROM TABLE LIT_ZFIT002 .
* COMMIT WORK AND WAIT .
*
* ELSE .
* MESSAGE '赠送额度不够使用' TYPE 'E' .
* EXIT .
* ENDIF .
*
*
* ENDIF .
* ENDIF .
*
* ENDIF .
* ELSEIF LV_KBETR_01 = 0 ."相等不处理
*
* ELSE ."小于0减少
* LWA_XKOMV-KBETR = LWA_XKOMV-KBETR - LWA_XKOMV_01-KBETR .
* LWA_XKOMV-KBETR = 0 - LWA_XKOMV-KBETR .
* LV_KBETR = LWA_XKOMV-KBETR .
* LV_MARK = 'X' .
* ENDIF .
*
* ELSE .
* IF LWA_XKOMV_01-KBETR <> 0 ."赠送额度不需要了
* LV_KBETR = LWA_XKOMV_01-KBETR .
* LV_MARK = 'X' .
*
* ENDIF .
*
* ENDIF .
*
**********************************************
* IF LV_MARK = 'X' .
* READ TABLE XVBPA INTO LWA_XVBPA
* WITH KEY POSNR = '000000'
* PARVW = 'RG' .
* IF SY-SUBRC = 0 .
* SELECT *
* FROM ZFIT002
* INTO TABLE LIT_ZFIT002
* WHERE KUNNK = LWA_XVBPA-KUNNR
* AND WRBZH <> 0 .
* IF SY-SUBRC = 0 .
* LIT_ZFIT002_01[] = LIT_ZFIT002[] .
* SORT LIT_ZFIT002_01 BY BELNY DESCENDING.
* DELETE ADJACENT DUPLICATES FROM LIT_ZFIT002_01
* COMPARING BELNY .
* CLEAR LWA_ZFIT002_01 .
* SORT LIT_ZFIT002_01 BY MARKZ ASCENDING ."优先使用未清的赠送额度
* LOOP AT LIT_ZFIT002_01 INTO LWA_ZFIT002_01 .
* IF LV_KBETR <= 0 .
* EXIT .
* ENDIF .
* IF LV_KBETR >= LWA_ZFIT002_01-WRBZH ."LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH
* LV_KBETR = LV_KBETR - LWA_ZFIT002_01-WRBZH .
* LWA_ZFIT002_01-WRBZH = 0 ."预存款核销为0
* LWA_ZFIT002_01-WRBZY = LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH.
* LWA_ZFIT002_01-MARKZ = '' .
* MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
* TRANSPORTING WRBZH WRBZY MARKZ
* WHERE BELNY = LWA_ZFIT002_01-BELNY .
* ELSE .
*
* LWA_ZFIT002_01-WRBZH = LWA_ZFIT002_01-WRBZH - LV_KBETR .
* "LWA_ZFIT002_01-WRBZY = LWA_ZFIT002_01-WRBZY + LV_KBETR .
* LWA_ZFIT002_01-WRBZY = LWA_ZFIT002_01-WRBTZ - LWA_ZFIT002_01-WRBZH.
* IF LWA_ZFIT002_01-WRBZY = 0 .
* LWA_ZFIT002_01-MARKZ = 'X' .
* ELSE .
* LWA_ZFIT002_01-MARKZ = '' .
* ENDIF .
* MODIFY LIT_ZFIT002 FROM LWA_ZFIT002_01
* TRANSPORTING WRBZH WRBZY MARKZ
* WHERE BELNY = LWA_ZFIT002_01-BELNY .
* LV_KBETR = 0 .
*
* ENDIF.
* MODIFY ZFIT002 FROM TABLE LIT_ZFIT002 .
* COMMIT WORK AND WAIT .
* CLEAR LWA_ZFIT002_01 .
* ENDLOOP .
*
* ENDIF .
*
* ENDIF .
*
* ENDIF.
* CLEAR LWA_KOMP .
* ENDLOOP .
*******************************8
*ENDIF .
*
*CLEAR GIT_XKOMV_OLD[] .
*CLEAR GIT_XKOMV[] .
*CLEAR gv_markz .
ENDIF .
*} INSERT
ENDFORM.
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_SAVE_DOCUMENT_PREPARE *
*---------------------------------------------------------------------*
* This userexit can be used for changes or checks, before a *
* document is saved. *
* *
* If field T180-TRTYP contents 'H', the document will be *
* created, else it will be changed. *
* *
* This form is called at the beginning of form BELEG_SICHERN *
* *
*---------------------------------------------------------------------*
FORM USEREXIT_SAVE_DOCUMENT_PREPARE.
*{ INSERT SGDK900103 1
*DATA : LV_KBETR1 TYPE KOMV-KBETR .
*DATA : LV_KBETR2 TYPE KOMV-KBETR .
*DATA : LWA_KOMV1 TYPE KOMV .
*DATA : LWA_KOMV2 TYPE KOMV .
*DATA : LV_MESS(30) TYPE C .
*
*CLEAR LWA_KOMV1 .
*LOOP AT XKOMV INTO LWA_KOMV1
* WHERE KSCHL = 'ZA00'.
*
* LV_KBETR1 = LWA_KOMV1-KBETR .
* CLEAR LWA_KOMV2 .
* LOOP AT XKOMV INTO LWA_KOMV2
* WHERE KPOSN = LWA_KOMV1-KPOSN
* AND KSCHL = 'ZA01'.
* LV_KBETR2 = LWA_KOMV2-KBETR .
*
* IF LV_KBETR2 < LV_KBETR2 .
* CONCATENATE '行项目' LWA_KOMV1-KPOSN
* ':定价条件ZA00大于ZA01' INTO LV_MESS .
* MESSAGE LV_MESS TYPE 'E' .
* ENDIF .
* CLEAR LWA_KOMV2 .
* ENDLOOP .
* CLEAR LWA_KOMV1 .
*ENDLOOP .
*} INSERT
ENDFORM.
*eject
ABAP va01信贷检查 售达方未清检查MV45AFZZ
最新推荐文章于 2024-09-12 13:26:14 发布