SAP SD 實際應用增強(含程式碼)總結

dicksonjyl560101發表於2020-03-03

SAP SD 實際應用增強(含程式碼)總結


1.SD-如何讀取文字訂單的抬頭文字


在最近一次修改訂單跟蹤表,使用者提出需要讀取抬頭文字。由於使用者輸入文字時存在多種語言,如果根據使用者的語言或者在條件介面設定語言條件來提取文字,發現都會漏取文字。後來經過思索,用先從STXH表中獲取抬頭文字的語言,再使用該語言傳入read_text函式讀取文字,這樣就確保文字讀取,不會出現遺漏。程式碼摘抄如下:


CLEAR lV_text.

select single TDSPRAS into (w_LANG ) from STXH

where TDOBJECT = 'VBBK' and TDNAME = CS_TAB-vbeln and TDID = 'YOD1'.

if sy-subrc = 0.

w_tdid = 'YOD1'.

w_tdspras = w_LANG .

w_tdname = CS_TAB-vbeln.

w_tdobject = 'VBBK'.

REFRESH w_lines.

CALL FUNCTION 'READ_TEXT'

EXPORTING

CLIENT = SY-MANDT

ID = w_tdid

LANGUAGE = w_tdspras

NAME = w_tdname

OBJECT = w_tdobject

TABLES

LINES = w_lines

EXCEPTIONS

ID = 1

LANGUAGE = 2

NAME = 3

NOT_FOUND = 4

OBJECT = 5

REFERENCE_CHECK = 6

WRONG_ACCESS_TO_ARCHIVE = 7

OTHERS = 8


2.SD-如何增強VF04顯示交貨單相關的發票金額


sap給我們留好了增強的出口:EXIT_SAPLV60P_008,我們可以修改 ZXV6PU08,來顯示出庫相關的Billing的金額。


方法如下:


1、在VKDFIF中新增欄位YYNETWR,用於顯示價格。


2、修改 ZXV6PU08,填寫YYNETWR欄位。


程式碼照抄如下:


PERFORM y0000sd_0000_fill_vkdfif

TABLES

lt_vkdfif[]

USING lt_vkdfif-vkorg.


* we store the final result

c_vkdfif[] = lt_vkdfif[].


FORM y0000sd_0000_fill_vkdfif

TABLES tt_vkdfif STRUCTURE vkdfif

USING uv_vkorg TYPE vkorg.


DATA ls_vkdfif TYPE vkdfif.

DATA lv_tabix LIKE sy-tabix.

DATA: BEGIN OF t_vbap OCCURS 0,

vbeln TYPE vbeln,

kbmeng TYPE kbmeng,

netwr TYPE netwr,

waerk TYPE waerk,

lfimg TYPE lfimg,

END OF t_vbap.

***********************************

LOOP AT tt_vkdfif INTO ls_vkdfif WHERE vkorg = uv_vkorg.

lv_tabix = sy-tabix.


SELECT SINGLE vbfa~vbelv

vbfa~waers

FROM vbfa AS vbfa

JOIN lips AS lips

ON lips~vbeln = vbfa~vbeln AND

lips~posnr = vbfa~posnn

INTO ( ls_vkdfif-yyvbeln_order,

ls_vkdfif-yywaers )

WHERE vbfa~vbeln = ls_vkdfif-vbeln

AND vbfa~vbtyp_n = 'J' "delivery

AND vbfa~vbtyp_v <> 'B'. "quotation


CHECK sy-subrc = 0.


** Confirmed qty value - CT115262 *************

if ls_vkdfif-fkart = 'F2'.

clear ls_vkdfif-yynetwr .

SELECT vp~vbeln vp~kbmeng vp~netwr vp~waerk lp~lfimg

INTO CORRESPONDING FIELDS OF TABLE t_vbap

FROM vbap as vp

INNER JOIN lips AS lp ON lp~vgbel = vp~vbeln AND

lp~vgpos = vp~posnr

WHERE vp~vbeln = LS_VKDFIF-YYVBELN_ORDER.

LOOP AT t_vbap.

