Application Development 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: 

BADI Regarding

Former Member
0 Kudos

Dear All ,

I am new to BADI . I want to learn BADI , But i donot have any scenario and any idea how to go about .

If any body have implemented BADI please help me ,by giving the scenario . Please give any mail id so that i can communicate with you if i stuck somewhere .

Please send the documents to help_on_sap@yahoo.com

Thanka and regards

Raghavendra

6 REPLIES 6

Former Member

Former Member
0 Kudos

Hi,

Take a look at the blog series.

/people/thomas.weiss/blog/2006/01/24/what-the-new-enhancement-framework-is-for-150-its-basic-structure-and-elements-for-beginners

/people/thomas.weiss/blog/2006/03/15/the-new-enhancement-framework-part-2--what-else-you-need-to-know-before-building-an-enhancement

/people/thomas.weiss/blog/2006/04/03/how-to-define-a-new-badi-within-the-enhancement-framework--part-3-of-the-series

/people/thomas.weiss/blog/2006/04/18/how-to-implement-a-badi-and-how-to-use-a-filter--part-4-of-the-series-on-the-new-enhancement-framework

/people/thomas.weiss/blog/2006/05/03/source-code-enhancements--part-5-of-the-series-on-the-new-enhancement-framework

Also, you can probaly try doing a BADI which will fire upon saving a PO or Purchase Req.

regards,

Ravi

Note : Please mark the helpful answers

vinod_gunaware2
Active Contributor
0 Kudos

Hi

Check mail. If it is useful, pls reward pts.

Implementing Business Add-Ins (BADI)

The use of object orientated code within SAP has lead to new method of enhancing standard SAP code called Business Add-Ins or

BADI's for short. Although the implementation concept is based on classes, methods and inheritance you do not really have to understand this fully to implement a BADI. Simply think of methods as a function module with the same import and export parameters and follow the simple instructions below.

Steps:1. Execute Business Add-In(BADI) transaction SE18

2. Enter

BADI name i.e. HRPBSGB_HESA_NISR and press the display button

3 Select menu option Implementation->Create

4. Give implementation a name such as Z_HRPBSGB_HESA_NISR

5. You can now make any changes you require to the

BADI within this implementation, for example choose the Interface tab

6. Double click on the method you want to change, you can now enter any code you require.

7. Please note to find out what import and export parameters a method has got return the original BADI definition (i.e. HRPBSGB_HESA_NISR) and double click on the method name for example within HRPBSGB_HESA_NISR contract is a method

8. When changes have been made activate the implementation

regards

vinod

Former Member
0 Kudos

Dear vinodh

I have not recived the mail will please resend

I give another mail id .

raghavendra04@gmail.com

Former Member
0 Kudos

Hai Raghavendra

9.1 Single Implementation of BADI

Go to transaction SE18 and create a BADI Definition.

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

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

Save and activate it.

Go to transaction SE19 and create a BADI implementation.

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

Press Enter.

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

Double click on the method name.

Write the code. Save and activate it.

Then, create a code using the BADI

9.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

Then, create one implementations for the same BADI:-

(Code is similar to the previous one)

Then, create a program utilizing the BADI:-

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.

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.

9.3 Searching for BADI in SAP Transaction and Implementing it

There is a business demand in ABC corporation . when the user will post goods receipt via transaction MIGO, he should enter same date in document date and posting date field.

Else, an information message will ask the user to do that.

The Bill of Lading number should start with ‘NP’

You, as a SAP Technical Consultant, is asked to translate this idea into the appropriate section of the code.

Your manager has asked you to use BADI instead of any user or field exits to implement the idea.

Go to the program behing MIGO and search for the phrase : CL_EXITHANDLER=>GET_INSTANCE in the main program. This will show you the BADIs which can be implemented by you to incorporate the business demand.

So, you get to know now that there are two BADIs which can come to your use. They are:

MB_MIGO_BADI

MB_MIGO_ITEM_BADI.

Now, you have to go to transaction SE18 and explore each of the BADIs to find out the suitable one. In fact, the suitable one will have a method in it for which import/export parameters should have some reference to document/posting dates.

On investigation, you will find that in BADI : MB_MIGO_ITEM_BADI, there is a method : ITEM_MODIFY which uses : is_gohead as import parameter. This has the structure GOHEAD which contains the fields for document and posting date as columns.

Now, you will implement this BADI. Go to transaction SE19 and create an implementation for the BADI. In the code for the method, write the following:-

method IF_EX_MB_MIGO_ITEM_BADI~ITEM_MODIFY .

DATA : L_INI(2) TYPE C.

IF is_gohead-bldat ne is_gohead-budat.

message i398(00) with 'Both posting and document dates should be same'.

ENDIF.

L_INI = IS_GOHEAD-FRBNR+0(2).

TRANSLATE L_INI TO UPPER CASE.

IF L_INI NE 'NP'.

MESSAGE I398(00) WITH 'Bill of Lading should start with NP'.

ENDIF.

endmethod.

Then, save and activate it. Then, perform a transaction via MIGO. Your requirement will be fulfilled.

9.4 Menu Enhancements

9.4.1 Demand :

User will choose a material in the selection screen. All the records for that material in different plants and storage locs will be shown in a report. User will select a line from the list and choose option from the menupath to migrate to transaction MB03 to see the details of that document number.

BADI with function codes will be used to provide the menu option. The underlying method will accept the document number as an input and the method will call transaction MB03 for that document number.

9.4.2 Steps to be followed

9.4.2.1 Step 1 : Create the main program in SE38

Create a report program from SE38. Create a pf-ststus for including menu painter.

