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

Former Member
0 Kudos

Hi Experts,

Can any one provide me BADI Documents and examples.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi PB, this will help u.

Business Add-Ins

Business Add-Ins are a new SAP enhancement technique based on ABAP Objects. 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 (SMOD/CMOD [Page 40]), two different views are available:

• In the definition view, an application programmer predefines exit points in a source that allow specific industry sectors, partners, and customers to attach additional software 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 logic if one is available.

In contrast to customer exits, Business Add-Ins no longer assume a two-system infrastructure (SAP and customers), but instead allow for multiple levels of software development (by SAP, partners, and customers, and as country versions, industry solutions, and the like). Definitions and implementations of Business Add-Ins can be created at each level within such a system infrastructure.

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 control add-in implementation and make it dependent on specific criteria (on a specific Country value, for example). All ABAP sources, screens, GUIs, and table interfaces created using this enhancement technique are defined in a manner that allows 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. In Release 4.6A, program and menu enhancements can be made with Business Add-Ins. The actual program code is enhanced using ABAP Objects. In order to better understand the programming techniques behind the Business Add-In enhancement concept, SAP recommends reading the section on ABAP Objects

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

http://help.sap.com/saphelp_nw04/helpdata/en/e6/d54d3c596f0b26e10000000a11402f/content.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/c2/eab541c5b63031e10000000a155106/frameset.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.

BADI creation:

REPORT Z_BADI_TEST.

  • test call Badi from standard abap. (Only from rel 6.40 and above)

  • do the following

  • 1) define the Badi (SE18). For Abap call test uncheck multiple use

  • and filter boxes

  • 2) Implement the badi (SE19). Add any methods here in the implemntation

  • 3) activate

*

  • 4) define the standard class exithandler to the abap. This class is the "Badi caller

"

  • 5) define an exit variable referring to your Badi Implementation interface

  • this interface will normally be something like ZIF_EX***************

  • You will see this in SE18/SE19.

*

  • 6) Instantiate your instance of the badi (method call get_instance)

  • 7) Now call any method(s) in the Badi.

*

class cl_exithandler definition load. "Declaration

data exit type ref to zif_ex__jimbotest. "Interface reference

data yes type c.

data: v_knvv type knvv. "Used in Fmod call in Badi methods

start-of-selection.

yes = ' '.

selection-screen begin of block b1.

parameters: r1 radiobutton group rad1,

r2 radiobutton group rad1,

r3 radiobutton group rad1.

selection-screen end of block b1.

parameters: p_kunnr type knvv-kunnr.

select single * into v_knvv

from knvv

where kunnr eq p_kunnr.

export v_knvv to memory id 'CUST6A'. "Save customer data for the function module

call method cl_exithandler=>get_instance "Factory method call

exporting "Method

exit_name = 'Z_JIMBOTEST' "Name of your BADI

  • null_instance_accepted = yes

changing instance = exit.

if not exit is initial.

break-point 1.

if r1 = 'X'.

call method exit->dispord . "Add-In call

  • changing testparm1 = word.

endif.

if r2 = 'X'.

call method exit->dispfakt.

endif.

if r3 = 'X'.

call method exit->dispmat.

endif.

In the badi methods

1)

method ZIF_EX__JIMBOTEST~DISPORD.

CALL FUNCTION 'Z_DISPLAY_CUST'.

endmethod.

2)

method ZIF_EX__JIMBOTEST~DISPFAKT.

CALL FUNCTION 'Z_DISPLAY_FAKT'.

endmethod

3)

method ZIF_EX__JIMBOTEST~DISPMAT.

CALL FUNCTION 'Z_DISPLAY_CUST'.

endmethod.

Copy via SE 41 the status SALV_STANDARD from standard SAP program SALV_DEMO_METADATA into the main program where you've created the 3 function modules below (SAP______TOP)

Global Data for the three function modules I'm calling

FUNCTION-POOL Z_BADI_KNVV. "MESSAGE-ID ..

include <color>.

include <icon>.

include <symbol>.

tables: zknvv.

data: v_zzkvgr6 TYPE KNVV-ZZKVGR6.

data: choice1 type c.

data: choice2 type c.

data: choice3 type c.

data: choice4 Type c.

data: ok-code(5) type c.

data: answer type string.

