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: 

bapi/badi

Former Member
0 Kudos

hai sir

i want real time objects of badi/bapi functionalities. plz help me to understand these

3 REPLIES 3

Former Member
0 Kudos

Hi Venu,

DEFINING THE BADI

1) execute Tcode SE18.

2) Specify a definition Name : ZBADI_SPFLI

3) Press create

4) Choose the attribute tab. Specify short desc for badi.. and specify the type :

multiple use.

5) Choose the interface tab

6) Specify interface name: ZIF_EX_BADI_SPFLI and save.

7) Dbl clk on interface name to start class builder . specify a method name (name,

level, desc).

Method level desc

Linese;ection instance methos some desc

😎 place the cursor on the method name desc its parameters to define the interface.

Parameter type refe field desc

I_carrid import spfli-carrid some

I_connid import spefi-connid some

9) save , check and activate…adapter class proposed by system is

ZCL_IM_IM_LINESEL is genereated.

IMPLEMENTATION OF BADI DEFINITION

1) EXECUTE tcode se18.choose menuitem create from the implementation menubar.

2) Specify aname for implementation ZIM_LINESEL

3) Specify short desc.

4) Choose interface tab. System proposes a name fo the implementation class.

ZCL_IM_IMLINESEL which is already generarted.

5) Specify short desc for method

6) Dbl clk on method to insert code..(check the code in “AAA”).

7) Save , check and activate the code.

Some useful URL

http://www.esnips.com/doc/e06e4171-29df-462f-b857-54fac19a9d8e/ppt-on-badis.ppt

http://www.esnips.com/doc/10016c34-55a7-4b13-8f5f-bf720422d265/BADIs.pdf

http://www.esnips.com/doc/43a58f51-5d92-4213-913a-de05e9faac0d/Business-Addin.doc

http://www.esnips.com/doc/1e10392e-64d8-4181-b2a5-5f04d8f87839/badi.doc

www.sapgenie.com/publications/saptips/022006%20-%20Zaidi%20BADI.pdf

http://www.sapdevelopment.co.uk/enhance/enhance_badi.htm

http://help.sap.com/saphelp_nw04/helpdata/en/04/f3683c05ea4464e10000000a114084/content.htm

Now write a sample program to use this badi method..

Look for “BBB” sample program.

“AAA”

data : wa_flights type sflight,

it_flights type table of sflight.

format color col_heading.

write:/ 'Flight info of:', i_carrid, i_connid.

format color col_normal.

select * from sflight

into corresponding fields of table it_flights

where carrid = i_carrid

and connid = i_connid.

loop at it_flights into wa_flights.

write:/ wa_flights-fldate,

wa_flights-planetype,

wa_flights-price currency wa_flights-currency,

wa_flights-seatsmax,

wa_flights-seatsocc.

endloop.

“BBB”

&----


*& Report ZBADI_TEST *

*& *

&----


*& *

*& *

&----


REPORT ZBADI_TEST .

tables: spfli.

data: wa_spfli type spfli,

it_spfli type table of spfli with key carrid connid.

*Initialise the object of the interface.

data: exit_ref type ref to ZCL_IM_IM_LINESEL,

exit_ref1 type ref to ZIF_EX_BADISPFLI1.

selection-screen begin of block b1.

select-options: s_carr for spfli-carrid.

selection-screen end of block b1.

start-of-selection.

select * from spfli into corresponding fields of table it_spfli

where carrid in s_carr.

end-of-selection.

loop at it_spfli into wa_spfli.

write:/ wa_spfli-carrid,

wa_spfli-connid,

wa_spfli-cityfrom,

wa_spfli-deptime,

wa_spfli-arrtime.

hide: wa_spfli-carrid, wa_spfli-connid.

endloop.

at line-selection.

check not wa_spfli-carrid is initial.

create object exit_ref.

exit_ref1 = exit_ref.

call method exit_ref1->lineselection

EXPORTING

i_carrid = wa_spfli-carrid

