【ABAP增强】基于源代码的增强
? ? ? ? 基于源代碼的增強(qiáng)實(shí)質(zhì)上是對(duì)SAP所預(yù)留的空的子過程進(jìn)行編碼,用戶可以編輯此子過程,并在這個(gè)子過程中添加自定義的代碼,以增加SAP標(biāo)準(zhǔn)程序的控制功能。
1、通過系統(tǒng)IMG信息查找基于源代碼的用戶出口
一般相近的功能的子程序出口都會(huì)放在一個(gè)統(tǒng)一的INCLUDE程序中,SAP的程序執(zhí)行會(huì)調(diào)用該子程序,可以通過SAP的IMG(系統(tǒng)配置工具)獲取相關(guān)的出口程序的信息。
輸入事務(wù)代碼SPRO進(jìn)入IMG界面,以查找銷售相關(guān)的出口信息為例,可依次選擇“銷售與分銷”-“系統(tǒng)修正”-“用戶出口”命令,如下圖所示:
單擊菜單中的按鈕,可以看到SAP所提供的該節(jié)點(diǎn)所對(duì)應(yīng)的功能介紹,類似于F1的幫助,會(huì)對(duì)所提供的用戶出口程序類型、名稱和功能做簡(jiǎn)單的介紹,如下圖所示:
通過說明文檔可以獲取SAP預(yù)定義的出口名稱,如上圖在IMG可以看到包含的源碼出口Include包括MV45ATZZ、MV45AOZZ、MV45AIZZ、MV45AFZZ等。
2、通過開發(fā)類來查找基于源代碼的用戶出口
大部分銷售及分銷的程序都是基于源碼控制來實(shí)現(xiàn)增強(qiáng)的,該類增強(qiáng)包含在開發(fā)類VMOD中,通過SE80可以查找該開發(fā)類所包含的所有對(duì)象。
執(zhí)行事務(wù)代碼SE80,在對(duì)象類型下面選擇Package表示以開發(fā)類為條件,在對(duì)象名稱中輸入開發(fā)類名稱VMOD,回車,可以看到在列表中將帶出該開發(fā)類所包含的所有對(duì)象,包括字典對(duì)象、函數(shù)組、Include程序等等,該開發(fā)類所對(duì)應(yīng)的出口程序都在“包含”列表中,具體如下圖所示:
3、基于源碼的用戶出口應(yīng)用
以出口程序MV45AFZZ為例,該出口程序主要是在銷售訂單執(zhí)行時(shí)候被調(diào)用,通過ABAP編輯打開并查看源代碼,可以發(fā)現(xiàn)該程序中包含了很多空的子程序,在程序中會(huì)對(duì)這些子程序做一些簡(jiǎn)單的注釋說明,具體代碼如下:
***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.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.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.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.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.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.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.ENDFORM. *eject雙擊某一個(gè)子程序名,如USEREXIT_MOVE_FIELD_TO_VBAK,可以看到其在主程序中被調(diào)用的具體位置,如下圖所示:
(現(xiàn)在好像該功能已經(jīng)失效)
4、如何查找基于源碼的用戶出口的默認(rèn)參數(shù)
出口程序通過通過ABAP來進(jìn)行修改,在ABAP編輯器中可以直接在所定義的子程序中添加代碼。
做出口程序開發(fā)需要特別注意,僅能在指定的子程序中間穿插代碼,不能對(duì)子程序的結(jié)構(gòu)或者名稱做任何改變,而且必須保證所編譯代碼可以正常激活,否則可能導(dǎo)致正常的業(yè)務(wù)發(fā)生異常。
出口開發(fā)必須要了解業(yè)務(wù)需求以及該處增強(qiáng)在系統(tǒng)中所對(duì)應(yīng)的功能組,以確定對(duì)哪一部分代碼進(jìn)行更改,并能找到程序中所能使用到的系統(tǒng)參數(shù),以上面的MV45AFZZ為例,其主要的功能包括銷售訂單的創(chuàng)建、檢查以及保存。SAP的銷售訂單數(shù)據(jù)主要保存在VBAK和VBAP表中,而且SAP程序執(zhí)行中會(huì)對(duì)這些數(shù)據(jù)臨時(shí)存放于內(nèi)表XVBAK和XVKAP中。
查找出口中能使用到哪些內(nèi)表是整個(gè)開發(fā)的關(guān)鍵,可以通過網(wǎng)絡(luò)資源來找到SAP官方提供的一些信息。
●查找出口程序所對(duì)應(yīng)的主程序,通過ABAP編輯器能找到該出口程序的所處清單,即查看該出口程序具體由哪些程序調(diào)用。首先在ABAP編輯器中輸入出口程序名稱“MV45AFZZ”,單擊工具欄的“所用處清單”,將提示需要比較程序類型,默認(rèn)即可。
●單擊確定按鈕后將看到該出口程序被主程序SAPMV45A所調(diào)用,如下圖所示:
●選中命中清單中的程序名稱,單擊工具欄中的“查看”按鈕,查看該程序的源代碼。
SAP的程序規(guī)則一般會(huì)把不同的功能代碼封裝在不同的Include中,如變量定義一般存放在程序以TOP結(jié)尾的Include中,主程序SAPMV45A中包含Include程序MV45ATOP,如下圖所示:
●雙擊Include程序mv45atop,即可查看該程序所對(duì)應(yīng)的代碼。mv45atop中也包含了很多Include程序,例如其下級(jí)程序copydata中包含了部分內(nèi)表及變量的定義,如圖所示:
5、通過源碼出口來增強(qiáng)VA01功能實(shí)例
程序中所看到的變量及內(nèi)表數(shù)據(jù)都可以在用戶出口對(duì)應(yīng)的子程序中直接引用,系統(tǒng)執(zhí)行中的一些業(yè)務(wù)數(shù)據(jù)會(huì)被暫時(shí)存在指定的內(nèi)表中供出口程序判斷和使用。根據(jù)這些子程序的名稱及簡(jiǎn)介可以初步判斷其調(diào)用的過程,例如子程序USEREXIT_SAVE_DOCUMENT_PREPARE則會(huì)在訂單維護(hù)(VA01和VA02)保存前調(diào)用,下面以實(shí)例來介紹出口應(yīng)用。
例如:在SAP標(biāo)準(zhǔn)功能中,保存銷售訂單一般不會(huì)判斷采購(gòu)訂單編碼,本例中需要實(shí)現(xiàn)在訂單創(chuàng)建時(shí),若訂單類型為ZOR1,要求必須填入采購(gòu)訂單號(hào),否則無法保存。
通過F1鍵查找屏幕字段的技術(shù)信息,在訂單創(chuàng)建事務(wù)代碼VA01中可以找到訂單類型在屏幕中的字段名稱為VBAK-AUART,采購(gòu)訂單編碼在屏幕中的字段名稱為VBKD-BSTKD,對(duì)應(yīng)字段可以直接在用戶出口中進(jìn)行引用,出口代碼如下所示:
*---------------------------------------------------------------------* * 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.if vbak-auart = 'ZOR1' and vbak-bstkd is initial.message '該類型下必輸采購(gòu)訂單編號(hào)' type 'E'. endif.ENDFORM.?
程序中還包含了其他很多出口,用戶可以在程序中通過設(shè)置斷點(diǎn)Debug的方式來查找程序執(zhí)行時(shí)不同功能所對(duì)應(yīng)的出口。
總結(jié)
以上是生活随笔為你收集整理的【ABAP增强】基于源代码的增强的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【ABAP】模式(Pattern)创建与
- 下一篇: 【ABAP增强】基于函数的出口CMOD