2007 Jun 03 3:55 PM
hyyy guys,
How to translate ABAP method in .net , if I make function and return of object class.
etc ;
public AbstractClass CreateSomething()
{
return new ClassA();
}
I just know that ABAP use CREATE OBJECT <cref>, but that method require
reference variable. How can I solve the problem?
Thanks
2007 Jun 03 4:26 PM
Hi there,
Consider the following scenario.. In the class definition you specify what the return type is in exporting parameter (in this case we have some class defined as 'lcl_abstract' as an example).
CLASS lcl_test DEFINITION.
PUBLIC SECTION.
METHODS: createsomething
EXPORTING my_obj TYPE REF TO lcl_abstract.
ENDCLASS.
CLASS lcl_test IMPLEMENTATION.
METHOD: createsomething.
CREATE OBJECT my_obj.
ENDMETHOD.
ENDCLASS.
------------------------------
DATA: obj_ref TYPE REF TO lcl_abstract,
test_ref TYPE REF TO lcl_test.
START-OF-SELECTION.
CREATE OBJECT test_ref.
test_ref->createsomething( importing my_obj = obj_ref ).Message was edited by:
DanielY
Hi there,
Consider the following scenario.. In the class definition you specify what the return type is in exporting parameter (in this case we have some class defined as 'lcl_abstract' as an example).
CLASS lcl_test DEFINITION.
PUBLIC SECTION.
METHODS: createsomething
EXPORTING my_obj TYPE REF TO lcl_abstract.
ENDCLASS.
CLASS lcl_test IMPLEMENTATION.
METHOD: createsomething.
CREATE OBJECT my_obj.
ENDMETHOD.
ENDCLASS.
------------------------------
DATA: obj_ref TYPE REF TO lcl_abstract,
test_ref TYPE REF TO lcl_test.
START-OF-SELECTION.
CREATE OBJECT test_ref.
test_ref->createsomething( importing my_obj = obj_ref ).Message was edited by:
DanielY
2007 Jun 03 4:26 PM
Hi there,
Consider the following scenario.. In the class definition you specify what the return type is in exporting parameter (in this case we have some class defined as 'lcl_abstract' as an example).
CLASS lcl_test DEFINITION.
PUBLIC SECTION.
METHODS: createsomething
EXPORTING my_obj TYPE REF TO lcl_abstract.
ENDCLASS.
CLASS lcl_test IMPLEMENTATION.
METHOD: createsomething.
CREATE OBJECT my_obj.
ENDMETHOD.
ENDCLASS.
------------------------------
DATA: obj_ref TYPE REF TO lcl_abstract,
test_ref TYPE REF TO lcl_test.
START-OF-SELECTION.
CREATE OBJECT test_ref.
test_ref->createsomething( importing my_obj = obj_ref ).Message was edited by:
DanielY
2007 Jun 04 4:13 AM
Thanks. Anyway i still need a reference variable to return a object and add parameter in the function. But thanks for your help
2007 Jun 05 4:37 AM
Hi,
have a look at this code. The method createsomething now has a returning parameter + you can see how you to use the word TYPE to actually specify the concrete class which inherits from the abstract class.
CLASS lcl_test DEFINITION.
PUBLIC SECTION.
METHODS: createsomething RETURNING VALUE(my_obj) TYPE REF TO lcl_abstract.
ENDCLASS.
CLASS lcl_test IMPLEMENTATION.
METHOD: createsomething.
CREATE OBJECT my_obj type ClassA.
ENDMETHOD.
ENDCLASS. cheers
Thomas
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |