Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

badi

Former Member
0 Likes
998

hi,

What is meant by FILTER in badi ? how it will work?

Thank you

ASHOK

3 REPLIES 3
Read only

Former Member
0 Likes
527

Can you be more clear on what you mean by reusability? Almost any piece of code in SAP can be reused to some extent. You can insert code into your own custom programs to call badis, function module exits implemented in CMOD and even subroutine user exits if you try hard enough.

Multiple Use:

Every time a BADI is implemented in SE19, a new class is created for the implemented BADI. If a BADI Definition is flagged for multiple use, it means that you can create as many implementations of that BADI as you would like. For example if you had two different actions that need to be carried out, you could implement each action in a separate implementation. If the BADI is not set up for multiple use, both actions would have to be implemented in the same SE19 implementation.

Filters:

Filters are used to attach some type of criteria to the execution of a BADI. It would be similar to putting a hardcoded "if" statement in your code.

For example, see BADI Definition BDCP_BEFORE_WRITE. This BADI is set up for muletiple use and filters. It is used to do some checking before change pointers are written for a particular ALE Message Type. The Filter value can be set in your implementation to only be carried out for that message type. If a BADI is set up to have a filter value, this must be populated in your implementation.

Hope this helps,

Read only

0 Likes
527

Karthikeyan,

Thank you for copying my response from here:

Best Regards,

Chris H.

Read only

Former Member
0 Likes
527

1.1 Single Implementation of BADI

i) Go to transaction SE18 and create a BADI Definition

Def name:Ysub_get_materials

Click On Create button

Enter the description. The name of the interface will be automatically proposed. Double click on it.

Iname: yif_ex_sub_get_materials

Save as local object.

Enter the name of the method you want to create. Click the Paramters pushbutton to create parameters for the method.

Mname: get_materials

Parameters:

Matnr importing type Matnr

X_mara exporting type mara

Save and activate

2) Go to transaction SE19 and create a BADI implementation.

Implname: ysub_getm_implement

Click on Create button

A popup window will ask you for the definition name. Enter the name of the BADI definition which you have created

Definition name: ysub_get_materials

Press Enter.

Enter the description for the implementation. Then save and activate it.

Goto interface tab

Double click on the method name.

Click on yes.

Write the below code.

Method yif_ex_sub_Get_materials~get_materials.

If not matnr is initial.

Select single * from mara into x_mara

Where matnr = matnr.

Endif.

Endmethod.

Save and activate it

Then, create a code using the BADI

Report ysub_get_materials_program.

CLASS cl_exithandler DEFINITION LOAD.

DATA: l_badi_instnce type ref to yif_ex_sub_Get_materials,

x_mara like mara.

PARAMETERS: p_matnr like mara-matnr obligatory.

START-OF-SELECTION.

CALL METHOD CL_EXITHANDLER=>GET_INSTANCE “ this is static method.

EXPORTING EXIT_NAME = ‘YSUB_GET_MATERIALS’ “badi definition name

NULL_INSTANCE_ACCPETED = ‘X’

CHANGING INSTANCE =l_badi_instance.

CALL METHOD l_badi_instance-> GET_MATERIALS

EXPORTING MATNR = p_matnr

IMPORTING X_MARA = x_mara.

Write:/ x_mara-matnr,

x_mara-maktl,

x_mara-meins.

1.2 Multiple Implementation

Create a BADI: YSUB_GET_MATERIALS_1 in a manner similar to that created above. But, check the checkbox for Multiple Use in Attributes tab

Then, create one implementations for the same BADI:-

Method yif_ex_sub_Get_materials~get_materials.

If not matnr is initial.

Select single * from mara into x_mara

Where matnr = matnr.

Endif.

Endmethod.

Code is similar to the previous one)

Same above report program

Now, you want to create another implementation of the same BADI. Let us examplify the concept. Say, you want that when the user will enter ‘GARI’ in the selectiuon-screen, it will stand for ‘CAR’ internally and selection will be done out of MARA table based on material code : ‘CAR’. O, you define another implementation of the same BADI from transaction : SE19.

Implname2: YSUB_GETM_IMPL2

Method yif_ex_sub_Get_materials~get_materials.

Data: l_matnr type matnr.

L_matnr = matnr.

If l_matnr = ‘GARI’.

L_matnr = ‘CAR’.

Endif.

Select single * from mara into x_mara

Where matnr = l_matnr.

Endif.

Endmethod.

Now, when you will execute the program and enter ‘GARI’ in the material code field in the selection-screen, it will get internally translated to ‘CAR’ when the second implementation will be active.