1. 程式人生 > >使用者出口(USER EXIT)總結

使用者出口(USER EXIT)總結

一.使用者出口的型別

 

1、第一代

sap提供一個空程式碼的子過程,在這個子過程中使用者可以新增自己的程式碼,控制自己的需求。這類增強都需要修改sap的標準程式碼。

示例:USEREXIT..in SAPMV45A

 

2、第二代

sap提供的是CUSTOMER-FUNCTION,它是通過SMOD和CMOD完成實現。

 

3、第三代

sap提供的第三代的使用者出口就是BADI,他的呼叫方式是CALLMETHOD (instance),(相關的TCODE是SE18和SE19),你可以通過EXIT_HANDLER這個單詞查詢BADI。

 

另外還有一種出口叫BTE

相關TCODE: FIBF

Business Transaction Events (Open FI)

 

二,使用者出口比較。

 

第一代使用者出口是form出口 如

 

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.

 

找法省略。 SD的使用者出口和定價的使用者出口等多采用這種方式。

 

第二代使用者出口多是 callcustomer-function ‘001’ 這種方式實現的。

 

是通過smod和cmod來實現的,

 

Here are a couple of hints:

If you have a user exit function module:EXIT_SAPLEINM_014

1) Fire up SE37 to get the developmentclass ME

2) Fire up transaction CMOD and go to menuoption Utilities -> SAP Enhancements

3) Enter the development class ME andexecute. This will list all the enhancements available in that developmentclass. Double click at leisure

For those wanting a more scientific method:

1) SE16 with table MODSAP - Enter thefunction module in MEMBER and execute (e.g. EXIT_SAPLEINM_014)

2) NAME is the Enhancement

3) To find the project that the enhancementis in:

4) SE16 with table MODACT - Enter theenhancement in MEMBER and execute (e.g. MM06E001)

5) NAME is the Project to use in CMOD 

 

參考其他資料。

 

第三代使用者出口 BADI

 

badi物件的資訊儲存在SXS_INTER, SXC_EXIT, SXC_CLASS 和SXC_ATTR 這四個表中(參見SECE包);

 

sap程式都會呼叫cl_exithandler=>get_instance來判斷物件是否存在,並返回例項;其實get_instance就是對上述幾個表和他們的檢視(V_EXT_IMP 和 V_EXT_ACT)進行查詢和搜尋。

 

基於這個機理,我查用ST05來監控一個TCODE來跟蹤,然後選擇查詢有關上述幾個表和檢視的操作,就可獲得相關BADI。

 

se18 查詢介面,se19 實現介面就可以實現使用者增強。

 

補充7.00版後badi的幾個處理變化

 

以前的CL_EXITHANDLER=>GET_PROG_AND_DYNP_FOR_SUBSCR被CL_ENH_BADI_RUNTIME_FUNCTIONS=>GET_PROG_AND_DYNP_FOR_SUBSCR代替.

以前的PUT_DATA_TO_SCREEN和GET_DATA_FROM_SCREEN不在需要。使用者可以建立自己的資料傳輸函式,通過CALL BADI來呼叫.

使用者也不需要呼叫CL_EXITHANDLER=>SET_INSTANCE_FOR_SUBSCREENS和CL_EXITHANDLER=>GET_INSTANCE_FOR_SUBSCREENS函式.

sample :This is an example to show - how to achieve post-processing [follow-on processing ] functionality using BADIs [ Business Add-inn ] oruser-exits.

 

Find the relevant BADI using transactionSE18. In this case BADI ME_PURCHDOC_POSTED is used.

Further, implement the BADI usingtransaction SE19.

In Attributes section of BADI, define aSTATIC attribute as PO_NUMBER. Static means the attribute will keep its valuebetween the calls. This will be checked to ensure that same POwill not be processed twice. Also these kind of user-exits and BADIs might getcalled recursively and get caught into an infinite loop, if not coded properly.Rememeber that this BADI is at the time of POsave and then you are again trying to change & save the Purchase Order fromwithin the BADI.

BAPI to change Purchase Order'BAPI_PO_CHANGE' will be called IN BACKGROUND TASK to ensure that it will becalled when COMMIT WORK is encountered.

Don't forget to activate the BADIimplementation in SE19.

也可以再後臺配置的地方找使用者出口。如spro 物料管理-採購-採購業務附加等。

 

BTE

 

1. IMG Menu Path: Financial AccountingFinancial Accounting Global Settings Use Business Transaction EventsEnvironment Infosystem (Processes).

2. Find the correct Business Event. You areupdating a field, so you select the Processes Info System instead of thePublish and Subscribe Info System.

3. Execute the search with the defaults.

4. Find the correct interface for updatinga document: Post Document: SAP- Internal Field Substitution

5. Put your cursor on the event and clickon the Sample Function Module button.

6. You are now in transaction SE37 –Function Builder. This is the function module (sample_process_00001130) youwill need to copy into a "Z" name function module for your coding

