SD交貨單修改程式 的增強地方MV50AFZ1
阿新 • • 發佈:2019-01-10
***INCLUDE MV50AFZ1 .
************************************************************************
* *
* This include is reserved for user modifications *
* *
* Forms for delivery 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 delivery 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. "USEREXIT_DELETE_DOCUMENT
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_MOVE_FIELD_TO_LIKP *
*---------------------------------------------------------------------*
* This userexit can be used to move some fields into the *
* delivery header workaerea LIKP. *
* This form is called, when a header is created *
* This form is called at the end of form LIKP_FUELLEN. *
* *
*---------------------------------------------------------------------*
FORM userexit_move_field_to_likp.
* LIKP-zzfield = xxxx-zzfield2.
ENDFORM. "USEREXIT_MOVE_FIELD_TO_LIKP
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_MOVE_FIELD_TO_LIPS *
*---------------------------------------------------------------------*
* This userexit can be used to move some fields into the *
* delivery item workaerea LIPS *
* This form is called, when an item is created *
* *
* *
* This form is called at the end of form LIPS_FUELLEN. *
* *
*---------------------------------------------------------------------*
FORM userexit_move_field_to_lips.
* LIPS-zzfield = xxxx-zzfield2.
*增加庫存地點許可權檢查
DATA: text0(30) TYPE c.
IF lips-lgort <> ''.
AUTHORITY-CHECK OBJECT 'M_MSEG_LGO'
ID 'LGORT' FIELD lips-lgort.
IF sy-subrc <> 0.
CONCATENATE '沒有庫存地點' xlips-lgort '的許可權' INTO text0.
CONDENSE text0 NO-GAPS.
MESSAGE text0 TYPE 'E'.
EXIT.
ENDIF.
ENDIF.
ENDFORM. "USEREXIT_MOVE_FIELD_TO_LIPS
*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 TVLK like in standard
* US_RANGE_INTERN = TVLK-NUMKI.
**獲取流水號
DATA: retc TYPE inri-returncode.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = us_range_intern
object = 'RV_BELEG'
ignore_buffer = tvshp-ignbf "40C
IMPORTING
number = xlikp-vbeln
returncode = retc
EXCEPTIONS
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
interval_overflow = 6
OTHERS = 99.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE 'A' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE. "v_n_647514
CASE retc.
* critical sector of the number range reached
* message I532(V1).
WHEN '1'.
PERFORM message_handling
USING posnr_low '532' 'I' 'V1' 'RV_BELEG'
us_range_intern space space.
* the last number of the number range was given
* message I533(V1).
WHEN '2'.
PERFORM message_handling
USING posnr_low '533' 'I' 'V1' 'RV_BELEG'
us_range_intern space space.
ENDCASE. "^_n_647514
ENDIF.
IF xlikp-vbtyp <> '7'.
**更改交貨單編碼規則 2012.03.06
DATA:l_numbe LIKE ztsd04-numbe.
DATA:l_vbeln LIKE vbak-vbeln.
DATA:l_vbeln1 LIKE vbak-vbeln.
DATA:l_vbeln2 LIKE vbak-vbeln.
DATA: interval LIKE nriv.
SELECT SINGLE numbe INTO l_numbe FROM ztsd04
WHERE vkorg = xlikp-vkorg.
IF l_numbe IS INITIAL.
MESSAGE '該銷售組織未維護號碼段,請聯絡管理員' TYPE 'E'.
EXIT.
ENDIF.
CALL FUNCTION 'NUMBER_GET_INFO'
EXPORTING
nr_range_nr = us_range_intern
object = 'RV_BELEG'
IMPORTING
interval = interval.
l_vbeln1 = interval-fromnumber+2(8).
CONCATENATE l_numbe l_vbeln1 INTO l_vbeln1.
CONDENSE l_vbeln1 NO-GAPS.
l_vbeln2 = interval-tonumber+2(8).
CONCATENATE l_numbe l_vbeln2 INTO l_vbeln2.
CONDENSE l_vbeln2 NO-GAPS.
SELECT MAX( vbeln ) INTO l_vbeln FROM likp
WHERE vbeln > l_vbeln1
AND vbeln < l_vbeln2.
IF l_vbeln IS INITIAL.
* xlikp-vbeln = xlikp-vbeln+2(8).
* CONCATENATE l_numbe xlikp-vbeln INTO xlikp-vbeln.
xlikp-vbeln = l_vbeln1 + 1.
CONDENSE xlikp-vbeln NO-GAPS.
ELSE.
l_vbeln = l_vbeln + 1.
IF l_vbeln+2(8) > interval-tonumber+2(8).
MESSAGE '該銷售組織號碼段已用完,請聯絡管理員' TYPE 'E'.
EXIT.
ELSE.
xlikp-vbeln = l_vbeln.
ENDIF.
ENDIF.
ENDIF.
***
ENDFORM. "USEREXIT_NUMBER_RANGE
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_READ_DOCUMENT *
*---------------------------------------------------------------------*
* This userexit can be used to read data in additional tables *
* when the program reads a delivery. *
* *
* This form is called at the end of form BELEG_LESEN. *
* *
*---------------------------------------------------------------------*
FORM userexit_read_document.
**增加庫存地點許可權檢查
DATA: text0(30) TYPE c.
LOOP AT xlips.
IF xlips-lgort <> ''.
AUTHORITY-CHECK OBJECT 'M_MSEG_LGO'
ID 'LGORT' FIELD xlips-lgort.
IF sy-subrc <> 0.
CONCATENATE '沒有庫存地點' xlips-lgort '的許可權' INTO text0.
CONDENSE text0 NO-GAPS.
MESSAGE text0 TYPE 'E'.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. "USEREXIT_READ_DOCUMENT
*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.
***
ENDFORM. "USEREXIT_SAVE_DOCUMENT
*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.
**檢查庫位不能等於特殊庫存夥伴的庫位
DATA:i_kunnr LIKE kna1-kunnr.
DATA:i_adrnr LIKE kna1-adrnr.
DATA:i_sort2 LIKE adrc-sort2.
DATA: text0(30) TYPE c.
DATA: i_ihrez LIKE vbkd-ihrez.
CLEAR i_kunnr.
CLEAR:i_adrnr.
CLEAR:i_sort2.
IF sy-tcode <> 'VL09'.
IF xlikp-lfart <> 'ZLQ2'.
LOOP AT xvbpa WHERE parvw = 'SB'.
i_kunnr = xvbpa-kunnr.
ENDLOOP.
IF sy-subrc = 0 AND i_kunnr <> '0000000000'.
SELECT SINGLE adrnr INTO i_adrnr FROM kna1
WHERE kunnr = i_kunnr.
SELECT SINGLE sort2 INTO i_sort2 FROM adrc
WHERE addrnumber = i_adrnr.
ENDIF.
LOOP AT xlips.
IF i_sort2 <> ''.
IF xlips-lgort = i_sort2.
CONCATENATE '庫存地點' xlips-lgort '不能與特殊庫存合作伙伴的庫存地點一致!' INTO text0.
CONDENSE text0 NO-GAPS.
MESSAGE text0 TYPE 'E'.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ELSE.
*沖銷時判斷是否開立結算訂單
SELECT SINGLE ihrez INTO i_ihrez FROM vbkd
WHERE ihrez = xlikp-vbeln.
IF sy-subrc = 0.
CONCATENATE '交貨單' xlikp-vbeln '已開立結算訂單,不能沖銷!' INTO text0.
CONDENSE text0 NO-GAPS.
MESSAGE text0 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. "USEREXIT_SAVE_DOCUMENT_PREPARE
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_REFRESH_DOCUMENT *
*---------------------------------------------------------------------*
* It is always necessary to refresh user-specific data before *
* the next document will be processed. *
* This can be done in this userexit. *
* This userexit can be used to refresh user-specific data *
* when the processing of a delivery is finished *
* - after the document is saved *
* - when you leave the document processing with F3 or F15 *
* It may be necessary to refresh user-specific data before *
* the next document will be processed. *
* *
* This form is called in dialog at the end of form *
* BELEG_INITIALISIEREN *
* *
*---------------------------------------------------------------------*
FORM userexit_refresh_document.
* clear: ZZ50A.
* refresh: zzitemtab.
ENDFORM. "USEREXIT_REFRESH_DOCUMENT
*eject
************************************************************************
* *
* This include is reserved for user modifications *
* *
* Forms for delivery 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 delivery 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. "USEREXIT_DELETE_DOCUMENT
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_MOVE_FIELD_TO_LIKP *
*---------------------------------------------------------------------*
* This userexit can be used to move some fields into the *
* delivery header workaerea LIKP. *
* This form is called, when a header is created *
* This form is called at the end of form LIKP_FUELLEN. *
* *
*---------------------------------------------------------------------*
FORM userexit_move_field_to_likp.
* LIKP-zzfield = xxxx-zzfield2.
ENDFORM. "USEREXIT_MOVE_FIELD_TO_LIKP
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_MOVE_FIELD_TO_LIPS *
*---------------------------------------------------------------------*
* This userexit can be used to move some fields into the *
* delivery item workaerea LIPS *
* This form is called, when an item is created *
* *
* *
* This form is called at the end of form LIPS_FUELLEN. *
* *
*---------------------------------------------------------------------*
FORM userexit_move_field_to_lips.
* LIPS-zzfield = xxxx-zzfield2.
*增加庫存地點許可權檢查
DATA: text0(30) TYPE c.
IF lips-lgort <> ''.
AUTHORITY-CHECK OBJECT 'M_MSEG_LGO'
ID 'LGORT' FIELD lips-lgort.
IF sy-subrc <> 0.
CONCATENATE '沒有庫存地點' xlips-lgort '的許可權' INTO text0.
CONDENSE text0 NO-GAPS.
MESSAGE text0 TYPE 'E'.
EXIT.
ENDIF.
ENDIF.
ENDFORM. "USEREXIT_MOVE_FIELD_TO_LIPS
*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 TVLK like in standard
* US_RANGE_INTERN = TVLK-NUMKI.
**獲取流水號
DATA: retc TYPE inri-returncode.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = us_range_intern
object = 'RV_BELEG'
ignore_buffer = tvshp-ignbf "40C
IMPORTING
number = xlikp-vbeln
returncode = retc
EXCEPTIONS
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
interval_overflow = 6
OTHERS = 99.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE 'A' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE. "v_n_647514
CASE retc.
* critical sector of the number range reached
* message I532(V1).
WHEN '1'.
PERFORM message_handling
USING posnr_low '532' 'I' 'V1' 'RV_BELEG'
us_range_intern space space.
* the last number of the number range was given
* message I533(V1).
WHEN '2'.
PERFORM message_handling
USING posnr_low '533' 'I' 'V1' 'RV_BELEG'
us_range_intern space space.
ENDCASE. "^_n_647514
ENDIF.
IF xlikp-vbtyp <> '7'.
**更改交貨單編碼規則 2012.03.06
DATA:l_numbe LIKE ztsd04-numbe.
DATA:l_vbeln LIKE vbak-vbeln.
DATA:l_vbeln1 LIKE vbak-vbeln.
DATA:l_vbeln2 LIKE vbak-vbeln.
DATA: interval LIKE nriv.
SELECT SINGLE numbe INTO l_numbe FROM ztsd04
WHERE vkorg = xlikp-vkorg.
IF l_numbe IS INITIAL.
MESSAGE '該銷售組織未維護號碼段,請聯絡管理員' TYPE 'E'.
EXIT.
ENDIF.
CALL FUNCTION 'NUMBER_GET_INFO'
EXPORTING
nr_range_nr = us_range_intern
object = 'RV_BELEG'
IMPORTING
interval = interval.
l_vbeln1 = interval-fromnumber+2(8).
CONCATENATE l_numbe l_vbeln1 INTO l_vbeln1.
CONDENSE l_vbeln1 NO-GAPS.
l_vbeln2 = interval-tonumber+2(8).
CONCATENATE l_numbe l_vbeln2 INTO l_vbeln2.
CONDENSE l_vbeln2 NO-GAPS.
SELECT MAX( vbeln ) INTO l_vbeln FROM likp
WHERE vbeln > l_vbeln1
AND vbeln < l_vbeln2.
IF l_vbeln IS INITIAL.
* xlikp-vbeln = xlikp-vbeln+2(8).
* CONCATENATE l_numbe xlikp-vbeln INTO xlikp-vbeln.
xlikp-vbeln = l_vbeln1 + 1.
CONDENSE xlikp-vbeln NO-GAPS.
ELSE.
l_vbeln = l_vbeln + 1.
IF l_vbeln+2(8) > interval-tonumber+2(8).
MESSAGE '該銷售組織號碼段已用完,請聯絡管理員' TYPE 'E'.
EXIT.
ELSE.
xlikp-vbeln = l_vbeln.
ENDIF.
ENDIF.
ENDIF.
***
ENDFORM. "USEREXIT_NUMBER_RANGE
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_READ_DOCUMENT *
*---------------------------------------------------------------------*
* This userexit can be used to read data in additional tables *
* when the program reads a delivery. *
* *
* This form is called at the end of form BELEG_LESEN. *
* *
*---------------------------------------------------------------------*
FORM userexit_read_document.
**增加庫存地點許可權檢查
DATA: text0(30) TYPE c.
LOOP AT xlips.
IF xlips-lgort <> ''.
AUTHORITY-CHECK OBJECT 'M_MSEG_LGO'
ID 'LGORT' FIELD xlips-lgort.
IF sy-subrc <> 0.
CONCATENATE '沒有庫存地點' xlips-lgort '的許可權' INTO text0.
CONDENSE text0 NO-GAPS.
MESSAGE text0 TYPE 'E'.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. "USEREXIT_READ_DOCUMENT
*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.
***
ENDFORM. "USEREXIT_SAVE_DOCUMENT
*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.
**檢查庫位不能等於特殊庫存夥伴的庫位
DATA:i_kunnr LIKE kna1-kunnr.
DATA:i_adrnr LIKE kna1-adrnr.
DATA:i_sort2 LIKE adrc-sort2.
DATA: text0(30) TYPE c.
DATA: i_ihrez LIKE vbkd-ihrez.
CLEAR i_kunnr.
CLEAR:i_adrnr.
CLEAR:i_sort2.
IF sy-tcode <> 'VL09'.
IF xlikp-lfart <> 'ZLQ2'.
LOOP AT xvbpa WHERE parvw = 'SB'.
i_kunnr = xvbpa-kunnr.
ENDLOOP.
IF sy-subrc = 0 AND i_kunnr <> '0000000000'.
SELECT SINGLE adrnr INTO i_adrnr FROM kna1
WHERE kunnr = i_kunnr.
SELECT SINGLE sort2 INTO i_sort2 FROM adrc
WHERE addrnumber = i_adrnr.
ENDIF.
LOOP AT xlips.
IF i_sort2 <> ''.
IF xlips-lgort = i_sort2.
CONCATENATE '庫存地點' xlips-lgort '不能與特殊庫存合作伙伴的庫存地點一致!' INTO text0.
CONDENSE text0 NO-GAPS.
MESSAGE text0 TYPE 'E'.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ELSE.
*沖銷時判斷是否開立結算訂單
SELECT SINGLE ihrez INTO i_ihrez FROM vbkd
WHERE ihrez = xlikp-vbeln.
IF sy-subrc = 0.
CONCATENATE '交貨單' xlikp-vbeln '已開立結算訂單,不能沖銷!' INTO text0.
CONDENSE text0 NO-GAPS.
MESSAGE text0 TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. "USEREXIT_SAVE_DOCUMENT_PREPARE
*eject
*---------------------------------------------------------------------*
* FORM USEREXIT_REFRESH_DOCUMENT *
*---------------------------------------------------------------------*
* It is always necessary to refresh user-specific data before *
* the next document will be processed. *
* This can be done in this userexit. *
* This userexit can be used to refresh user-specific data *
* when the processing of a delivery is finished *
* - after the document is saved *
* - when you leave the document processing with F3 or F15 *
* It may be necessary to refresh user-specific data before *
* the next document will be processed. *
* *
* This form is called in dialog at the end of form *
* BELEG_INITIALISIEREN *
* *
*---------------------------------------------------------------------*
FORM userexit_refresh_document.
* clear: ZZ50A.
* refresh: zzitemtab.
ENDFORM. "USEREXIT_REFRESH_DOCUMENT
*eject