data: value1 type SPOP-VARVALUE1.

data: answer1 type string.

tables: vbak, vbap, vakpa, vbrk, vrkpa.

data: lr_functions type ref to cl_salv_functions_list.

constants: gc_true type sap_bool value 'X',

gc_false type sap_bool value space.

  • add for colour displays

data: ls_color type lvc_s_colo.

DATA : LV_SALV_COLUMNS_TABLE TYPE REF TO CL_SALV_COLUMNS_TABLE.

data: lr_columns type ref to cl_salv_columns_table,

lr_column type ref to cl_salv_column_table.

Data:

gr_table TYPE REF TO cl_salv_table.

data: z_datum type sy-datum.

data: v_knvv type knvv.

data : begin of s_vbak,

vkorg type vakpa-vkorg,

vkgrp type vakpa-vkgrp,

vtweg type vakpa-vtweg,

spart type vakpa-spart,

auart type vakpa-auart,

vbeln type vakpa-vbeln,

bstnk type vakpa-bstnk,

audat type vakpa-audat,

netwr type vbak-netwr,

end of s_vbak.

data : begin of s_vbrk,

vbeln type vrkpa-vbeln,

vkorg type vrkpa-vkorg,

fkart type vrkpa-fkart,

fkdat type vrkpa-fkdat,

netwr type vbrk-netwr,

end of s_vbrk.

data: begin of s_vbap,

matnr type vbap-matnr,

arktx type vbap-arktx,

netwr type vbap-netwr,

kwmeng type vbap-kwmeng,

end of s_vbap.

data: t_vbap like table of s_vbap.

data: t_vbak

like table of s_vbak.

data: t_vbrk

like table of s_vbrk.

data: s_name type tabname.

data: gr_selections type ref to cl_salv_selections.

data: gr_events type ref to cl_salv_events_table.

Source code of the function modules.

Function modules

FUNCTION Z_DISPLAY_CUST.

*"----


""Lokale interface:

*"----


s_name = 'S_VBAK'.

  • orders in last 6 months

z_datum = sy-datum - 180.

import v_knvv from memory id 'CUST6A'.

  • get data

select avkorg aaudat avkgrp avtweg aspart aauart abstnk avbeln b~netwr

into corresponding fields of table t_vbak

up to 100 rows

from ( vakpa as a

inner join vbak as b

on avbeln eq bvbeln )

where a~kunde eq v_knvv-kunnr

and a~parvw eq 'AG'

  • and a~vkorg eq 'EN01'

and a~trvog eq '0'

and a~audat gt z_datum.

sort t_vbak by audat descending.

*data: gt_hyperlink type standard table of g_type_s_hyperlink.

  • Instead of if_salv_c_bool_sap=>false, you can pass the

  • value if_salv_c_bool_sap=>true to this method to

  • see your ALV as a list.

  • display data in Grid / List

TRY.

CALL METHOD cl_salv_table=>factory

EXPORTING

list_display = if_salv_c_bool_sap=>false

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = t_vbak.

CATCH cx_salv_msg.

ENDTRY.

try.

LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

ls_color-col = col_negative.

ls_color-int = 0.

ls_color-inv = 0.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'VBELN' ).

ls_color-col = col_negative.

ls_color-int = 1.

ls_color-inv = 1.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

*LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

lr_column->set_short_text( 'Short' ).

lr_column->set_medium_text( 'Medium' ).

lr_column->set_long_text( 'Net Value' ).

*lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'URL' ).

*

catch cx_salv_not_found.

endtry.

gr_table->set_screen_status( pfstatus = 'SALV_STANDARD'

report = sy-repid

set_functions = gr_table->c_functions_all ).

  • this statement actually does the display.

gr_table->display( ).

ENDFUNCTION.

FUNCTION Z_DISPLAY_FAKT.

*"----


""Lokale interface:

*"----


s_name = 'S_VBRK'.

  • invoices in last 6 months

z_datum = sy-datum - 180.

import v_knvv from memory id 'CUST6A'.

  • get data

select avbeln afkart avkorg afkdat

b~netwr

into corresponding fields of table t_vbrk

up to 100 rows

from ( vrkpa as a

inner join vbrk as b

on avbeln eq bvbeln )

where a~kunde eq v_knvv-kunnr

