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 error : type of EXIT_REF1 cannot be converted to the type of EXIT_REF

Former Member
0 Kudos

Hi all,

The below was the posted earlier for BAdI. Ihave followed all the steps. And i have written the below code. Syntactically it is not showing any errors, but when i am activating i am getting error

like " The type of EXIT_REF1 cannot be converted to the type of EXIT_REF". where i am doing the mistake..??

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.

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. "" The type of EXIT_REF1 cannot be converted to the type of EXIT_REF"

call method exit_ref1->lineselection

EXPORTING

i_carrid = wa_spfli-carrid

i_connid = wa_spfli-connid.

clear wa_spfli.

Thanks in advance

krupali.

2 REPLIES 2

Former Member
0 Kudos

You are trying to assign a class instance (object) to an interface reference variable.

Just create an interface reference and use this reference variable to get the instance of the BADI.

DATA: lf_var TYPE REF TO IF_XXXX.

call method cl_exithandler =>get_instance

EXPORTING

exit_name = <badi name>

CHANGING

instance = lf_var

Call method if_var -> <methd name>

Exporting

Changing

uwe_schieferstein
Active Contributor
0 Kudos

Hello

Assuming that exit_ref (ZCL_IM_IM_LINESEL) implements interface IF_EX_BADISPFLI1 then the following coding might work:


data: exit_ref type ref to ZCL_IM_IM_LINESEL,
"exit_ref1 type ref to ZIF_EX_BADISPFLI1.
lo_intf     TYPE REF TO if_ex_badispfli1.

...
at line-selection.
check not wa_spfli-carrid is initial.
create object exit_ref.
lo_intf ?= exit_ref.

Regards

Uwe