if t_vbap-kbmeng <> 0.

ls_vkdfif-yynetwr = ls_vkdfif-yynetwr +

t_vbap-netwr * t_vbap-lfimg / t_vbap-kbmeng .

ls_vkdfif-waerk = t_vbap-waerk.

endif.

ENDLOOP.

endif.

*************************************************


SELECT SINGLE vdatu

FROM vbak

INTO ls_vkdfif-yyvdatu

WHERE vbeln = ls_vkdfif-yyvbeln_order.


MODIFY tt_vkdfif INDEX lv_tabix FROM ls_vkdfif.

ENDLOOP.

ENDFORM.




3.SD--如何增強是同一類出庫單使用不同號碼段


在現實的業務中,一個公司有多個銷售組織,它們使用同一個出庫型別,業務往往希望它們建立的出庫單的號碼採用不同號碼範圍。但在sap裡出庫單號碼範圍是在出庫單型別裡設定,也就是使用相同的出庫單型別,也就使用相同的號碼範圍。如果要達到上需業務需求,我們可以使用增強實現。具體實現參見下面的步驟:


步驟1:建立多個號碼段:


path: Spro->Sales and Distribution->Sales->Sales Documents->Sales Document Header->Define Number Ranges For Sales Documents


or


path: Spro->Logistics Execution->Shipping->Deliveries->Define Number Ranges for Deliveries


TCODE: VN01

步驟二:設定出庫單型別的號碼範圍


path: Spro->Logistics Execution->Shipping->Deliveries->Define Delivery Types

TCODE: 0VLK


步驟三:修改SAP增強程式碼


modify the source code to control use different number range for different sale organiztion

3.1 you can use se38 to open source code MV50AFZ1 and find the form userexit_number_range.


*---------------------------------------------------------------------*

* 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.

*{ INSERT DEVK943692 1

DATA: z_werks TYPE lips-werks,

z_vkorg TYPE likp-vkorg,

z_nrnr TYPE nrnr,

z_vbtyp TYPE likp-vbtyp.

DATA: wa_xlikp LIKE likpvb,

wa_xlips LIKE lipsvb.

US_RANGE_INTERN = TVLK-NUMKI.

data t(1).

t = TVLK-LFART(1).

if t = 'Z'.

LOOP AT xlikp INTO wa_xlikp.

LOOP AT xlips INTO wa_xlips.

CASE wa_xlikp-vbtyp.

WHEN OTHERS.

MOVE: wa_xlikp-vbtyp TO z_vbtyp.

ENDCASE.

IF z_vbtyp EQ 'J' or "outbound del.

z_vbtyp eq 'T'. "return del. "V003

MOVE: wa_xlips-werks TO z_werks, "V002 "SBr16072007

wa_xlikp-vkorg TO z_vkorg.

ELSEIF z_vbtyp EQ '7'. "shipp.notification

MOVE: space TO z_vkorg,

wa_xlips-werks TO z_werks.

ENDIF.

if z_vkorg = '6001'.

if z_vbtyp eq 'J'.

Case z_werks.

WHEN '6255'.

US_RANGE_INTERN = 'D1'.

WHEN '6245'.

US_RANGE_INTERN = 'D2'.

WHEN '6254'.

US_RANGE_INTERN = 'D3'.

WHEN '6234'.

US_RANGE_INTERN = 'D4'.

WHEN '6101'.

US_RANGE_INTERN = 'D5'.

endcase.

elseif z_vbtyp EQ 'T' .

Case z_werks.

WHEN '6255'.

US_RANGE_INTERN = 'R1'.

WHEN '6245'.

US_RANGE_INTERN = 'R2'.

WHEN '6254'.

US_RANGE_INTERN = 'R3'.

WHEN '6234'.

US_RANGE_INTERN = 'R4'.

WHEN '6101'.

US_RANGE_INTERN = 'R5'.

endcase.

endif.

endif.

EXIT.

ENDLOOP.

EXIT.

ENDLOOP.

endif.

*} INSERT


ENDFORM.


4.SD--如何在輸出控制中增加自定義欄位


