Enhancement Framework 联系客服

发布时间 : 星期五 文章Enhancement Framework更新完毕开始阅读ac6da9075fbfc77da369b141

with its calling points in ABAP programs, it forms explicit enhancement options in such programs.

The definition of a BAdI contains a BAdI interface, a set of selection filters, and some settings that affect runtime behaviour later on. A BAdI interface forms the entire interface or part of the interface of an object plug-in.

A BAdI implementation is the term used in the Enhancement Framework for an enhancement implementation element. A BAdI implementation consists of a BAdI implementation class that implements the BAdI interface, and of a condition imposed on the filters specified in the BAdI definition. These can be used to select the BAdI implementation.

The calling points of a BAdI are defined through the ABAP statements GET BADI and CALL BADI, which – in the definition world of the Enhancement Framework – form the enhancement spot element calls of the explicit enhancement option.

Object Types Involved

In keeping with design patterns, the command GET BADI corresponds to the call for an abstract factory. It returns – depending on the filter values and a context – an instance of a proxy object. The static constellation of the interfaces and classes involved is displayed in the following UML diagram.

The BAdI has the name badi_name. The class shown here with the same name is the so-called BAdI class, which is created during the definition of a BAdI in the Enhancement Builder as the final subclass of the abstract global class cl_badi_base. The BAdI class is the template for the BAdI object, and does not play any visible role (with the exception of the namespace).

The name of the BAdI interface, for which badi_name is defined, is if_intf and contains the predefined tag interface if_badi_interface. The BAdI interface must not contain any variable attributes. If the BAdI can be used on a multiple basis, it must not contain any methods with exporting or returning parameters. The methods of a BAdI interface are

the so-called BAdI methods.(注:如果BAdi是以multiple basis来使用的,它不能包含任何带有传出参数或者返回参数的方法。)

The BAdI implementation classes cl_imp1, ... , cl_impn also implement the BAdI interface if_intf. The abstract class cl_abstract_imp displayed here is only for demonstration purposes since, in contrast to the classical BAdIs, there are no limitations with regard to the classes to be implemented, provided they implement the BAdI interface only. A BAdI

implementation class can even implement two different BAdI interfaces. This makes it possible when defining BAdIs, for example, to create partial implementations in the form of (abstract) BAdI implementation classes, from which the actual BAdI implementation classes inherit. (注:一个BAdi实现类可以实现两个不同的BAdi接口。 困惑? 解释如下:

当定义BAdi时,可以创建一个抽象的BAdi实现类(部分实现),实际的BAdi实现类可以继承这个抽象类,同时实现定义的BAdi接口,如cl_imp1。

呵呵,原来是这样的实现了2个不同的BAdi接口,其实就是在实现接口的同时,继承了BAdi的一个抽象类。 )

The BAdI class is not a BAdI implementation class and does not really implement the BAdI interface, but merely contains references to the actual object plug-ins (objects of BAdI implementation classes).

The architecture of BAdIs can be viewed also in relation to another design pattern, known as the parameterized event handler. Here, the BAdI implementation classes play the role of observers that automatically register at GET BADI for the appropriate BAdI object. The BAdI object takes on the role of subject, and method calls with CALL BADIcorrespond to a Notify.

Function Code and Screen Enhancements Use

The main use of BAdIs is to enhance ABAP programs using object plug-ins. For reasons of compatibility, and to be able to use the classic means for designing a user interface for an ABAP-based SAP system (GUI status and screens,) menu enhancements and screen enhancements were adopted almost unchanged from the classic BAdIs into the BAdIs of the new enhancement concept. These enhancements represent a concept that is independent of enhancements through object plug-ins and they are not supported using special ABAP statements.

Features

Function Code Enhancements

Menu enhancements have been adopted under the new name “Function Code Enhancements“, whereby the classic concept has been kept in its entirety. The use of the ABAP statements GET BADI and CALL BADI is not necessary. The runtime environment inserts the implementation of a function code enhancement automatically during program regeneration.

Screen Enhancements

对于屏幕增强,采纳了经典的概念,即Classic BAdi Concepts。但是有几点不同:

? 之前对方法的调用

CL_EXITHANDLER=>GET_PROG_AND_DYNP_FOR_SUBSCR, 已经被

CL_ENH_BADI_RUNTIME_FUNCTIONS=>GET_PROG_AND_DYNP_FOR_SUBSCR 所取代,他们的接口参数相同。

? 不再生成方法: PUT_DATA_TO_SCREEN and GET_DATA_FROM_SCREEN。可以创建

自己的BAdi方法来传输数据,通过CALL BADI来调用。 ? 不再需要调用

CL_EXITHANDLER=>SET_INSTANCE_FOR_SUBSCREENS and

CL_EXITHANDLER=>GET_INSTANCE_FOR_SUBSCREENS 这2个方法了。这些方法现在不需要了,因为它们仅仅是把BAdi引用放在了一个临时存储区。 SET_INSTANCE_FOR_SUBSCREENS也不需要了。

GET_INSTANCE_FOR_SUBSCREENS 可以被 GET BADI取代,如果有必要。

BAdIs Embedded in the Enhancement Concept

Use

The following figure shows how BAdIs are embedded in the enhancement concept:

The definition of BAdIs is managed by enhancement spots. A simple enhancement spot for BAdIs can contain several BAdI definitions as enhancement spot element definitions. BAdIs that would otherwise be spread out in the system can be grouped together semantically.

This structuring is mirrored on the implementation side through the enhancement implementations. A BAdI can be implemented by several BAdI implementations that are managed by enhancement implementations. A simple enhancement implementation for object plug-ins can contain several BAdI implementations of an enhancement spot as enhancement implementation elements and can implement a BAdI multiple times. Therefore, several enhancement implementations can be assigned to one enhancement spot.

In the above figure, the BAdIs A, B, and C are managed by a common enhancement spot for which there are two enhancement implementations on the implementation side. The first enhancement implementation manages one implementation for each of the BAdIs A and B; the second one manages the implementations of the BAdIs A and C.

A BAdI is always assigned to the same package, like the enhancement spot, to which it belongs.

Example

The structuring features of BAdIs in enhancement spots can be of a technical or a subject nature. If, in the definition of several BAdIs, you have the provision that they are to be used in the same context (this is a feature known only by the person who defines the BAdIs), they must be used by the same simple enhancement spot.

From a subject point of view, all BAdIs must then be grouped together by affiliation to functional units – for example, payroll – in combined enhancement spots.

Typical BAdIs

This example explains the enhancement technique through BAdIs.

Task

Country-specific validity tests are to be executed upon completion of an order in ERP. The interface of this validity test is to be specified using the interface if_check_validity. The current country is available in a field called cntry. A suitable BAdI enhancement option consists of two parts:

... 1. Depending on the current country, an object (or even several objects) must be

supplied that implements the if_check_validity interface.

2. The appropriate methods of this object (or several objects) are called, and the

result of this validity test is used again in the ERP coding.

It is very important to ensure that the order processing itself predefines the specification of the if_check_validity interface and its contract. The contract contains rules for the interface of the BAdI. That is, which values may be passed to the methods, which values are expected back,