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

Conversion .NET to ABAP Object

Former Member
0 Likes
463

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
416

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

3 REPLIES 3
Read only

Former Member
0 Likes
417

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

Read only

0 Likes
416

Thanks. Anyway i still need a reference variable to return a object and add parameter in the function. But thanks for your help

Read only

thomasalexander_ritter
Product and Topic Expert
Product and Topic Expert
0 Likes
416

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