原帖地址: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