使用者出口(USER EXIT)總結

來源:互聯網
上載者:User

原帖地址:http://zhangweipublic.spaces.live.com/blog/cns!2A1866522DD62E4D!2445.entry

一.使用者出口的類型

1、第一代
sap提供一個空代碼的子過程,在這個子過程中使用者可以添加自己的代碼,控制自己的需求。這類增強都需要修改sap的標準代碼。
樣本:USEREXIT.. in SAPMV45A

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

3、第三代
sap提供的第三代的使用者出口就是BADI,他的調用方式是CALL METHOD (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的使用者出口和定價的使用者出口等多採用這種方式。

第二代使用者出口多是 call customer-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 development class ME
2) Fire up transaction CMOD and go to menu option Utilities -> SAP Enhancements
3) Enter the development class ME and execute. This will list all the enhancements available in that development class. Double click at leisure
For those wanting a more scientific method:
1) SE16 with table MODSAP - Enter the function module in MEMBER and execute (e.g. EXIT_SAPLEINM_014)
2) NAME is the Enhancement
3) To find the project that the enhancement is in:
4) SE16 with table MODACT - Enter the enhancement 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 ] or user-exits.

Find the relevant BADI using transaction SE18. In this case BADI ME_PURCHDOC_POSTED is used.
Further, implement the BADI using transaction SE19.
In Attributes section of BADI, define a STATIC attribute as PO_NUMBER. Static means the attribute will keep its value between the calls. This will be checked to ensure that same PO will not be processed twice. Also these kind of user-exits and BADIs might get called recursively and get caught into an infinite loop, if not coded properly. Rememeber that this BADI is at the time of PO save and then you are again trying to change & save the Purchase Order from within the BADI.
BAPI to change Purchase Order 'BAPI_PO_CHANGE' will be called IN BACKGROUND TASK to ensure that it will be called when COMMIT WORK is encountered.
Don't forget to activate the BADI implementation in SE19.
也可以再後台配置的地方找使用者出口。如spro 物料管理-採購-採購業務附加等。

BTE

1. IMG Menu Path: Financial Accounting Financial Accounting Global Settings Use Business Transaction Events Environment Infosystem (Processes).
2. Find the correct Business Event. You are updating a field, so you select the Processes Info System instead of the Publish and Subscribe Info System.
3. Execute the search with the defaults.
4. Find the correct interface for updating a document: Post Document: SAP- Internal Field Substitution
5. Put your cursor on the event and click on the Sample Function Module button.
6. You are now in transaction SE37 – Function Builder. This is the function module (sample_process_00001130) you will need to copy into a "Z" name function module for your coding
7. Click on the Copy button.
8. Enter the "Z" function module name in the To Function Module field
9. Enter a Function Group. If you need to create a "Z" function group, go to transaction code SE37 and follow menu path: Go to Function Groups Create Group. A function group is a logical grouping of function modules, and the ABAP code is generated for function groups. You will be prompted for a development class and transport when creating 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 source code screen where you may enter your ABAP code.
12. Notice the tables available for the code. 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 into z_groupkey
where lifnr = t_bseg-lifnr.
endif.
* Move the group key field into all line items 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 Builder screen by clicking on the green arrow button.
16. Activate the function module by clicking on the Activate button
17. Assign the function module to the event in the IMG: Financial Accounting Financial Accounting Global Settings Business Transaction Events Settings Process Function Modules of an SAP Appl.
18. Hit enter past the warning messages that 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 is valid for. If it is valid for all countries, leave this field blank.
22. Enter the application the interface should be called for. If it should be called for all applications, leave this field blank. Please note that not all integrated transactions are programmed to go through these interfaces! You will need to test to find out!
23. Enter the new "Z" function module
24. Save the settings. At this point you will be prompted for a CTS number for the configuration change.
25. The Business Transaction Event is complete! You are ready for testing 

sample :

What is a BTE

(1)BTE are comparabl to the old enhancements .
(2)BTEs are used mostly within FI .
(3)BTEs can be used both by SAP, third part vensdors and customers. Each use their own function modules where the logic is placed, so they don't interfere with each other .
There are 2 types of BTE:
(1)Publish & Subscribe interfaces. Can not update data. Posiible to have multiple implementations .
(2)Process interfaces. Can update date. Only one active implementation .
How does it work
The BTE is a functionmodule (Implemented by the customer) that has a standard interface defined by SAP. The BTE is called by the SAP standard program by a call to function OPEN_FI_PERFORM_ or OUTBOUND_CALL_. This function chekcs if there are any active BTEs according to customizing.
How to find a BTE
Search the socurce code for for "OPEN_FI_PERFORM" og " OUTBOUND_CALL_"
Use transaction FIBF menu Environment->Info System (P/S ). Use the Documenttion button to see the documentation for the BTE
Implementing a BTE
(1)Goto transction FIBF menu Environment->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 the sample function module to a Z-function module (First create a new function group for the function module) . Note: The name of the Z-functionmodule is not important
(5)Edit the code in the new function module
(6)Go back to transaction FIBF - Menu Settings->Products -> Of a customer and create a new product whicj identifies the new product . Remember to mark the Active field.
(7)Go back to FIBF menu Settings->P/S function modules->of a customer - Create an entry that links the BTE and Product with the new function module

Example:
We want to implement BTE 00001030. Locate it in transaction FIBF .

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

Edit the code in the new function module.

Go back to transaction FIBF - Menu Settings->Products->Of a customer and create a new product whicj identifies the new productRemember to mark the Active field.

SaveGo back to FIBF menu Settings->P/S function modules->of a customer - Create an entry that links the BTE and Product 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

參考

http://blog.csdn.net/CompassButton/archive/2006/12/16/1445391.aspx

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.