i_connid = wa_spfli-connid.

clear wa_spfli.

-


Former Member
0 Kudos

Dear,

Read the given text and

Just follow the steps, You will able to program yr Ist BADI .

Business Add-Ins (BADI)

SAP Business Add-Ins (BAdIs) are one of the most important technologies used to adapt SAP software to specific requirements. BAdIs were introduced with Release 4.6 and replace function module exits. This technology is not limited to SAP applications. BAdI calls can be integrated in customer applications. These can then be enhanced by other customer applications. In the various SAP applications, BAdI calls are implemented at places where enhancements are appropriate.Business add-ins are enhancements to the standard version of the system. They can be inserted into the SAP System to accommodate user requirements too specific to be included in the standard delivery. Since specific industries often require special functions, SAP allows you to predefine these points in your software.

As with customer exits, two different views are available:

• In the definition view, an application programmer defines exit points in a source that allow specific industry sectors, partners, and customers to attach additional coding to standard SAP source code, without having to modify the original object.

• In the implementation view, the users of Business Add-Ins can customize the logic they need or use a standard solution, if one is available.

In contrast to customer exits, Business Add-Ins no longer assume a two-level infrastructure (SAP and customer solutions), but instead allow for a multi-level system landscape (SAP, country-specific versions, industry solutions, partner, customer, and so on). You can create definitions and implementations of Business Add-Ins at any level of the system landscape.SAP guarantees the upward compatibility of all Business Add-In interfaces. Release upgrades do not affect enhancement calls from within the standard software nor do they affect the validity of call interfaces. You do not have to register Business Add-Ins in SSCR.

The Business Add-In enhancement technique differentiates between enhancements that can only be implemented once and enhancements that can be used actively by any number of customers at the same time. In addition, Business Add-Ins can be defined according to filter values. This allows you to differentiate between Add-In implementations using the filter Country or other criteria.

The enhancement technique is set up in such a way that it is possible to define interfaces for ABAP soure code, screens, GUI interfaces, and tables. These allow customers to include their own enhancements in the standard. A single Business Add-In contains all of the interfaces necessary to implement a specific task.

BADI is just an object-oriented version of user-exit. Instead of entering program code into some function module (as in customer-exit), you define some class which has to implement predefined methods and those methods are fired at predefined points just like an old user-exit. Some BADI can have multiple independent implementations which is much better for software deployment as several developers can implement the same BADI independently. BADI/UserExists are used to enhance R/3 For customer Needs.

How To Define a New BAdI Within the Enhancement Framework (Some Basics About the BAdI,BAdI Commands in ABAP,

When to Use a BAdI?)

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

How to implement a BAdI And How to Use a Filter

/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

Introducing Business Add-Ins

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f3202186-0601-0010-6591-b832b1a0...

How to implement BAdi in Enhancement Framework

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d0456c54-0901-0010-f0b3-cd765fb9...

Business Add-Ins

http://help.sap.com/saphelp_47x200/helpdata/en/ee/a1d548892b11d295d60000e82de14a/frameset.htm

BAdI: Customer-Defined Functions in the Formula Builder

http://help.sap.com/saphelp_nw04/helpdata/en/04/f3683c05ea4464e10000000a114084/content.htm

Difference Between BADI and User Exits

http://www.sap-img.com/abap/difference-between-badi-and-user-exits.htm

To Use BADI - Business Add In you need to Understand ABAP OO Interface Concept

http://www.sap-img.com/abap/business-add-in-you-need-to-understand-abap-oo-interface-concept.htm

BADI example

DEFINING THE BADI

1) execute Tcode SE18.

2) Specify a definition Name : ZBADI_SPFLI

3) Press create

4) Choose the attribute tab. Specify short desc for badi.. and specify the type :

multiple use.

5) Choose the interface tab

6) Specify interface name: ZIF_EX_BADI_SPFLI and save.

7) Dbl clk on interface name to start class builder . specify a method name (name,

level, desc).

Method level desc