7. Click on the Copy button.

8. Enter the "Z" function modulename in the To Function Module field

9. Enter a Function Group. If you need tocreate a "Z" function group, go to transaction code SE37 and followmenu path: Go to Function Groups Create Group. A function group is a logicalgrouping of function modules, and the ABAP code is generated for functiongroups. You will be prompted for a development class and transport whencreating the function group.

10. In Function Builder (transaction SE37),enter the new "Z" function module. Click on the Change button.

11. The system will default into the sourcecode screen where you may enter your ABAP code.

12. Notice the tables available for thecode. Additional tables may be declared if necessary.

13. Enter the following source code 

 

tables: lfa1.

data: z_groupkey like lfa1-konzs.

z_groupkey = ' '.

loop at t_bseg.

* check for vendor lines. If one is found,read the vendor master and

* retrieve the group key field.

if t_bseg-koart eq 'K'.

select single konzs from lfa1 intoz_groupkey

where lifnr = t_bseg-lifnr.

endif.

* Move the group key field into all lineitems allocation field.

loop at t_bsegsub.

t_bsegsub-zuonr = z_groupkey.

modify t_bsegsub index sy-tabix.

endloop. "t_bsegsub

endloop. "t_bseg

 

14. Save the function module.

15. Back out to the main Function Builderscreen by clicking on the green arrow button.

16. Activate the function module byclicking on the Activate button

17. Assign the function module to the eventin the IMG: Financial Accounting Financial Accounting Global Settings BusinessTransaction Events Settings Process Function Modules of an SAP Appl.

18. Hit enter past the warning messagesthat this is SAP data.

19. Click on the New Entries button.

20. Enter the process for your interface.In your example it is 00001130.

21. Enter the country the interface isvalid for. If it is valid for all countries, leave this field blank.

22. Enter the application the interfaceshould be called for. If it should be called for all applications, leave thisfield blank. Please note that not all integrated transactions are programmed togo through these interfaces! You will need to test to find out!

23. Enter the new "Z" functionmodule

24. Save the settings. At this point youwill be prompted for a CTS number for the configuration change.

25. The Business Transaction Event iscomplete! You are ready for testing 

 

sample :

 

What is a BTE

 

(1)BTE are comparabl to the oldenhancements .

(2)BTEs are used mostly within FI .

(3)BTEs can be used both by SAP, third partvensdors and customers. Each use their own function modules where the logic isplaced, so they don't interfere with each other .

There are 2 types of BTE:

(1)Publish & Subscribe interfaces. Cannot update data. Posiible to have multiple implementations .

(2)Process interfaces. Can update date. Onlyone active implementation .

How does it work

The BTE is a functionmodule (Implemented bythe customer) that has a standard interface defined by SAP. The BTE is calledby the SAP standard program by a call to function OPEN_FI_PERFORM_ orOUTBOUND_CALL_. This function chekcs if there are any active BTEs according tocustomizing.

How to find a BTE

Search the socurce code for for"OPEN_FI_PERFORM" og " OUTBOUND_CALL_"

Use transaction FIBF menuEnvironment->Info System (P/S ). Use the Documenttion button to see thedocumentation for the BTE

Implementing a BTE

(1)Goto transction FIBF menuEnvironment->Info System (P/S )

(2)Select the BTE you want to implement.

(3)Press button Sample function module

(4)This brings you to SE37 - Copy thesample function module to a Z-function module (First create a new functiongroup for the function module) . Note: The name of the Z-functionmodule is notimportant

(5)Edit the code in the new function module

(6)Go back to transaction FIBF - MenuSettings->Products -> Of a customer and create a new product whicjidentifies the new product . Remember to mark the Active field.

(7)Go back to FIBF menu Settings->P/Sfunction modules->of a customer - Create an entry that links the BTE andProduct with the new function module

 

Example:

We want to implement BTE 00001030. Locateit in transaction FIBF .

 

Press button Sample function module . Copyfunction module in SE37 (First create a new function group for the functionmodule)

 

Edit the code in the new function module.

 

Go back to transaction FIBF - MenuSettings->Products->Of a customer and create a new product whicjidentifies the new productRemember to mark the Active field.

 

SaveGo back to FIBF menu Settings->P/Sfunction modules->of a customer - Create an entry that links the BTE andProduct with the new function module .

 

相關TCODE

FIBF Maintenance transaction BTE

BERE Business Event Repository

BERP Business Processes

BF31 Application modules per Event

BF32 Partner Modules per Event

BF34 Customer Modules per Event

BF41 Application Modules per Process

BF42 Partner Modules per Process

BF44 Customer Modules per Process

 

 

 

 

 

 

SAP 增強已經發展過幾代了,建議你係統學習一下 SAP 標準教材 BC425 和 BC427。

簡單說一下我的理解:

