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

Commit work in BADI

Former Member
0 Likes
1,204

Dear Friends,

I need help to record texts inside the Production Order, using the method "cl_binary_relation=>create_link".

My current report calls this method from a production order BADI, but without a COMMIT WORK the texts are not updated into the database. Nevertheless, if I put the COMMIT WORK statement, the exception COMMIT_IN_PERFORM_ON_COMMIT is triggered.

I have tested the solution from a test report (a copy of the source code that is inside the BADI report), with the COMMIT WORK.

Thanks in advance,

Marcelo Perine

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
708

Hi this may be of some help for 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.

with regards,

Hema SUndara.

pls reward points if u find it needful.

3 REPLIES 3
Read only

Former Member
0 Likes
709

Hi this may be of some help for 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.

with regards,

Hema SUndara.

pls reward points if u find it needful.

Read only

Former Member
0 Likes
708

Thanks for the answer.

The BADI was created. The problem is the COMMIT WORK in BADI that generates the DUMP.

Best regards,

Marcelo Perine

Read only

Former Member
0 Likes
708

I found the link http://help.sap.com/saphelp_crm30/helpdata/en/b7/305b3a201b9c5ee10000000a114084/content.htm that says "The relationship is created in the update, either by committing to work by the application or when an ABAP - OO-transaction is completed."

How can terminate the transaction ABAP - OO? Recalling that I am using the method cl_binary_relation => create_link

To help, I am posting the code ABAP.

BADI

>METHOD if_ex_workorder_update~before_update.

> PERFORM grava_texto_nota IN PROGRAM zvm_ppr0008 >IF FOUND

> TABLES it_header

> it_item.

>ENDMETHOD.

Program zvm_ppr0008 - Form grava_texto_nota

>REPORT zvm_ppr0008.

>FORM grava_texto_nota TABLES t_header STRUCTURE caufvdb

> t_item STRUCTURE afpob.

>

> INCLUDE <cntn01>.

>

> CLASS cl_binary_relation DEFINITION LOAD.

> CLASS cl_obl_object DEFINITION LOAD.

>

> TYPES: BEGIN OF ty_message_key,

> foltp TYPE so_fol_tp,

> folyr TYPE so_fol_yr,

> folno TYPE so_fol_no,

> doctp TYPE so_doc_tp,

> docyr TYPE so_doc_yr,

> docno TYPE so_doc_no,

> fortp TYPE so_for_tp,

> foryr TYPE so_for_yr,

> forno TYPE so_for_no,

> END OF ty_message_key.

>

> DATA: lv_message_key TYPE ty_message_key,

> lo_message TYPE swc_object,

> lt_doc_content TYPE STANDARD TABLE OF soli-line WITH HEADER LINE,

> t_conf_out LIKE conf_out OCCURS 0 WITH HEADER LINE,

> t_qmttextos LIKE zvm_qmttextos OCCURS 0 WITH HEADER LINE.

>

> DATA:

> v_botype LIKE obl_s_pbor-typeid VALUE 'BUS2005',

> v_bo_id LIKE obl_s_pbor-instid,

> v_docty LIKE obl_s_pbor-typeid VALUE 'MESSAGE',

> v_msgtyp LIKE sofm-doctp VALUE 'RAW',

> v_reltyp LIKE mdoblrel-reltype VALUE 'NOTE',

> v_linh LIKE vbap-zzvm_linh,

> v_ptp LIKE vbap-zzvm_ptp,

> v_toto LIKE vbap-zzvm_toto,

> v_acab LIKE vbap-zzvm_acab.

>

> GET PARAMETER ID 'ZVM_PPR0008-LINH' FIELD v_linh. "Product Line

> GET PARAMETER ID 'ZVM_PPR0008-PTP' FIELD v_ptp. "PTP

> GET PARAMETER ID 'ZVM_PPR0008-TOTO' FIELD v_toto. "Heattreatcondition

> GET PARAMETER ID 'ZVM_PPR0008-ACAB' FIELD v_acab. "Finishing

>

> READ TABLE t_header INDEX 1.

> READ TABLE t_item INDEX 1.

>

> MOVE t_header-aufnr TO v_bo_id.

>

> SELECT *

> FROM zvm_qmttextos

> INTO TABLE t_qmttextos

> WHERE zcliente = t_item-kunnr

> AND matnr = t_header-matnr

> AND codlinha = v_linh

> AND codptp = v_ptp

> AND codacab = v_acab

> AND codtoto = v_toto.

>

> LOOP AT t_qmttextos.

>

> swc_create_object lo_message 'MESSAGE' lv_message_key.

>

> swc_container lt_message_container.

>

> swc_set_element lt_message_container 'DOCUMENTTITLE' t_qmttextos-tdnameor.

> swc_set_element lt_message_container 'DOCUMENTLANGU' 'E'.

> swc_set_element lt_message_container 'NO_DIALOG' 'X'.

> swc_set_element lt_message_container 'DOCUMENTNAME' v_docty.

> swc_set_element lt_message_container 'DOCUMENTLANGU' 'E'.

> swc_set_element lt_message_container 'DOCUMENTTYPE' v_msgtyp.

>

> lt_doc_content = t_qmttextos-tdnamecq.

> APPEND lt_doc_content.

>

> swc_set_element lt_message_container 'DocumentContent' lt_doc_content.

> swc_call_method lo_message 'CREATE' lt_message_container.

>

> swc_refresh_object lo_message.

>

> swc_get_object_key lo_message lv_message_key.

>

> DATA: lo_is_object_a TYPE sibflporb.

>

> lo_is_object_a-instid = v_bo_id.

> lo_is_object_a-typeid = v_botype.

> lo_is_object_a-catid = 'BO'.

>

> DATA: lo_is_object_b TYPE sibflporb.

>

> lo_is_object_b-instid = lv_message_key.

> lo_is_object_b-typeid = v_docty.

> lo_is_object_b-catid = 'BO'.

>

> CALL METHOD cl_binary_relation=>create_link

> EXPORTING

> is_object_a = lo_is_object_a

> is_object_b = lo_is_object_b

> ip_reltype = v_reltyp.

>

>* commit work "Here i need to use commit work but the exception COMMIT_IN_PERFORM_ON_COMMIT is triggered

>

> ENDLOOP.

>ENDFORM. "grava_texto_nota