Linese;ection instance methos some desc

😎 place the cursor on the method name desc its parameters to define the interface.

Parameter type refe field desc

I_carrid import spfli-carrid some

I_connid import spefi-connid some

9) save , check and activate…adapter class proposed by system is

ZCL_IM_IM_LINESEL is genereated.

IMPLEMENTATION OF BADI DEFINITION

1) EXECUTE tcode se18.choose menuitem create from the implementation menubar.

2) Specify aname for implementation ZIM_LINESEL

3) Specify short desc.

4) Choose interface tab. System proposes a name fo the implementation class.

ZCL_IM_IMLINESEL which is already generarted.

5) Specify short desc for method

6) Dbl clk on method to insert code..(check the code in “AAA”).

7) Save , check and activate the code.

Now write a sample program to use this badi method..

Look for “BBB” sample program.

“AAA”

data : wa_flights type sflight,

it_flights type table of sflight.

format color col_heading.

write:/ 'Flight info of:', i_carrid, i_connid.

format color col_normal.

select * from sflight

into corresponding fields of table it_flights

where carrid = i_carrid

and connid = i_connid.

loop at it_flights into wa_flights.

write:/ wa_flights-fldate,

wa_flights-planetype,

wa_flights-price currency wa_flights-currency,

wa_flights-seatsmax,

wa_flights-seatsocc.

endloop.

“BBB”

&----


*& Report ZBADI_TEST *

*& *

&----


*& *

*& *

&----


REPORT ZBADI_TEST .

tables: spfli.

data: wa_spfli type spfli,

it_spfli type table of spfli with key carrid connid.

*Initialise the object of the interface.

data: exit_ref type ref to ZCL_IM_IM_LINESEL,

exit_ref1 type ref to ZIF_EX_BADI_SPFLI.

selection-screen begin of block b1.

select-options: s_carr for spfli-carrid.

selection-screen end of block b1.

start-of-selection.

select * from spfli into corresponding fields of table it_spfli

where carrid in s_carr.

end-of-selection.

loop at it_spfli into wa_spfli.

write:/ wa_spfli-carrid,

wa_spfli-connid,

wa_spfli-cityfrom,

wa_spfli-deptime,

wa_spfli-arrtime.

hide: wa_spfli-carrid, wa_spfli-connid.

endloop.

at line-selection.

check not wa_spfli-carrid is initial.

create object exit_ref.

exit_ref1 = exit_ref.

call method exit_ref1->line_section

EXPORTING

i_carrid = wa_spfli-carrid

i_connid = wa_spfli-connid.

clear wa_spfli.

For BAPI:-

Just follow these steps to use the BAPI, I have given every possible text to make u understand the whole procedure of BAPI.

FU BAPI_MATERIAL_SAVEDATA

Create and Change Material Master Data

Functionality

You use this method to create new material master data or to change existing material master data. The data on a material can be transferred for each call.

When creating material master data, you must transfer the material number, the material type, and the industry sector to the method. You must also enter a material description and its language.

When changing material master data, you need enter only the material number.

In the header data, you must select at least one view for which data is to be created. Depending on the view selected, you must maintain other required parameters. If you do not enter values for all of the required parameters, the method is ended with an error message.

The corresponding fields in the tables (such as CLIENTDATA) must first be supplied with data by the calling program. An indicator must also be set for each of these fields so that the data is written to the database by the method. This requires the calling program to supply the corresponding field with the indicator in a checkbox table (for example, CLIENTDATAX). Checkbox tables exist for tables that do not contain any language-dependent texts (MAKT, MLTX), International Article Numbers (MEAN), or tax classifications (MLAN). Several data records for a material can be created in these tables.