and a~parvw eq 'RG'

  • and a~vkorg eq 'EN01'

and a~vbtyp eq 'M'

and a~fkdat gt z_datum.

sort t_vbrk by fkdat descending.

*data: gt_hyperlink type standard table of g_type_s_hyperlink.

  • Instead of if_salv_c_bool_sap=>false, you can pass the

  • value if_salv_c_bool_sap=>true to this method to

  • see your ALV as a list.

  • display data in Grid / List

TRY.

CALL METHOD cl_salv_table=>factory

EXPORTING

list_display = if_salv_c_bool_sap=>false

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = t_vbrk.

CATCH cx_salv_msg.

ENDTRY.

try.

LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

ls_color-col = col_negative.

ls_color-int = 0.

ls_color-inv = 0.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'VBELN' ).

ls_color-col = col_negative.

ls_color-int = 1.

ls_color-inv = 1.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

*LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

lr_column->set_short_text( 'Short' ).

lr_column->set_medium_text( 'Medium' ).

lr_column->set_long_text( 'Net Value' ).

*lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'URL' ).

*

catch cx_salv_not_found.

endtry.

gr_table->set_screen_status( pfstatus = 'SALV_STANDARD'

report = sy-repid

set_functions = gr_table->c_functions_all ).

  • this statement actually does the display.

gr_table->display( ).

ENDFUNCTION.

FUNCTION Z_DISPLAY_MATERIAL.

*"----


""Lokale interface:

*"----


s_name = 'S_VBAP'.

  • invoicesrs in last 6 months

z_datum = sy-datum - 180.

import v_knvv from memory id 'CUST6A'.

  • get data

select avbeln bmatnr barktx bnetwr b~kwmeng

into corresponding fields of table t_vbap

up to 100 rows

from ( vakpa as a

inner join vbap as b

on avbeln eq bvbeln )

where a~kunde eq v_knvv-kunnr

and a~parvw eq 'AG'

  • and a~vkorg eq 'EN01'

and a~trvog eq '0'

and a~audat gt z_datum.

TRY.

CALL METHOD cl_salv_table=>factory

EXPORTING

list_display = if_salv_c_bool_sap=>false

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = t_vbap.

CATCH cx_salv_msg.

ENDTRY.

try.

LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

ls_color-col = col_negative.

ls_color-int = 0.

ls_color-inv = 0.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'ARKTX' ).

ls_color-col = col_negative.

ls_color-int = 1.

ls_color-inv = 1.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

*LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

lr_column->set_short_text( 'Short' ).

lr_column->set_medium_text( 'Medium' ).

lr_column->set_long_text( 'Net Value' ).

*lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'URL' ).

*

catch cx_salv_not_found.

endtry.

gr_table->set_screen_status( pfstatus = 'SALV_STANDARD'

report = sy-repid

set_functions = gr_table->c_functions_all ).

  • this statement actually does the display.

gr_table->display( ).

ENDFUNCTION.

hope this helps.

kindly reward if found helpful.

cheers,

Hema.

4 REPLIES 4

Former Member
0 Kudos

Hi PB, this will help u.

Business Add-Ins

Business Add-Ins are a new SAP enhancement technique based on ABAP Objects. 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 (SMOD/CMOD [Page 40]), two different views are available:

• In the definition view, an application programmer predefines exit points in a source that allow specific industry sectors, partners, and customers to attach additional software 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 logic if one is available.

In contrast to customer exits, Business Add-Ins no longer assume a two-system infrastructure (SAP and customers), but instead allow for multiple levels of software development (by SAP, partners, and customers, and as country versions, industry solutions, and the like). Definitions and implementations of Business Add-Ins can be created at each level within such a system infrastructure.

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 control add-in implementation and make it dependent on specific criteria (on a specific Country value, for example). All ABAP sources, screens, GUIs, and table interfaces created using this enhancement technique are defined in a manner that allows 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. In Release 4.6A, program and menu enhancements can be made with Business Add-Ins. The actual program code is enhanced using ABAP Objects. In order to better understand the programming techniques behind the Business Add-In enhancement concept, SAP recommends reading the section on ABAP Objects

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

http://help.sap.com/saphelp_nw04/helpdata/en/e6/d54d3c596f0b26e10000000a11402f/content.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/c2/eab541c5b63031e10000000a155106/frameset.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.

