Application Development 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: 

abap object syntax

Former Member
0 Kudos

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.

1 REPLY 1

Former Member
0 Kudos

hi

1. from your question

4) may i know if both the same?

METHODS acknowledge IMPORTING creator TYPE REF TO client

DATA creator TYPE REF TO client.

the above are not same

METHODS acknowledge IMPORTING creator TYPE REF TO client - here you declared creator as a variable to get input for the method acknowledge.

DATA creator TYPE REF TO client. - here you declared creator as an object and it refrencing client class to access all the methods defined in client class.

pls see below

data : creator type ref to client.

create object creator.

call method creator->acknowledge.

2. from your question

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?

here you delcare like following .

METHODS acknowledge IMPORTING creator type c.

and you need to change this code too

CALL METHOD server_ref->acknowledge EXPORTING creator = name.

insted of.

CALL METHOD server_ref->acknowledge EXPORTING creator = me.

and you have to remove this like below.

name = creator.

instead of

name = creator->name.

3. from your question.

METHODS: set_value IMPORTING im_value TYPE i

or METHODS acknowledge IMPORTING creator TYPE REF TO client.

METHODS: set_value IMPORTING im_value TYPE i - this code is correct.

METHODS acknowledge IMPORTING creator TYPE REF TO client.- this is also correct here you referencing the class client that's it.

4. from your question.

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.

it deponds how you delcare those variables in the class like following.

CLASS counter DEFINITION.

PUBLIC SECTION.

METHODS: set IMPORTING value(set_value) TYPE i,

increment,

get EXPORTING value(get_value) TYPE i.

PRIVATE SECTION.

DATA number TYPE i VALUE 5.

CALL METHOD cnt->set EXPORTING set_value = number.

or

CALL METHOD cnt->set( number ).

here you are getting value from variable number.

for importing you got to declare like following

CALL METHOD cnt->get importing get_value = number.

here you are passing value from get_value to number.

check ABAPDOCU tcode and see the samples abap objects.

regards

sarath