If a structure contains fields for units of measurement (such as structure CLIENTDATA, field BASE_UOM), language indicators (such as structure MATERIALDESCRIPTION, field LANGU), or country indicators (such as structure TAXCLASSIFICATIONS, field DEPCOUNTRY), there is always a field of the same name with the ending _ISO. This makes it possible to transfer either the internally used SAP code or a standardized ISO code for the units of measurement, language indicators, or country indicators. ISO codes are converted to an SAP code internally for further processing. The ISO code is used only if the SAP code is not transferred. If you use ISO codes, there must be a unique assignment of the ISO code to the SAP code in the following activities in Customizing for Global Parameters:

• Check Units of Measurement

• Define Countries

If you want to maintain long texts (basic data texts, internal comments, purchase order texts, material memos, or sales texts) or customer-defined fields for a material, some special conditions have to be observed. They are described in the documentation for parameters MATERIALLONGTEXT and EXTENSIONIN.

Parameters

HEADDATA

CLIENTDATA

CLIENTDATAX

PLANTDATA

PLANTDATAX

FORECASTPARAMETERS

FORECASTPARAMETERSX

PLANNINGDATA

PLANNINGDATAX

STORAGELOCATIONDATA

STORAGELOCATIONDATAX

VALUATIONDATA

VALUATIONDATAX

WAREHOUSENUMBERDATA

WAREHOUSENUMBERDATAX

SALESDATA

SALESDATAX

STORAGETYPEDATA

STORAGETYPEDATAX

FLAG_ONLINE

FLAG_CAD_CALL

NO_DEQUEUE

RETURN

MATERIALDESCRIPTION

UNITSOFMEASURE

UNITSOFMEASUREX

INTERNATIONALARTNOS

MATERIALLONGTEXT

TAXCLASSIFICATIONS

RETURNMESSAGES

PRTDATA

PRTDATAX

EXTENSIONIN

EXTENSIONINX

BAPI to Copy Materials from one Plant to Another

*

  • Copy Materials from one Plant to Another

  • First run GETDATA AS CHECKBOX, "Tick to download materials data to local harddisk

  • Second run UPDDATA AS CHECKBOX. "Tick to update date to Materials Master

  • Check data in Excel before Second run

REPORT ZBAPIMM01 LINE-SIZE 255 NO STANDARD PAGE HEADING

LINE-COUNT 065(001).

TABLES: T001L, "Storage Locations

MARA, "General Material Data

MAKT, "Material Descriptions

MBEW, "Material Valuation

MARC. "Plant Data for Material

DATA: BAPI_HEAD LIKE BAPIMATHEAD,

BAPI_MAKT LIKE BAPI_MAKT, "Material Description

BAPI_MARA1 LIKE BAPI_MARA, "Client Data

BAPI_MARAX LIKE BAPI_MARAX,

BAPI_MARC1 LIKE BAPI_MARC, "Plant View

BAPI_MARCX LIKE BAPI_MARCX,

BAPI_MBEW1 LIKE BAPI_MBEW, "Accounting View

BAPI_MBEWX LIKE BAPI_MBEWX,

BAPI_RETURN LIKE BAPIRET2.

DATA: BEGIN OF INT_MAKT OCCURS 100.

INCLUDE STRUCTURE BAPI_MAKT.

DATA: END OF INT_MAKT.

DATA: BEGIN OF INT_MAT OCCURS 100,

WERKS(4), "Plant

MTART(4), "Material type

MATNR(18), "Material number

MATKL(9) , "Material group

MBRSH(1), "Industry sector

MEINS(3), "Base unit of measure

GEWEI(3), "Weight Unit

SPART(2), "Division

EKGRP(3), "Purchasing group

VPRSV(1), "Price control indicator

STPRS(12), "Standard price

PEINH(3), "Price unit

SPRAS(2), "Language key

MAKTX(40), "Material description

END OF INT_MAT.

SELECT-OPTIONS:

PLANT FOR MARC-WERKS OBLIGATORY MEMORY ID PLT,

MATERIAL FOR MARA-MATNR MEMORY ID MAT,

MATLTYPE FOR MARA-MTART MEMORY ID MTY,

DIVISION FOR MARA-SPART MEMORY ID DIV.

