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: 

Pass referance of veriable to method in class

Former Member
0 Kudos

Hi friends,

I am trying to use ABAP object. In that i am trying to use reference variable which is pass to method in class. Whatever the operation perform on that variable should be reflected to original variable at main method.

So how can I do that.

Message was edited by:

Amit Sontakke

4 REPLIES 4

0 Kudos

Hi,

For your method use a CHANGING parameter and use TYPE REF TO for its TYPE and then pass the data.

Then when ever you pass the data to the method the changes will e reflected in your main program.

Regards,

Sesh

Former Member
0 Kudos

Hi Amit,

Actually i didnt get ur question. Please explain in detail

Regards,

Nikhil

Former Member
0 Kudos

Hi Amit,

U can try it out. Using Pass by Value it is possible for U to access the variable inside the method.

ex:-

DATA : num type i.

CLASS c1 definition.

PUBLIC SECTION.

METHODS : meth1 IMPORTING INPUT1 TYPE I

VALUE(INPUT2) TYPE I.

ENDCLASS. "c1 DEFINITION

CLASS c1 implementation.

METHOD : meth1.

" INPUT1 = 2. " input parameters passed by reference cannot be changed within the method

INPUT2 = 4.

WRITE : /5 'Input Parameters PASSED BY VALUE alone can be changed inside METHOD : ' ,INPUT1.

ENDMETHOD.

ENDCLASS. "c1 IMPLEMENTATION

START-OF-SELECTION.

DATA :oref TYPE ref TO c1.

CREATE OBJECT : oref.

num = 5.

CALL METHOD : oref->meth1 EXPORTING INPUT1 = 3

INPUT2 = num.

<u>Reward Points if Useful.</u>

Regards,

Kavitha.

Former Member
0 Kudos

Myself