在sap的輸出控制中,我們有時需要增加系統未定義的欄位作為條件表的欄位,為了實現該需求我們就需要修改增強。


輸出控制用到的通訊結構


KOMKBK1 (Output Determination Communication Area CAS Appl. K1)

KOMKBV1 (Output Determination Communication Area Header Appl. V1)

KOMKBV2 (Output Determination Communication Area Header Appl. V2)

KOMKBV3 (Output Determination Communication Area Header Appl. V3)

KOMKBV5 (Communication Structure for Output Control Groups Appl. V5)

KOMPBV1 (Output Determination Communication Area Item Appl. V1)

KOMPBV2 (Output Determination Communication Area Item Appl. V2)

KOMPBV3 (Output Determination Communication Area Item Appl. V3)

SAP在這些結構中預留了INCLUDEs,使用者可以向這些結構新增新的欄位


Sales activities: KOMKBZ1 (in KOMKBK1)

Sales document header: KOMKBZ3 (in KOMKBV1)

Delivery header: KOMKBZ4 (in KOMKBV2)

Groups header: KOMKBZF (in KOMKBV5)

Billing document header: KOMKBZ5 (in KOMKBV3)

Sales document item: KOMPBZ1 (in KOMPBV1)

Delivery item: KOMPBZ3 (in KOMPBV2)

Billing document item: KOMKBZ5 (in KOMPBV3)

如果需要用新增欄位建立條件表,我們就需要同時向KOMBZ結構新增該欄位 (KOMBZ包含在通訊結構KOMB中).


完成以上兩部後,我們還需要增強sap的程式碼,對通訊結構的欄位進行賦值。sap在RVCOMFZZ, RVCOMFZ1 和RVCOMFZ4單元預留了很多的出口。


RVCOMFZ1中的出口如下:


USEREXIT_KOMPBV2_FILL (item fields in delivery)

USEREXIT_KOMPBV2_PARTNER (item fields for partners in delivery)

USEREXIT_KOMPBV3_FILL (item fields in billing document)

USEREXIT_KOMPBV3_PARTNER (item fields for partners in billing document)

RVCOMFZZ中的出口如下:


USEREXIT_KOMKBK1_FILL (header fields in sales activities)

USEREXIT_KOMKBK1_PARTNER (header fields for partners in sales activ.)

USEREXIT_KOMKBV1_FILL (header fields for sales documents)

USEREXIT_KOMKBV1_PARTNER (header fields for partners in sales documents)

USEREXIT_KOMKBV2_FILL (header fields in delivery)

USEREXIT_KOMKBV2_PARTNER (header fields for partners in delivery)

USEREXIT_KOMKBV3_FILL (header fields in billing document)

USEREXIT_KOMKBV3_PARTNER (header fields for partners in billing doc.)

RVCOMFZ4中的出口如下:


USEREXIT_KOMKBV5_FILL (header field for groups)


In output determination, communication table KOMB contains all key fields that can be used for conditions for output determination.


When you create new fields for output determination, you can distinguish between two types of fields:


Fields that are used in condition tables

Fields which are only used to query conditions.

Both types of field have to be included in KOMKBV1. Fields which are only used to query conditions do not have to be included in KOMB and T681F or in the field catalog.


對訂單輸出控制增加自定義欄位的詳細步驟如下;


1、用SE11向KOMKBV1中的KOMKBZ3增加自定義欄位;


2、用SE11向KOMB中的KOMBZ增加自定義欄位;


3、用V/86將自定義欄位新增到允許欄位中(欄位必須來自KOMB,否則在建表時不可見);


4、用V/57定義條件表;


5、定義條件儲存順序;


6、將條件儲存順序賦值給條件型別;


7、修改程式碼RVCOMFZZ中的子過程USEREXIT_KOMKBV1_FILL


5.SD--批次刪除訂單


在sap應用中常常會需要批次刪除一些錯誤錄入的單據,為此開發了一個小程式。該程式為了安全,程式做了一下控制


1、限制使用者只能刪除自己的訂單,不能刪除別人輸入的訂單,如果需要修改一下查詢條件;