PARAMETERS: F_FILE LIKE RLGRAP-FILENAME

DEFAULT 'C:DATAMATERIAL.XLS' MEMORY ID F_FILE,

GETDATA AS CHECKBOX, "Tick to download materials data to local harddisk

UPDDATA AS CHECKBOX. "Tick to update date to Materials Master

IF GETDATA = 'X'.

PERFORM DOWNLOAD_DATA.

PERFORM DOWNLOAD_FILE.

ENDIF.

IF UPDDATA = 'X'.

PERFORM UPLOAD_FILE.

PERFORM UPDATE_MM.

ENDIF.

FORM DOWNLOAD_DATA.

SELECT * FROM MARC WHERE LVORM EQ ' '

AND WERKS IN PLANT

AND MATNR IN MATERIAL.

CLEAR MARA.

SELECT SINGLE * FROM MARA WHERE MATNR = MARC-MATNR.

CHECK MATLTYPE.

CHECK DIVISION.

CLEAR MBEW.

SELECT SINGLE * FROM MBEW WHERE MATNR = MARC-MATNR

AND BWKEY = MARC-WERKS.

CLEAR MAKT.

SELECT SINGLE * FROM MAKT WHERE SPRAS = 'EN'

AND MATNR = MARC-MATNR.

WRITE:/ MARC-WERKS, "Plant

MARA-MTART, "Material type

MARA-MATNR, "Material number

MARA-MATKL, "Material group

MARA-MBRSH, "Industry sector

MARA-MEINS, "Base unit of measure

MARA-GEWEI, "Weight Unit

MARA-SPART, "Division

MARC-EKGRP, "Purchasing group

MBEW-VPRSV, "Price control indicator

MBEW-STPRS, "Standard price

MBEW-PEINH, "Price unit

MAKT-SPRAS, "Language key

MAKT-MAKTX. "Material description

INT_MAT-WERKS = MARC-WERKS. "Plant

INT_MAT-MTART = MARA-MTART. "Material type

INT_MAT-MATNR = MARA-MATNR. "Material number

INT_MAT-MATKL = MARA-MATKL. "Material group

INT_MAT-MBRSH = MARA-MBRSH. "Industry sector

INT_MAT-MEINS = MARA-MEINS. "Base unit of measure

INT_MAT-GEWEI = MARA-GEWEI. "Weight Unit

INT_MAT-SPART = MARA-SPART. "Division

INT_MAT-EKGRP = MARC-EKGRP. "Purchasing group

INT_MAT-VPRSV = MBEW-VPRSV. "Price control indicator

INT_MAT-STPRS = MBEW-STPRS. "Standard price

INT_MAT-PEINH = MBEW-PEINH. "Price unit

INT_MAT-SPRAS = MAKT-SPRAS. "Language key

INT_MAT-MAKTX = MAKT-MAKTX. "Material description

APPEND INT_MAT.

CLEAR INT_MAT.

ENDSELECT.

ENDFORM.

FORM DOWNLOAD_FILE.

call function 'WS_DOWNLOAD'

EXPORTING

FILENAME = F_FILE

FILETYPE = 'DAT'

  • FILETYPE = 'WK1'

tables

data_tab = INT_MAT

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

OTHERS = 10.

IF SY-SUBRC = 0.

FORMAT COLOR COL_GROUP.

WRITE:/ 'Data Download Successfully to your local harddisk'.

SKIP.

ENDIF.

ENDFORM.

FORM UPLOAD_FILE.

call function 'WS_UPLOAD'

EXPORTING

FILENAME = F_FILE

FILETYPE = 'DAT'

  • FILETYPE = 'WK1'

tables

data_tab = INT_MAT

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

OTHERS = 10.

IF SY-SUBRC = 0.

FORMAT COLOR COL_GROUP.

WRITE:/ 'Data Upload Successfully from your local harddisk'.

SKIP.

ENDIF.

ENDFORM.

FORM UPDATE_MM.

LOOP AT INT_MAT.

  • Header

