‎2008 Mar 19 11:52 AM
hi,
i have one doubt how to declare an interface to a radio butoon selection functionality(MEANS SEE CODE ),i m here sending the coding where its poping uup an error as iref_data can not be converted into type o_cuswtomer .herezcl_customer and zcl_salesorder, are classes declared globally in se24 and zif_data is an interface declared in se25(globally)
methods i used in thes calsses are create ,change and display(these three methods i have created)if u find any solution kindly help me me
selection-screen:begin of block b1 with frame title text-030.
parameter: rb_cus radiobutton group r1,
rb_order radiobutton group r1.
selection-screen:end of block b1.
selection-screen:begin of block b2 with frame title text-030.
parameters:rb_crea radiobutton group g1,
rb_chan radiobutton group g1,
rb_dis radiobutton group g1.
selection-screen:end of block b2.
*interface declaration.
INTERFACE zif_data.
methods:create,
change,
display.
endinterface.
*refrence variables.
data:o_customer type ref to zcl_customer,
o_sorder type ref to zcl_salesorder,
iref_data TYPE REF TO zif_data.
***************selection-criteria****************
start-of-selection.
if rb_cus = 'X'.
iref_data = o_customer.
elseif
rb_order = 'X'.
iref_data = o_sorder.
endif.
if rb_crea = 'X'.
call method iref_data->create.
elseif
rb_chan = 'X'.
call method iref_data-> change.
elseif
rb_dis = 'X'.
call method iref_data-> display.
endif.
end-of-selection.
‎2008 Mar 20 4:22 PM
Raj,
this is because iref_data and o_customer / o_salesorder are two totally different 'objects'. You probably want to implement the interface in both classes(add ZIF_DATA as an interface on the interface tab of the class) and use the display and change method of the interface, or not?
Assuming, zcl_customer and zcl_salesorder are classes that can be instantiated. If so, I don't see in your coding that you do (CREATE OBJECT o_customer / o_salesorder). Meaning, when trying the call the interface method (create, change, display, or whatever method this interface has) through the instances of the classes, you will get a short dump.
Please, explain more about how and what exactly it is you want to do.
If I'm not wrong, than you probably want something like this:
Implement interface in both classes (interface tab). Now you can use the methods of the interface via the instances of the class. I guess, both zcl_customer and zcl_salesorder can be instantiated (create an instance via CREATE OBJECT o_customer, which will call the constructor method of the class).
You now have an instance of the class, meaning you can call an interface method as follows:
call method o_customer->zif_data~display.
Kind regards,
Micky.
‎2008 Mar 21 7:26 AM
Hi,
First check u have added the u r interface in two global classes
zcl_customer and zcl_salesorder classes in interface tab.
Regards
Pratap.M
‎2008 Mar 21 9:36 AM
Hi,
I developed the code in local class:
interface I1.
METHODS : CREATE,
CHANGE,
DISPLAY .
ENDINTERFACE.
CLASS cl_customer DEFINITION.
PUBLIC SECTION.
INTERFACES : I1.
ENDCLASS.
CLASS cl_customer IMPLEMENTATION.
METHOD I1~CREATE.
WRITE:/5 'I am CREATE method in c1'.
ENDMETHOD.
METHOD I1~CHANGE.
WRITE:/5 'I am CHANGE method in c1'.
ENDMETHOD.
METHOD I1~DISPLAY.
WRITE:/5 'I am DISPLAY method in c1'.
ENDMETHOD.
ENDCLASS.
CLASS CL_SALESORDER DEFINITION.
PUBLIC SECTION.
INTERFACES : I1.
ENDCLASS.
CLASS CL_SALESORDER IMPLEMENTATION.
METHOD I1~CREATE.
WRITE:/5 'I am CREATE method m1 in c2'.
ENDMETHOD.
METHOD I1~CHANGE.
WRITE:/5 'I am CHANGE method m1 in c2'.
ENDMETHOD.
METHOD I1~DISPLAY.
WRITE:/5 'I am DISPLAY method m1 in c2'.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA : OREF1 TYPE REF TO CL_CUSTOMER ,
OREF2 TYPE REF TO CL_SALESORDER ,
IREF TYPE REF TO I1 .
CREATE OBJECT : OREF1 ,
OREF2 .
IREF = OREF1.
CALL METHOD IREF->CREATE.
CALL METHOD IREF->DISPLAY.
CALL METHOD IREF->CHANGE.
IREF = OREF2.
CALL METHOD IREF->CREATE.
CALL METHOD IREF->DISPLAY.
CALL METHOD IREF->CHANGE.
If it is helpful rewards points
Regards
Pratap.M