【增强】 使用BADI(Create BADI) (转载)
【增强】 使用BADI(Create BADI)
在前一篇(【增强】使用BADI(Implement BADI))中,记录了使用现存的BADI。这一篇将记录通过我们自己创建一个BADI并在我们自己的业务中去实现它。不同于Exit,因为BADI的背后是OO的原理,所以关于ABAP OO请查阅SAP专门关于OO的BC401.
1.创建BADI
Tcode: SE18 (BADI Builder)

Menu: UtilitiesàCreate Classic BADI
(注:不能通过画面上的create来创建,除非使用一个enhancement Spot)

进入:

在Interface处,我们双击进入interface,我们定义一个Method:

定义method:

该method的parameter:

然后我们激活该interface.
我们的BADI现在变成:

我们这里不再去实现Fcode(Menu exit)与Subscreen(Screen Exit).
保存该BADI.
2.实现BADI
Tcode : SE19 (BADI Implementation)

Create Implementation:

进入实现:

在interface处:

我们进入该method并进行coding如下:

最后,激活我们的implementation.

3.程序中使用自己创建的BADI
我们要使用的数据:

SE38中我们coding如下:
|
*&———————————————————————* REPORT ZTEST_BADI. * for BADI,must define one instance variable for BADI interface * define Type START-OF-SELECTION. *1. get the data from DB *2. get the BADI Insatance *3. output the data
lw_output = ls_scarr-CARRID. WRITE:/10 lw_output, ENDLOOP. |
最后结果:

4.DeActive创建的BADI再查看效果
将我们刚active的implementation进行deActive

再执行我们上面的程序:

5.总结
1.SE18中创建BADI.需要定义好interface,这个interface name供后面program中调用。如果该BADI已经被implementation了,再修改了它的definition,需要regenerate一下。
2.SE19实现BADI,就是对interface的method进行实现。并激活与否,直接影响BADI是否起作用。
3.在其它程序中使用BADI。以下很重要:
|
1. CL_EXITHANDLER=》get_instance:用来取得BADI interface 2.再通过该interface的instance就可以随意地调用它的method了。 |
4.另外,在SE18中创建BADI的两个很重要的参数:

(更多深入知识请查阅SAP相关资料文档)
转自:http://scnblogs.techweb.com.cn/tcsapbw/archives/652.html

浙公网安备 33010602011771号