2、系統預設為"測試執行",方便使用者在刪除訂單前要核實一下訂單,確認不要誤操作;


程式程式碼如下,供大家參考!


REPORT zsde0099.

TYPE-POOLS: slis.

*----------------------------------------------------------------------*

* data Declarations

*----------------------------------------------------------------------*

TABLES: vbak. " Sales Document: Header Data

*----------------------------------------------------------------------*

* table control Output Declarations

*----------------------------------------------------------------------*

TYPES: BEGIN OF tc_0100,

sel(1), " Check box

vbeln LIKE vbak-vbeln, " Sales Order Number

erdat LIKE vbak-erdat, " Sales order creation date

ernam LIKE vbak-ernam,

kunnr LIKE likp-kunag, " Sold-to Party

name1 LIKE kna1-name1, " Sold-to Company Name

text(200),

END OF tc_0100.

DATA: wa_tc_0100 TYPE tc_0100,

it_tc_0100 TYPE tc_0100 OCCURS 0 WITH HEADER LINE.


DATA g_fieldcat TYPE slis_t_fieldcat_alv.


*----------------------------------------------------------------------*

* Selection Screen

*----------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK params1 WITH FRAME TITLE text-001.

PARAMETER: s_vkorg LIKE vbak-vkorg DEFAULT '6001' OBLIGATORY MODIF ID s1. " " Sales Org.

SELECT-OPTIONS:

s_vtweg FOR vbak-vtweg OBLIGATORY, " Distribution Channel

s_spart FOR vbak-spart OBLIGATORY DEFAULT '10', " Division

s_auart FOR vbak-auart OBLIGATORY, " Order type

s_erdat FOR vbak-erdat OBLIGATORY, " Sales order creation date

* s_ERNAM FOR vbak-ERNAM OBLIGATORY , " Sales order creation date

s_kunnr FOR vbak-kunnr , " Sold-to party

s_vbeln FOR vbak-vbeln . " Sales Order

PARAMETER p_test AS CHECKBOX DEFAULT 'X'.


SELECTION-SCREEN END OF BLOCK params1.

***********************************************************************

*INITIALIZATION.

***********************************************************************

INITIALIZATION.

s_auart-sign = 'I'.

s_auart-option = 'EQ'.

s_auart-low = 'ZC01'.

APPEND s_auart.

s_auart-low = 'ZC03'.

APPEND s_auart.

s_auart-low = 'ZC06'.

APPEND s_auart.

s_auart-low = 'ZC20'.

APPEND s_auart.

s_vtweg-sign = 'I'.

s_vtweg-option = 'EQ'.

s_vtweg-low = '10'.

APPEND s_vtweg.

s_vtweg-low = '20'.

APPEND s_vtweg.

s_vtweg-low = '30'.

APPEND s_vtweg.

s_vtweg-low = '40'.

APPEND s_vtweg.

*----------------------------------------------------------------------*

* Selection Events Processing

*----------------------------------------------------------------------*

AT SELECTION-SCREEN OUTPUT.

PERFORM screen_check.


AT SELECTION-SCREEN.

CLEAR: it_tc_0100, wa_tc_0100.

REFRESH: it_tc_0100.


START-OF-SELECTION.

PERFORM extract_data.


END-OF-SELECTION.

PERFORM change_sales_orders.

PERFORM display_mes.


*&---------------------------------------------------------------------*

*& Form SCREEN_CHECK

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

FORM screen_check.

DATA: l_line TYPE i .

DESCRIBE TABLE s_erdat LINES l_line.

IF l_line EQ 0.

s_erdat-sign = 'I'.

s_erdat-option = 'BT'.

s_erdat-high = sy-datum.

s_erdat-low = sy-datum.

APPEND s_erdat.

ENDIF.

DESCRIBE TABLE s_vtweg LINES l_line.

IF l_line EQ 0.

ENDIF.

ENDFORM. "SCREEN_CHECK

*&---------------------------------------------------------------------*

*& Form extract_data

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

FORM extract_data.