Double click on the GUI status to create and activate it.

Click Yes to create the GUI status .

Enter a description for the GUI status and press Enter.

The screen shown above will appear. Save, activate and come out.

You will be navigated to SE38 editor for the program. Save and activate it. Come out.

9.4.2.2 Step 2 :- Create BADI Definition from SE18

Go to transaction SE18. Enter the name of the BADI to be defined and press Create pushbutton.

Enter the description. Check-off the checkbox for Multiple use BADI. The tabstrips for function code(Fcodes) will appear. Click on that to go to appropriate tab-page.

Enter the name of the program. Enter the name of the function code,starting with ‘+’ which will be used later in program for BADI. Enter description . Then, double click on the program name.

Click Yes.

Save the BADI definition.

enter two lines for two function codes:- one for exiting out of the program,another for the details on document number.Press Enter.

The screen shown above will appear. Double click on the line for +ZDOC.

Enter the details for function code +ZDOC.

Then , double click on the line for function code : EXIT.

Complete entry for that too.

Then, save and activate the menu painter.Come out.

You will navigate to the transaction SE18. Click on the tab page : Interface.

An interface name is proposed by the system. Double-click on that.

Enter the name of the method which will be activated when the function code related to BADI will be activated. Then, click on the pushbutton : Parameters.

Enter the details for import/export parameters of the method.

Then, check and activate the BADI definition.

9.4.2.3 Step 3 :-Implement the BADI from transaction SE19

Go to transaction SE19 and create an implementation for the BADI you have defined.

Enter the name of the BADI definition.

Enter the description for the BADI implementation.

Then, in the table control, fill in the details for function code +ZDOC.

Then, go to tab page for: Interfaces.

Then, check and activate the BADI implementation.

Double click on the method name to write code for it.

Write the code. Check and activate it.

Come out.Once again, check and activate the implementation and come out of SE19.

9.4.2.4 Step 4:- Place the function codes properly in the menu painter

Edit the report program. Double click on the GUI status.

Maintain the two function codes at appropriate place. Check, activate and come out to SE38 editor.

9.4.2.5 Step 5:- Complete the program details

&----


*& Report YSUBBADIFC0001 *

*& *

&----


REPORT YSUBBADIFC0001 .

  • Create a GUI status for the program

SET PF-STATUS 'YSUBBADIFC0001'.

  • LOAD THE DEFINITION OF THE GLOBAL CLASS

CLASS CL_EXITHANDLER DEFINITION LOAD.

  • Declare an interface reference variable for the interface used in the

  • BADI

data : l_badi type ref to YIF_EX_SUBBADIFC0001_D.

data : w_mblnr like mseg-mblnr.

  • Declare types

TYPES : BEGIN OF TYP_DOC ,

MBLNR LIKE MSEG-MBLNR , "Document number

MJAHR LIKE MSEG-MJAHR , "Fiscal year

bwart LIKE MSEG-BWART , "Movement type

WERKS LIKE MSEG-WERKS , "Plant

LGORT LIKE MSEG-LGORT , "Storage location

SHKZG LIKE MSEG-SHKZG , "Dr/Cr Indicator

CHARG LIKE MSEG-CHARG , "Batch

MENGE LIKE MSEG-MENGE , "Qty

END OF TYP_DOC.

DATA : I_DOC TYPE STANDARD TABLE OF TYP_DOC WITH HEADER LINE.

PARAMETERS : P_MATNR LIKE MSEG-MATNR OBLIGATORY.

START-OF-SELECTION.

SELECT mblnr "Document no

mjahr "Fiscal yr.

bwart "Movement type

werks "Plant

lgort "Storage Loc

shkzg "Dr/Cr indicator

charg "Batch

menge "Quantity

from mseg

INTO TABLE i_doc

where matnr = p_matnr.

END-OF-SELECTION.

IF NOT i_doc[] IS INITIAL.

loop at i_doc.

write:/5 i_doc-mblnr right-justified,

20 i_doc-mjahr right-justified,

29 i_doc-bwart right-justified,

39 i_doc-werks right-justified,

46 i_doc-lgort right-justified,

53 i_doc-shkzg right-justified,

58 i_doc-charg right-justified,

66 i_doc-menge left-justified.

endloop.

endif.

TOP-OF-PAGE .

WRITE:/5 'DocNo' ,

20 'Fis.Yr' ,

28 'Mvt.Typ' ,

38 'Plant' ,

45 'StLoc' ,

52 'Dr/Cr' ,

58 'Batch' ,

65 'Qty' .

write:/5 sy-uline(70).

AT USER-COMMAND.

CASE SY-UCOMM.

WHEN 'EXIT'.

LEAVE PROGRAM.

WHEN '+ZDOC'.

  • Register for the BADI

CALL METHOD CL_EXITHANDLER=>GET_INSTANCE

EXPORTING exit_name = 'YSUBBADIFC0001_D'

null_instance_accepted = 'X'

CHANGING instance = l_badi.

IF NOT l_badi IS INITIAL.

  • Read the document no for the current line and pass it to the method

READ CURRENT LINE FIELD VALUE I_DOC-MBLNR INTO W_MBLNR.

CALL METHOD L_BADI->SHOW_DETAILS EXPORTING DOCNR = W_MBLNR.

endif.

endcase.

9.4.3 Mode of Execution

Execute the program with a material code.

The output shown above will appear. Select a document number and press the pushbutton in the application toolbar.

It will take you to transaction MB03 for that document number( as per the method behing the function code implemented by BADI). Press Enter to see the details.

Thanks & regards

Sreeni