第一代:基於原始碼的增強。
原始碼增強以子程式形式釋出,在 SAP 的發行版本中,使用 PERFORM 呼叫這些子程式,它們在釋出時都是空的,集中在一些檔名倒數第二個字元為 Z 的包含程式中。使用者增強時,應首先到 servicemarketplace 申請物件鍵,然後才能修改這些子程式,這些子程式可以使用程式中所有的全域性資料。
螢幕增強以客戶螢幕形式釋出,它們包含在標準程式中,沒有什麼特別規律。
這種原始碼增強和螢幕增強的說明可以從事務碼 spro 後臺配置中相關模組的路徑裡面找到。
同時使用的針對資料表的增強是 appendstructure,可以在事務碼 se11 中開啟透明表,點選應用工具欄最右邊的那個 appendstructure 按鈕就能為資料表追加新的欄位。

第二代:基於函式模組的增強。
原始碼增強以函式模組形式釋出,在 SAP 的發行版本中,使用 CALL CUSTOMER-FUNCTION 呼叫這些函式模組,它們在釋出時只有一句程式碼 INCLUDExxxxxxx。使用者增強時,無需申請物件鍵,直接雙擊這個包含,然後回車,就可以建立相關的包含檔案,編寫相應的程式碼了。這些函式模組中只能使用介面中傳遞的引數,不能使用呼叫程式的全域性變數。
螢幕增強也包含在函式模組所屬的函式組中。
針對資料表的增強是 CI_ 結構,這些結構以 .INCLUDE 結構的形式包含在 SAP 釋出的資料表中,使用者可以通過向這些結構中新增欄位而對資料表進行增強。
上述這類增強通過事務碼 SMOD 進行維護,CMOD 進行實現。SMOD 中的一個增強可以包含上述的原始碼、螢幕和表結構增強,按照較容易理解的邏輯結構來管理這些增強,使用相對更加便利。

第三代:基於面向物件概念的增強。
這就是傳說中的 BAdI(Business Add-Ins),原始碼增強以介面形式釋出,在 SAP 的發行版本中,也是通過介面的方法呼叫來使用。使用者增強時,實際是實現一個(或多個)基於這個介面的實現類。由於介面可以有多個實現類,所以對一個增強可以有多種不同的原始碼,它們通過過濾器應用於不同的業務場景。
這種增強使用事務碼 SE18 建立、SE19 實現。
很遺憾,我對面向物件理解不深,使用 BAdI 也很少,所以不清楚它怎麼實現螢幕增強。

第四代:SwitchFramework。
SAP 從 NetWeaver7.0 以後退出的新增強體系,它對 BAdI 做出了改進,改叫新 BAdI 了。還新增 Enhancement Spot 和 Enhancement Section 以及隱式增強點的概念,基本可以在面向物件的程式裡實現處處皆可增強的最高境界。
但是由於我公司業務環境問題,我還完全沒有用它做過任何例項,因此沒有發言權。

基於強晟的回覆,補充幾點:
1) Field Exit技術:基於data element,如個螢幕的輸入框參考該data element,定義啟用Field Exit後,程式響應一個Function Code,可以觸發該Field Exit邏輯。只支援傳統的Dialog技術。詳細可參考程式RSMODPRF。

2) BTE(Business transaction Event):R/3 ERP的某幾個transaction中以FUNCTION MODULE形式預留的出口,以事件event方式定義,可以被BOR(BAPI)所使用,被Workflow以事件方式觸發。BAdI技術出現以前,這是唯一可以multiple實施,並且按照層次定義實施(可區分為SAPApplicatoin,Partner和Customer實施)。FIBF提供實施平臺,可參考其中的文件。

3) Enhancement framework 及 Switch Framework。準確地說,後者用來精確控制某類功能在一個系統中是否可以被啟用。而前者,則提供系統功能增強定義與實施。
從Netweaver 04s開始出現的Enhancement framework 可被認為Classic BAdI的升級,但其功能比Classic BAdI遠遠強大許多。
Enhancement framework 相比Classic BAdI來說主要的新功能有:
->原始碼增強,包括隱性增強(可以實施在某些特定地點,如FORM的開始或結束等等),系統級的支援,無需預定義;顯性增強(強晟已經解釋)。
->函式組增強,可用來增強FunctionModule介面引數
->類增強,可用來增加一個類的方法,增強方法的介面引數,以及對方法增強邏輯。
->語法級別的BAdI觸發機制(Kernal-BAdI),BAdI不再由Exit handle來控制,而是升級稱為ABAP語法級別的控制,以提供更高的執行效率。原來的BAdI因此改名Classic BAdI。
->框架提供了更多的管理功能,如通過CompositeEnhancement Implementation合併管理若干增強實施。
->對系統升級後的BAdI實施提供更方便的管理。
->與被增強物件更緊密地結合,如Web Dynprofor ABAP編輯器中直接整合了BAdI實施。
->與SwitchFramework的整合。
->相容Classic BAdI,如可仍然使用SE18定義,SE19實施。