DATA: lt_it1 LIKE it_tc_0100 OCCURS 0 WITH HEADER LINE,

l_chk(1). " for exclude incomplete SO


SELECT a~vbeln a~erdat a~ernam a~kunnr INTO CORRESPONDING FIELDS OF TABLE lt_it1

FROM vbak AS a

WHERE a~vbeln IN s_vbeln

AND a~auart IN s_auart

AND a~vkorg EQ s_vkorg

AND a~vtweg IN s_vtweg

AND a~spart IN s_spart

AND a~erdat IN s_erdat

AND a~ernam = sy-uname

AND a~kunnr IN s_kunnr.


LOOP AT lt_it1.

* get sold-to party company name

PERFORM get_customer_company_name USING lt_it1-kunnr CHANGING lt_it1-name1.

MODIFY lt_it1.

ENDLOOP.

it_tc_0100[] = lt_it1[].

ENDFORM. "extract_data

*&---------------------------------------------------------------------*

*& Form GET_CUSTOMER_COMPANY_NAME

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->F_KUNNR text

* -->F_NAME text

*----------------------------------------------------------------------*

FORM get_customer_company_name USING f_kunnr CHANGING f_name.

CLEAR f_name.

SELECT SINGLE name1 INTO f_name

FROM kna1

WHERE kunnr = f_kunnr.

ENDFORM. "GET_CUSTOMER_COMPANY_NAME

*&---------------------------------------------------------------------*

*& Form change_sales_orders

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

FORM change_sales_orders.

DATA: lt_order_header_in LIKE bapisdh1,

lt_order_header_inx LIKE bapisdh1x,

lt_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,

lt_order_item_in LIKE bapisditm OCCURS 0 WITH HEADER LINE,

lt_order_item_inx LIKE bapisditmx OCCURS 0 WITH HEADER LINE,

cp_eind(1).


SORT it_tc_0100 BY vbeln.

DELETE ADJACENT DUPLICATES FROM it_tc_0100.


LOOP AT it_tc_0100.

CLEAR: lt_order_header_inx,lt_order_item_in, lt_order_item_inx, lt_return,cp_eind.

REFRESH: lt_order_item_in, lt_order_item_inx, lt_return.

lt_order_header_inx-updateflag = 'D'.

IF p_test NE 'X'.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

salesdocument = it_tc_0100-vbeln

* ORDER_HEADER_IN = LT_ORDER_HEADER_IN

order_header_inx = lt_order_header_inx

TABLES

return = lt_return.

* 處理錯誤訊息:透過判斷訊息的型別,來判斷BAPI是否成功

LOOP AT lt_return .

IF lt_return-type EQ 'E' OR

lt_return-type = 'A' OR

lt_return = 'X'.

cp_eind = 'X'. "失敗

it_tc_0100-text = lt_return-message.

ENDIF.

ENDLOOP.

IF cp_eind NE 'X'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

ENDIF.

ENDIF.

IF cp_eind NE 'X' AND sy-subrc = 0.

IF p_test = 'X'.

it_tc_0100-text = 'Test successfully.'.


ELSE.

it_tc_0100-text = 'Delete successfully.'.

ENDIF.

ELSE.

CONCATENATE it_tc_0100-text '---' 'Delete error.' into it_tc_0100-text.

ENDIF.

MODIFY it_tc_0100.

ENDLOOP.

ENDFORM. "change_sales_orders


*&---------------------------------------------------------------------*

*& Form init_fieldedi

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_P_FIELDTAB text

*----------------------------------------------------------------------*

FORM init_fieldedi USING p_p_fieldtab TYPE slis_t_fieldcat_alv.

DATA: l_fieldcat TYPE slis_fieldcat_alv.

REFRESH p_p_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-fieldname = 'VBELN'.

l_fieldcat-seltext_m = 'ORDER NUMBER'.

l_fieldcat-outputlen = 10.

APPEND l_fieldcat TO p_p_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-fieldname = 'ERDAT'.

l_fieldcat-seltext_m = 'Create Date'.

l_fieldcat-ref_fieldname = 'ERDAT'.

l_fieldcat-ref_tabname = 'VBAK'.

l_fieldcat-outputlen = 10.

APPEND l_fieldcat TO p_p_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-fieldname = 'ERNAM'.

l_fieldcat-seltext_m = 'Input Person'.

l_fieldcat-ref_fieldname = 'ERDAT'.

l_fieldcat-ref_tabname = 'VBAK'.

l_fieldcat-outputlen = 10.

APPEND l_fieldcat TO p_p_fieldtab.

CLEAR l_fieldcat.

l_fieldcat-fieldname = 'KUNNR'.

l_fieldcat-seltext_m = 'Sold Code'.

l_fieldcat-ref_fieldname = 'KUNNR'.

l_fieldcat-ref_tabname = 'VBAK'.

l_fieldcat-outputlen = 10.

APPEND l_fieldcat TO p_p_fieldtab.


CLEAR l_fieldcat.

l_fieldcat-fieldname = 'NAME1'.

l_fieldcat-seltext_m = 'Sold Name1'.

l_fieldcat-outputlen = 35.

APPEND l_fieldcat TO p_p_fieldtab.


CLEAR l_fieldcat.

l_fieldcat-fieldname = 'TEXT'.

l_fieldcat-seltext_m = 'Message'.

l_fieldcat-outputlen = 120.

APPEND l_fieldcat TO p_p_fieldtab.


ENDFORM. " INITIALIZE_FIELDEDI

*&---------------------------------------------------------------------*

*& Form display_mes

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* --> p1 text

* <-- p2 text

*----------------------------------------------------------------------*

FORM display_mes .

PERFORM init_fieldedi USING g_fieldcat[].

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

it_fieldcat = g_fieldcat[]

i_save = 'A'

i_default = 'A'

TABLES

t_outtab = it_tc_0100.

ENDFORM. " display_mes


6.如何使用SE16N進行資料批次修改和輸入?

1、run SE16N;input table name and filter criteria;Go to the command field and type '/h' and press enter. This would activate the normal debugging session.

SAP SD 實際應用增強(含程式碼)總結

2、Execute (F8) to enter in debugging session.

SAP SD 實際應用增強(含程式碼)總結


This would activate the normal debugging session. Execute (F8) to enter in debugging session. Just make the below two variables as checked (X) .GD-SAPEDIT = XGD-EDIT=X3、Press F8 to continue the program, enter modify screen. After edit data, you need to click "save" button to save data into database.

7.SD-如何根據銷售單位確認數量,避免出現小數確認數量


在銷售單中,我們可能按大包裝進行銷售,單有時庫存不夠,系統出現帶小數的確認數量。為了避免這個出現,我們可以使用增強進行避免。在單元ZXATPU02新增程式碼如下:

data: w_av_vrkme like atpcc-atpm1,

w_av_vrkme_n like atpcc-atpm1,

w_av_pc like atpcc-atpm1.


* only if more ordered the available

check: T_ATPCSX-bdmng > p_atpcc-atpm1.


* available only partial ? via MOD

w_av_vrkme = p_atpcc-atpm1 mod ( T_ATPCSX-umrez * T_ATPCSX-umren ).

* rounded up in KAR (via DIV)

w_av_vrkme_n = ( p_atpcc-atpm1 div T_ATPCSX-umrez ) * T_ATPCSX-umren.

* rounded up quanitity in PC

w_av_pc = w_av_vrkme_n * T_ATPCSX-umrez / T_ATPCSX-umren.

* only if we have one line otherwise too complex

read table T_MDVEX index 2.

if sy-subrc > 0.

read table T_MDVEX index 1.

if sy-subrc = 0.

if w_av_vrkme <> 0.

if p_atpcc-atpm1 < ( T_ATPCSX-umrez / T_ATPCSX-umren ).

T_MDVEX-mng02 = 0.

else.

T_MDVEX-mng02 = w_av_pc.

endif.

MODIFY t_mdvex index 1.

endif.

endif.

endif.


8.如何控制同一一個訂單型別的使用多個號碼範圍

在現實的業務中,一個公司有多個銷售組織,它們使用同一個訂單型別,業務往往希望它們建立的訂單的號碼採用不同號碼範圍。但在sap裡訂單號碼範圍是在訂單型別裡設定,也就是使用相同的訂單型別,也就使用相同的號碼範圍。如果要達到上需業務需求,我們可以使用增強實現。

具體實現參見下面的步驟:

步驟1:建立多個號碼段:path: Spro->Sales and Distribution->Sales->Sales Documents->Sales Document Header->Define Number Ranges For Sales Documents TCODE: VN01

步驟二:設定訂單型別的號碼範圍path: Spro->Sales and Distribution->Sales->Sales Documents->Sales Document Header->Define Sales Document TypesTCODE: VOV8

步驟三:修改SAP增強程式碼

modify the source code to control use different number range for different sale organiztion

3.1 you can use se38 to open source code MV45AFZZ and find the form userexit_number_range.

*---------------------------------------------------------------------*

* 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.


3.2 change the source code as the following

*---------------------------------------------------------------------*

* 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.

*{ INSERT TASK912652 1

IF us_range_intern = '13'.

CASE vbak-vkorg.

WHEN '0029'.

us_range_intern = '13'.

WHEN '0143'.

us_range_intern = '14'.

ENDCASE.

ENDIF.

*} INSERT


endform.


9 SD--訂單最小量限制的增強


在現實的銷售活動中考慮到配送成本,需要限制小額訂單的開具,為了達到該目的,我們可以對出口USEREXIT_SAVE_DOCUMENT_PREPARE 進行增強,具體步驟如下.一、設計訂單起定量設定表,自定義(銷售公司+訂單型別)具體定義參見下圖建立透過sap表維護工具來維護自定義表程式和事務媽。 二、設計訂單起定量設定(客戶)表,自定義(客戶)具體定義參見下圖建立透過sap表維護工具來維護自定義表程式和事務媽。 三、增強程式碼

se38開啟單元MV45AFZZ,修改USEREXIT_SAVE_DOCUMENT_PREPARE過程,程式碼如下


*---------------------------------------------------------------------*

* 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 DEVK938281 1

DATA: zzamount LIKE vbak-netwr.

DATA: zmin LIKE vbak-netwr.

IF vbak-waerk NE tvko-waers. "

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

EXPORTING

date = sy-datum

foreign_amount = vbak-netwr

foreign_currency = vbak-waerk

local_currency = sy-waers

IMPORTING

local_amount = zzamount

EXCEPTIONS

no_rate_found = 01

overflow + 02.

IF sy-subrc NE 0.

zzamount = vbak-netwr.

ENDIF.

ELSE.

zzamount = vbak-netwr.

ENDIF.

*minimum order value check in local currency

TABLES: zorderlimit, zorder_limit.

DATA minvalue LIKE vbak-netwr.

DATA difference LIKE vbak-netwr.

SELECT SINGLE * FROM zorder_limit

WHERE vkorg EQ vbak-vkorg

and auart EQ vbak-auart.

IF sy-subrc EQ 0.

SELECT SINGLE * FROM zorderlimit

WHERE KUNNR EQ vbak-KUNNR.

IF sy-subrc EQ 0.

zmin = zorderlimit-ZZNETWR * 100.

IF zzamount < zmin.

MESSAGE '單據小於公司規定的訂單起定量,系統不能儲存!' TYPE 'E'.

sy-subrc = 4.

exit.

ENDIF.

ELSE.

zmin = zorder_limit-ZZNETWR * 100.

IF zzamount < zmin.

MESSAGE '單據小於公司規定的訂單起定量,系統不能儲存!' TYPE 'E'.

sy-subrc = 4.

exit.

ENDIF.

ENDIF.

ENDIF.

*

*} INSERT


ENDFORM.

*eject


四、結果如下圖

SAP SD 實際應用增強(含程式碼)總結


https://mp.weixin.qq.com/s/_EFUHDawnxYqcKu5JJG9Xw


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29829936/viewspace-2678308/,如需轉載,請註明出處,否則將追究法律責任。

相關文章