BADI creation:

REPORT Z_BADI_TEST.

  • test call Badi from standard abap. (Only from rel 6.40 and above)

  • do the following

  • 1) define the Badi (SE18). For Abap call test uncheck multiple use

  • and filter boxes

  • 2) Implement the badi (SE19). Add any methods here in the implemntation

  • 3) activate

*

  • 4) define the standard class exithandler to the abap. This class is the "Badi caller

"

  • 5) define an exit variable referring to your Badi Implementation interface

  • this interface will normally be something like ZIF_EX***************

  • You will see this in SE18/SE19.

*

  • 6) Instantiate your instance of the badi (method call get_instance)

  • 7) Now call any method(s) in the Badi.

*

class cl_exithandler definition load. "Declaration

data exit type ref to zif_ex__jimbotest. "Interface reference

data yes type c.

data: v_knvv type knvv. "Used in Fmod call in Badi methods

start-of-selection.

yes = ' '.

selection-screen begin of block b1.

parameters: r1 radiobutton group rad1,

r2 radiobutton group rad1,

r3 radiobutton group rad1.

selection-screen end of block b1.

parameters: p_kunnr type knvv-kunnr.

select single * into v_knvv

from knvv

where kunnr eq p_kunnr.

export v_knvv to memory id 'CUST6A'. "Save customer data for the function module

call method cl_exithandler=>get_instance "Factory method call

exporting "Method

exit_name = 'Z_JIMBOTEST' "Name of your BADI

  • null_instance_accepted = yes

changing instance = exit.

if not exit is initial.

break-point 1.

if r1 = 'X'.

call method exit->dispord . "Add-In call

  • changing testparm1 = word.

endif.

if r2 = 'X'.

call method exit->dispfakt.

endif.

if r3 = 'X'.

call method exit->dispmat.

endif.

In the badi methods

1)

method ZIF_EX__JIMBOTEST~DISPORD.

CALL FUNCTION 'Z_DISPLAY_CUST'.

endmethod.

2)

method ZIF_EX__JIMBOTEST~DISPFAKT.

CALL FUNCTION 'Z_DISPLAY_FAKT'.

endmethod

3)

method ZIF_EX__JIMBOTEST~DISPMAT.

CALL FUNCTION 'Z_DISPLAY_CUST'.

endmethod.

Copy via SE 41 the status SALV_STANDARD from standard SAP program SALV_DEMO_METADATA into the main program where you've created the 3 function modules below (SAP______TOP)

Global Data for the three function modules I'm calling

FUNCTION-POOL Z_BADI_KNVV. "MESSAGE-ID ..

include <color>.

include <icon>.

include <symbol>.

tables: zknvv.

data: v_zzkvgr6 TYPE KNVV-ZZKVGR6.

data: choice1 type c.

data: choice2 type c.

data: choice3 type c.

data: choice4 Type c.

data: ok-code(5) type c.

data: answer type string.

data: value1 type SPOP-VARVALUE1.

data: answer1 type string.

tables: vbak, vbap, vakpa, vbrk, vrkpa.

data: lr_functions type ref to cl_salv_functions_list.

constants: gc_true type sap_bool value 'X',

gc_false type sap_bool value space.

  • add for colour displays

data: ls_color type lvc_s_colo.

DATA : LV_SALV_COLUMNS_TABLE TYPE REF TO CL_SALV_COLUMNS_TABLE.

data: lr_columns type ref to cl_salv_columns_table,

lr_column type ref to cl_salv_column_table.

Data:

gr_table TYPE REF TO cl_salv_table.

data: z_datum type sy-datum.

data: v_knvv type knvv.

data : begin of s_vbak,

vkorg type vakpa-vkorg,

vkgrp type vakpa-vkgrp,

vtweg type vakpa-vtweg,

spart type vakpa-spart,

auart type vakpa-auart,

vbeln type vakpa-vbeln,

bstnk type vakpa-bstnk,

audat type vakpa-audat,

netwr type vbak-netwr,

end of s_vbak.

data : begin of s_vbrk,

vbeln type vrkpa-vbeln,

vkorg type vrkpa-vkorg,

fkart type vrkpa-fkart,

fkdat type vrkpa-fkdat,

netwr type vbrk-netwr,

