Skip to Content
0
Former Member
Feb 12, 2007 at 12:42 AM

abap object syntax

42 Views

hi,

i would like to seek advice on the following. thanks alot

1) in doubt1 below, may i know why needless to create object for creator but still able to define creator->name?

2) in doubt1, creator already been defined reference variable. why when i have doubt3 or doubt4 statement, i got error while compile. when i have doubt2 statement then compile succesfully.

Field "CREATOR" is unknown. It is neither in one of the specified

tables nor defined by a "DATA" statement.

3)can i say that if want to create object or assignment "creator = client_ref" like in doubt3 and doubt4, we must have data keyword to define the reference variable. reference variable defined via interface parameter in methods cannot do the create object.

4) may i know if both the same?

METHODS acknowledge IMPORTING creator TYPE REF TO client

DATA creator TYPE REF TO client.

both also define the reference variable.

syntax error if i just define "METHODS acknowledge IMPORTING creator" for the interface parameter. so if i want to create object, i need to have both statement, correct?

5) interface parameter for methods against call method/create object

methods - need to define the type

METHODS: set_value IMPORTING im_value TYPE i

or METHODS acknowledge IMPORTING creator TYPE REF TO client.

whereas

call methods/create object must have '='

correct?

6) this case only allow exporting? if not defined means defaulted to export?

call method o_app1->set_value( 10 ). vs

call method o_app1->set_value exporting im_value = p_value.

REPORT self_reference.

----


  • CLASS client DEFINITION

----


  • ........ *

----


CLASS client DEFINITION.

PUBLIC SECTION.

DATA name(10) TYPE c VALUE 'master' READ-ONLY.

METHODS create_server.

ENDCLASS.

----


  • CLASS server DEFINITION

----


  • ........ *

----


CLASS server DEFINITION.

PUBLIC SECTION.

METHODS acknowledge IMPORTING creator TYPE REF TO client. "doubt1

PRIVATE SECTION.

DATA name(10) TYPE c VALUE 'servant'.

ENDCLASS.

----


  • CLASS client IMPLEMENTATION

----


  • ........ *

----


CLASS client IMPLEMENTATION.

METHOD create_server.

DATA server_ref TYPE REF TO server.

CREATE OBJECT server_ref.

CALL METHOD server_ref->acknowledge EXPORTING creator = me.

ENDMETHOD.

ENDCLASS.

----


  • CLASS server IMPLEMENTATION

----


  • ........ *

----


CLASS server IMPLEMENTATION.

METHOD acknowledge.

DATA name TYPE string.

name = creator->name.

WRITE: me->name, 'created by', name.

ENDMETHOD.

ENDCLASS.

DATA client_ref TYPE REF TO client.

  • DATA creator TYPE REF TO client. "doubt2

START-OF-SELECTION.

CREATE OBJECT client_ref.

  • create object creator. "doubt3

  • creator = client_ref. "doubt4

CALL METHOD client_ref->create_server.