BAPI_HEAD-MATERIAL = INT_MAT-MATNR.

BAPI_HEAD-IND_SECTOR = INT_MAT-MBRSH.

BAPI_HEAD-MATL_TYPE = INT_MAT-MTART.

BAPI_HEAD-BASIC_VIEW = 'X'.

BAPI_HEAD-PURCHASE_VIEW = 'X'.

BAPI_HEAD-ACCOUNT_VIEW = 'X'.

  • Material Description

REFRESH INT_MAKT.

INT_MAKT-LANGU = INT_MAT-SPRAS.

INT_MAKT-MATL_DESC = INT_MAT-MAKTX.

APPEND INT_MAKT.

  • Client Data - Basic

BAPI_MARA1-MATL_GROUP = INT_MAT-MATKL.

BAPI_MARA1-BASE_UOM = INT_MAT-MEINS.

BAPI_MARA1-UNIT_OF_WT = INT_MAT-GEWEI.

BAPI_MARA1-DIVISION = INT_MAT-SPART.

BAPI_MARAX-MATL_GROUP = 'X'.

BAPI_MARAX-BASE_UOM = 'X'.

BAPI_MARAX-UNIT_OF_WT = 'X'.

BAPI_MARAX-DIVISION = 'X'.

  • Plant - Purchasing

BAPI_MARC1-PLANT = INT_MAT-WERKS.

BAPI_MARC1-PUR_GROUP = INT_MAT-EKGRP.

BAPI_MARCX-PLANT = INT_MAT-WERKS.

BAPI_MARCX-PUR_GROUP = 'X'.

  • Accounting

BAPI_MBEW1-VAL_AREA = INT_MAT-WERKS.

BAPI_MBEW1-PRICE_CTRL = INT_MAT-VPRSV.

BAPI_MBEW1-STD_PRICE = INT_MAT-STPRS.

BAPI_MBEW1-PRICE_UNIT = INT_MAT-PEINH.

BAPI_MBEWX-VAL_AREA = INT_MAT-WERKS.

BAPI_MBEWX-PRICE_CTRL = 'X'.

BAPI_MBEWX-STD_PRICE = 'X'.

BAPI_MBEWX-PRICE_UNIT = 'X'.

WRITE:/ BAPI_HEAD, BAPI_MARC1.

call function 'BAPI_MATERIAL_SAVEDATA'

exporting

HEADDATA = BAPI_HEAD

CLIENTDATA = BAPI_MARA1

CLIENTDATAX = BAPI_MARAX

PLANTDATA = BAPI_MARC1

PLANTDATAX = BAPI_MARCX

  • FORECASTPARAMETERS =

  • FORECASTPARAMETERSX =

  • PLANNINGDATA =

  • PLANNINGDATAX =

  • STORAGELOCATIONDATA =

  • STORAGELOCATIONDATAX =

VALUATIONDATA = BAPI_MBEW1

VALUATIONDATAX = BAPI_MBEWX

  • WAREHOUSENUMBERDATA =

  • WAREHOUSENUMBERDATAX =

  • SALESDATA = BAPI_MVKE1

  • SALESDATAX = BAPI_MVKEX

  • STORAGETYPEDATA =

  • STORAGETYPEDATAX =

IMPORTING

RETURN = BAPI_RETURN

TABLES

MATERIALDESCRIPTION = INT_MAKT

  • UNITSOFMEASURE =

  • UNITSOFMEASUREX =

  • INTERNATIONALARTNOS =

  • MATERIALLONGTEXT =

  • TAXCLASSIFICATIONS =

  • RETURNMESSAGES =

  • PRTDATA =

  • PRTDATAX =

  • EXTENSIONIN =

  • EXTENSIONINX =

.

IF BAPI_RETURN-TYPE = 'E'.

WRITE:/ 'Error Message ', BAPI_RETURN.

ENDIF.

ENDLOOP.

ENDFORM.

*---End of Program

I am sure this will help u

Regards,

P Singh