end of s_vbrk.

data: begin of s_vbap,

matnr type vbap-matnr,

arktx type vbap-arktx,

netwr type vbap-netwr,

kwmeng type vbap-kwmeng,

end of s_vbap.

data: t_vbap like table of s_vbap.

data: t_vbak

like table of s_vbak.

data: t_vbrk

like table of s_vbrk.

data: s_name type tabname.

data: gr_selections type ref to cl_salv_selections.

data: gr_events type ref to cl_salv_events_table.

Source code of the function modules.

Function modules

FUNCTION Z_DISPLAY_CUST.

*"----


""Lokale interface:

*"----


s_name = 'S_VBAK'.

  • orders in last 6 months

z_datum = sy-datum - 180.

import v_knvv from memory id 'CUST6A'.

  • get data

select avkorg aaudat avkgrp avtweg aspart aauart abstnk avbeln b~netwr

into corresponding fields of table t_vbak

up to 100 rows

from ( vakpa as a

inner join vbak as b

on avbeln eq bvbeln )

where a~kunde eq v_knvv-kunnr

and a~parvw eq 'AG'

  • and a~vkorg eq 'EN01'

and a~trvog eq '0'

and a~audat gt z_datum.

sort t_vbak by audat descending.

*data: gt_hyperlink type standard table of g_type_s_hyperlink.

  • Instead of if_salv_c_bool_sap=>false, you can pass the

  • value if_salv_c_bool_sap=>true to this method to

  • see your ALV as a list.

  • display data in Grid / List

TRY.

CALL METHOD cl_salv_table=>factory

EXPORTING

list_display = if_salv_c_bool_sap=>false

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = t_vbak.

CATCH cx_salv_msg.

ENDTRY.

try.

LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

ls_color-col = col_negative.

ls_color-int = 0.

ls_color-inv = 0.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'VBELN' ).

ls_color-col = col_negative.

ls_color-int = 1.

ls_color-inv = 1.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

*LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

lr_column->set_short_text( 'Short' ).

lr_column->set_medium_text( 'Medium' ).

lr_column->set_long_text( 'Net Value' ).

*lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'URL' ).

*

catch cx_salv_not_found.

endtry.

gr_table->set_screen_status( pfstatus = 'SALV_STANDARD'

report = sy-repid

set_functions = gr_table->c_functions_all ).

  • this statement actually does the display.

gr_table->display( ).

ENDFUNCTION.

FUNCTION Z_DISPLAY_FAKT.

*"----


""Lokale interface:

*"----


s_name = 'S_VBRK'.

  • invoices in last 6 months

z_datum = sy-datum - 180.

import v_knvv from memory id 'CUST6A'.

  • get data

select avbeln afkart avkorg afkdat

b~netwr

into corresponding fields of table t_vbrk

up to 100 rows

from ( vrkpa as a

inner join vbrk as b

on avbeln eq bvbeln )

where a~kunde eq v_knvv-kunnr

and a~parvw eq 'RG'

  • and a~vkorg eq 'EN01'

and a~vbtyp eq 'M'

and a~fkdat gt z_datum.

sort t_vbrk by fkdat descending.

*data: gt_hyperlink type standard table of g_type_s_hyperlink.

  • Instead of if_salv_c_bool_sap=>false, you can pass the

  • value if_salv_c_bool_sap=>true to this method to

  • see your ALV as a list.

  • display data in Grid / List

TRY.

CALL METHOD cl_salv_table=>factory

EXPORTING

list_display = if_salv_c_bool_sap=>false

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = t_vbrk.

CATCH cx_salv_msg.

ENDTRY.

try.

LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

ls_color-col = col_negative.

ls_color-int = 0.

ls_color-inv = 0.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'VBELN' ).

ls_color-col = col_negative.

ls_color-int = 1.

ls_color-inv = 1.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

*LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

lr_column->set_short_text( 'Short' ).

lr_column->set_medium_text( 'Medium' ).

lr_column->set_long_text( 'Net Value' ).

*lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'URL' ).

*

catch cx_salv_not_found.

endtry.

gr_table->set_screen_status( pfstatus = 'SALV_STANDARD'

report = sy-repid

set_functions = gr_table->c_functions_all ).

  • this statement actually does the display.

gr_table->display( ).

ENDFUNCTION.

