badi example

13
Introduction BADI implementation in the MM02 transaction to change the material description.When the customer needs more functionality in the SAP standard Program (Functionality) then we can add extra functionality to standard SAP functionality through BADI. BADI can't disturb the original (standard) code. Adding extra functionality to the standard is nothing but Add-in. BADI are not created in the program itself. They are created and maintained separately and called when we need the BADI. In the given tutorial BADI implantation of transaction MM02 is done as to change the description of the material number, for that I have explained the way to find the appropriate BADI according to the requirement. Than we will learn to see all the methods associated with that BADI name and finally implement that BADI to add extra features. Steps to find BADI Run the transaction SE24. Under object type put the class name 'CL_EXITHANDLER'. Click on display button. Under this class 'CL_EXITHANDLER' select the method 'GET_INSTANCE' and double click on it.

Upload: kvarmasap123

Post on 12-Nov-2014

2.030 views

Category:

Documents


23 download

TRANSCRIPT

Page 1: Badi Example

IntroductionBADI implementation in the MM02 transaction to change the material description.When the customer needs

more functionality in the SAP standard Program (Functionality) then we can add extra functionality to

standard SAP functionality through BADI. BADI can't disturb the original (standard) code.

Adding extra functionality to the standard is nothing but Add-in.

BADI are not created in the program itself. They are created and maintained separately and called when we

need the BADI.

In the given tutorial BADI implantation of transaction MM02 is done as to change the description of the

material number, for that I have explained the way to find the appropriate BADI according to the

requirement.

Than we will learn to see all the methods associated with that BADI name and finally implement that BADI to

add extra features.

Steps to find BADIRun the transaction SE24. Under object type put the class name 'CL_EXITHANDLER'.

Click on display button. 

                                          

 

Under this class 'CL_EXITHANDLER' select the method 'GET_INSTANCE' and double click on it.

               

Under the method 'GET_INSTANCE' put break point on a function module called

Page 2: Badi Example

'CALL METHOD CL_EXITHANDLER=>GET_CLASS_NAME_BY_INTERFACE' 

               

Place the cursor over here and give a break point.

Then according to the requirement run the transaction. In this example transaction code is MM02.

Run the transaction MM02. As in 1st step we have put a break point, that function module will give all BADI

used by the

transaction in each screen and activity on the application (MM02).  

Now double click on the changing parameter EXIT_NAME of the function module to get the name of BADI

used in this transaction.

Page 3: Badi Example

             

Now press F8 to again and again to get the list of all the BADI.

We will get following BADI as shown below.

BADI_SCREEN_LOGIC_RT

W_RETAILSYSTEM_IDENT

BADI_MATN1

Than again pressing F8 key the initial screen of transaction MM02 will appear.

                                                

Get a material number using F4 help and press enter.

BADI name after calling the main screen of MM02. 

                                    

BADI_MATERIAL_OD.

Now press F8 you will get the following screen.

Page 4: Badi Example

Choose the basic data and press enter to proceed.

Press F8.

Press F8.

Page 5: Badi Example

ECM_EXIT (Customer Exits for Engineering Change Management)

Press F8.

BADI_LAYER (Layer Value Management for BADIs)

Press F8.

BADI_MATERIAL_OD (Integration of New Objects in Material or Article Master)

Press F8.

BADI_MAT_F_SPEC_SEL (BADI for Material Special Field Selection)

Press F8.

Change material window will come. In this change the material description.

Page 6: Badi Example

            

Page 7: Badi Example

And savethe changes.You will get the following BADI.

BADI_GTIN_VARIANT (User Exit for Customer-Specific GTIN Variant Check)

Press F8.

BADI_MATERIAL_CHEK (Enhanced Checks for Material Master Tables)

Press F8.

Page 8: Badi Example

BADI_MAT_F_SPEC_SEL (BADI for Material Special Field Selection)

Press F8.

EHSS_SPEC_CHECKS (BADI: Extended Checks for Specifications)

BADI name: 

BADI_GTIN_VARIANT

BADI_MATERIAL_CHECK

BADI_MAT_SPEC_SEL

EHSS_SPEC_CHECKS 

Step to check all the methods associated with that BADIRun the transaction SE18 to see the details of BADI. 

Click on display button to see the methods declared in that.

Click on the interface tab to see the details of all the methods associated with the BADI name as shown

below.

Page 9: Badi Example

Method CHECK_DATA is used to give the material description. Choose the method where the material

description is defined. 

Steps to implement the BADIRun the transaction SE19 (BADI Builder) and create an implementation for the corresponding BADI. Click

on create button to create an implementation.

Page 10: Badi Example

Give a name for the implementation.

              \

Give the BADI description as shown below.

Page 11: Badi Example

Double click on method CHECK_DATA. On double clicking system will provide you the editor to write the

code.

                

Write the code in the editor window as shown below.

Page 12: Badi Example

            

The entire code is written as shown below

  CONSTANTS: wl_prefix(6) TYPE c        VALUE 'LT_BD_',

              wl_uname     TYPE sy-uname VALUE 'EI6DEV'.

  DATA: int_stext TYPE TABLE OF short_desc.

  DATA: wa_stext  TYPE short_desc.

  DATA: wf_idx    TYPE sy-tabix.

  DATA: WA1 TYPE SHORT_DESC.

  DATA: WA TYPE SHORT_DESC.

WA-MAKTX = 'HELLO'.

LOOP AT STEXT INTO WA1.

CONCATENATE WA1-MAKTX WA-MAKTX INTO WA1-MAKTX.

MODIFY STEXT FROM WA1.

ENDLOOP.

  IF sy-uname = wl_uname.            "and sy-tcode = 'MM02'

    int_stext[] = stext[].

    READ TABLE int_stext INTO wa_stext WITH KEY spras = sy-langu.

    IF sy-subrc = 0.

      wf_idx = sy-tabix.

      IF wa_stext-maktx+0(6) = wl_prefix OR wa_stext-maktx IS INITIAL.

        EXIT.

      ELSE.

        CONCATENATE wl_prefix wa_stext-maktx INTO wa_stext-maktx.

        MODIFY int_stext FROM wa_stext INDEX wf_idx.

        stext[] = int_stext[].

      ENDIF.

Page 13: Badi Example

    ENDIF.

  ENDIF.

Save the changes and activate the program. Than activate the BADI implementation.

The output of the BADI implementation is as shown below. The material description has been changed with

the prefix LT_BD_.

          

This is how we can change the standard material description using BADI.