‎2010 May 04 5:52 PM
Hi experts.
I'm following Sebastian Noetzel's advice to use an interface to a local class, to get a dynpro in a global class:
Summarizing my code:
1) I have a local class (in a report because I must get a dynpro) with a method.
2) I have a global interface with the same method name.
3) I have a global class, which could have to use the dynpro method (see the first point)
How must I do to declare and use all these things?
Now Iu2019m doing a big jumble:
1) REPORT myreport.
CLASS mylocalclass DEFINTION.
PUBLIC SECTION.
INTERFACES zif_myinterface.
ENDCLASS.
CLASS mylocalclass IMPLEMENTATION.
METHOD zif_myinterface~mymethod.
u2026u2026u2026u2026u2026.all-the-code-I-need-is-here ..........
ENDMETHOD.
ENDCLASS.
2) (by SE24)
INTERFACE zif_myinterface.
With one method and his parameters:
METHOD mymethod.
3) (by SE24)
(In interfaces section)
INTERFACES zif_myinterface.
(after that I can see zif_myinterface ~mymethod among the methods protected)
METHOD constructor.
u2026.
CALL METHOD zif_myinterface~mymethod
IMPORTING
Myparameters.
u2026.
ENDMETHOD.
It is wrong of course: when I debug it, I can see an empty u201Czif_myinterface ~mymethodu201D that is executed.
Can you draught the right system?
‎2010 May 27 6:48 PM
An instance of the local class needs to be passed to the global class for this to work. I'm not sure exactly what you're doing but if you're doing this in the constructor, it would go something like this:
Add importing parameter io_myinterface type ref to zif_myinterface to the constructor of the global class
so somewhere in the report where the global class is instantiated...
data: lo_mylcl type ref to mylocalclass,
lo_mygc type ref to yourglobalclass.
create object lo_mylcl.
create object lo_mygc exporting io_myinterface = lo_mylcl.
then in the constructor of the global class, you do this:
io_myinterface->zif_myinterface~mymethod( ).
Edited by: Erik Peterson on May 27, 2010 1:49 PM
‎2010 May 28 8:07 AM
I made a global class like a generic class. Everybody can instantiate this class.
When somebody instantiates it, the class is not starting from a specific report within the involved local class.
So:
data: lo_mylcl type ref to mylocalclass,
lo_mygc type ref to yourglobalclass.
How can I tell to my global class where is the local class code?
Where can I put the report/include name?
This is the question, because I can have several report with the same local class name. How can the global class find It?
Can I put an include somewhere?
Perhaps it's a banal question but I'm a newbie ...
‎2010 May 28 1:13 PM
Only the instance to the local class is needed!
As you may have found out, you can't include programs in global classes.
The local class instance doesn't need to be passed in the constructor. It could go in any other method call.
lo_my_globalclass->do_something( io_interface = lo_my_localclass ).
Maybe this example program will help you. It uses local interfaces and classes only but it should illustrate how the interface instance needs to be passed to the class. This is generic. It's not too big a strech from this program to making A_GLOBAL_CLASS global, the interface global and having the LCL_1 and LCL_2 in two different programs.
REPORT ytest.
INTERFACE lif_name.
METHODS: get_name RETURNING value(rv_name) TYPE string.
ENDINTERFACE. "LIF_NAME
CLASS a_global_class DEFINITION.
PUBLIC SECTION.
METHODS: write_name IMPORTING io_name TYPE REF TO lif_name.
ENDCLASS. "A_GLOBAL_CLASS DEFINITION
CLASS a_global_class IMPLEMENTATION.
METHOD write_name.
DATA: lv_name TYPE string.
lv_name = io_name->get_name( ).
WRITE:/ lv_name.
ENDMETHOD. "WRITE_NAME
ENDCLASS. "A_GLOBAL_CLASS IMPLEMENTATION
CLASS lcl_1 DEFINITION.
PUBLIC SECTION.
INTERFACES lif_name.
ENDCLASS. "lcl_1 DEFINITION
CLASS lcl_1 IMPLEMENTATION.
METHOD lif_name~get_name.
rv_name = 'LCL_1'.
ENDMETHOD. "LIF_NAME~GET_NAME
ENDCLASS. "lcl_1 IMPLEMENTATION
CLASS lcl_2 DEFINITION.
PUBLIC SECTION.
INTERFACES lif_name.
ENDCLASS. "lcl_2 DEFINITION
CLASS lcl_2 IMPLEMENTATION.
METHOD lif_name~get_name.
rv_name = 'LCL_2'.
ENDMETHOD. "LIF_NAME~GET_NAME
ENDCLASS. "lcl_2 IMPLEMENTATION
DATA: go_global TYPE REF TO a_global_class,
go_1 TYPE REF TO lcl_1,
go_2 TYPE REF TO lcl_2.
START-OF-SELECTION.
CREATE OBJECT go_global.
CREATE OBJECT go_1.
CREATE OBJECT go_2.
go_global->write_name( go_1 ).
go_global->write_name( go_2 ).