FUNCTION Z_DISPLAY_MATERIAL.

*"----


""Lokale interface:

*"----


s_name = 'S_VBAP'.

  • invoicesrs in last 6 months

z_datum = sy-datum - 180.

import v_knvv from memory id 'CUST6A'.

  • get data

select avbeln bmatnr barktx bnetwr b~kwmeng

into corresponding fields of table t_vbap

up to 100 rows

from ( vakpa as a

inner join vbap as b

on avbeln eq bvbeln )

where a~kunde eq v_knvv-kunnr

and a~parvw eq 'AG'

  • and a~vkorg eq 'EN01'

and a~trvog eq '0'

and a~audat gt z_datum.

TRY.

CALL METHOD cl_salv_table=>factory

EXPORTING

list_display = if_salv_c_bool_sap=>false

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = t_vbap.

CATCH cx_salv_msg.

ENDTRY.

try.

LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

ls_color-col = col_negative.

ls_color-int = 0.

ls_color-inv = 0.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'ARKTX' ).

ls_color-col = col_negative.

ls_color-int = 1.

ls_color-inv = 1.

lr_column->set_color( ls_color ).

catch cx_salv_not_found.

endtry.

try.

*LV_SALV_COLUMNS_TABLE = gr_table->get_columns( ).

lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'NETWR' ).

lr_column->set_short_text( 'Short' ).

lr_column->set_medium_text( 'Medium' ).

lr_column->set_long_text( 'Net Value' ).

*lr_column ?= LV_SALV_COLUMNS_TABLE->get_column( 'URL' ).

*

catch cx_salv_not_found.

endtry.

gr_table->set_screen_status( pfstatus = 'SALV_STANDARD'

report = sy-repid

set_functions = gr_table->c_functions_all ).

  • this statement actually does the display.

gr_table->display( ).

ENDFUNCTION.

hope this helps.

kindly reward if found helpful.

cheers,

Hema.

Former Member
0 Kudos

Also PB, this will help u in BADI finding:

u can find BADI's in different ways...

1>First go to any transaction->iN THE menu bar SYSTEM->STATUS->Get the program name ->double click->u will go to the program attached to the tcode.Now search term will be CALL CL_EXITHANDLER.Now u will get list of BADI'S available..

2>Goto SE24->Give class name as CL_EXITHANDLER->Display->double click on get_instance mathod->Now u will go inside the method->Now put break point on the cl_exithandler.Now go to any transaction code and pass dat..U will see that it will be stopped on the break point which u set on the cl_exithandler...In the exit name u can find list of badi's attached to the tcode..

There are multiple ways of searching for BADI.

• Finding BADI Using CL_EXITHANDLER=>GET_INSTANCE

• Finding BADI Using SQL Trace (TCODE-ST05).

• Finding BADI Using Repository Information System (TCODE- SE84).

1. Go to the Transaction, for which we want to find the BADI, take the example of Transaction VD02. Click on System->Status. Double click on the program name. Once inside the program search for ‘CL_EXITHANDLER=>GET_INSTANCE’.

Make sure the radio button “In main program” is checked. A list of all the programs with call to the BADI’s will be listed.

The export parameter ‘EXIT_NAME’ for the method GET_INSTANCE of class CL_EXITHANDLER will have the user exit assigned to it. The changing parameter ‘INSTANCE’ will have the interface assigned to it. Double click on the method to enter the source code.Definition of Instance would give you the Interface name.

2. Start transaction ST05 (Performance Analysis).

Set flag field "Buffer trace"

Remark: We need to trace also the buffer calls, because BADI database tables are buffered. (Especially view V_EXT_IMP and V_EXT_ACT)

Push the button "Activate Trace". Start transaction VA02 in a new GUI session. Go back to the Performance trace session.

Push the button "Deactivate Trace".

Push the button "Display Trace".

The popup screen "Set Restrictions for Displaying Trace" appears.

Now, filter the trace on Objects:

• V_EXT_IMP

• V_EXT_ACT

Push button "Multiple selections" button behind field Objects

Fill: V_EXT_IMP and V_EXT_ACT

All the interface class names of view V_EXT_IMP start with IF_EX_. This is the standard SAP prefix for BADI class interfaces. The BADI name is after the IF_EX_.

