用户出口(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实施。

猜你喜欢

转载自blog.csdn.net/kuangben1/article/details/7084138
今日推荐