So the BADI name of IF_EX_CUSTOMER_ADD_DATA is CUSTOMER_ADD_DATA

3. Go to “Maintain Transaction” (TCODE- SE93).

Enter the Transaction VD02 for which you want to find BADI.

Click on the Display push buttons.

Get the Package Name. (Package VS in this case)

Go to TCode: SE84->Enhancements->Business Add-inns->Definition

Enter the Package Name and Execute.

Here you get a list of all the Enhancement BADI’s for the given package MB.

The simplese way for finding BADI is

1. chooes Tcode Program & package for that Tcode.

2. Go to Tcode se18

3. Press F4

4. search by package or by program.

This will help in BADI user exits:

Check this link to learn more about differences between user-exits and badis:

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

Difference Between BADI and User Exits

Business Add-Ins are a new SAP enhancement technique based on ABAP Objects. 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 predefines exit points in a source that allow specific industry sectors, partners, and customers to attach additional software 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 logic 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, partner, and customer solutions, as well as country versions, industry solutions, and the like). Definitions and implementations of Business Add-Ins can be created at each level within such a system infrastructure.

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 control add-in implementation and make it dependent on specific criteria (on a specific Country value, for example).

All ABAP sources, screens, GUIs, and table interfaces created using this enhancement technique are defined in a manner that allows 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.

The actual program code is enhanced using ABAP Objects. In order to better understand the programming techniques behind the Business Add-In enhancement concept, SAP recommends reading the section on ABAP Objects.

What is difference between badi and user-exists?

What is difference between enhancements and user-exists? and what is the full form of BADI?

I have another doubt in BDC IN BDC WE HAVE MSEGCALL (i did not remember the > correct name) where the error logs are stored, MSEGCALL is a table or structure.

What is the system landscape?

1) Difference between BADI and USER-EXIT.

i) BADI's can be used any number of times, where as USER-EXITS can be used only one time.

Ex:- if your assigning a USER-EXIT to a project in (CMOD), then you can not assign the same to other project.

ii) BADI's are oops based.

2) About 'BDCMSGCOLL' it is a structure. Used for finding error records.

3) Full form of BADI 'Business addins'.

3) System land scape will be depends on your project

Ex:- 'Development server'>'Quality server'-> 'Production server'......

kindly reward if found helpful.

cheers,

Hema.

Former Member
0 Kudos

Hi,

Pls refer the following document:

http://help.sap.com/saphelp_nw04/helpdata/en/e6/d54d3c596f0b26e10000000a11402f/content.htm

Regards,

Renjith Michael.

Former Member
0 Kudos

Hi PB ,

These steps should enable you to find any BADI related to any transaction in a matter of minutes.

Procedure 1:

1) Go to the transaction SE37 to find your function module.

2) Locate the function SXV_GET_CLIF_BY_NAME.

3) Put a breakpoint there.

4) Now open a new session.

5) Go to your transaction. 6) At that time, it will stop this function.

7) Double click on the function field EXIT_NAME.

😎 That will give you name of the BADI that is provided in your transaction.

Business Add-Ins

Procedure 2:

1) Goto se24 (Display class cl_exithandler)

2) Double click on the method GET_INSTANCE.

3) Put a break point at Line no.25 (CASE sy-subrc).

4) Now Execute SAP standard transaction

5) Press the required button for which you need to write an exit logic, the execution will stop at the break point.

6) Check the values of variable 'exit_name', it will give you the BADI name called at that time.

7) This way you will find all the BADIs called on click of any button in any transaction

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.

Actually there is no transaction to find when and where the BADI

is called.

1. You can see the BADI description to find why it is called.

2. Once you implemented and activated the BADI, put some break points

in the BADI and see "where else used" option to check in what all

programs this BADI is called. In the ITS debug, when you are doing

the operation what exactly the BADI description tells, it will take

to the break points and you have to do manually debug the whole thing.

I know its bit difficult to do manual debug the whole thing, it

takes lot of time, but you have to be very patience when you are

dealing with BADI's.

Transaction SE18 is the BADI equivalent of transaction SMOD

Transaction SE19 is the BADI equivalent of transaction CMOD .

To find the BADI to be implemented and then implement this via SE19.

Check this blogs 2 find a BADI:

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

cheers!

gyanaraj

****Pls reward points if u find this helpful