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: 

Regarding Returning Parameter and Static method

Former Member
0 Kudos

Hi frnds,

I am learning oops ABAP. I want to use returning parameters in method and also STATIC METHOD.

If any example it will be more helpful

regards,

satya

3 REPLIES 3

seshatalpasai_madala
Active Contributor
0 Kudos

Hi,

When you have returning parameters you cannot have any other IMPORTING and CHANGING parameters.

They are called functional method and they can be used with in the IF and other logical statements.

Where as other methods cannot be used. Only methods with RETURNING parameters can be used in '=' Assignment statement.

You can use them along with this format cl->method().

As follwos if obj->istrue( ) = 'X', this is possible only for method with returning paramters.

STATIC method's can only access STATIC data of the class and they are used to operate on the static data that will be used by all the objects of the class at runtime.

That is if obj1 modify's the static data obj2 to can see that change, this is not possible with instance data.

Example.

CLASS A definition.

METHODS: constructor.

CLASS-DATA: num_obj type i.

CLASS-METHODS: get_no_obj RETURNING re_num_obj type i.

ENDCLASS.

CLASS A implementation.

METHOD constructor.

num_obj = num_obj + 1.

ENDMETHOD.

METHOD get_no_obj.

re_num_obj = num_obj.

ENDMETHOD.

ENDCLASS.

Regards

Sesh

Former Member
0 Kudos

Hi satya,

Check this out ,Its helpful.

To get some values from a method , one can use the exporting, changing or returning parameters.If one uses RETURNING parameters, the following restrictions apply:-(1) No EXPORTING/CHANGING parameters can be used for the method.(2) Only one RETURNING parameter can be used.(3) RETURNING parameters are only passed by value.This program demonstrates the use of RETURNING parameters and the various ways to call a method with RETURNING parameter to get the value into some variable.

Sample Program

</code>

report ysubdel1 message-id 00.

data : w_num type i.

class c1 definition .

public section.

methods : m1 importing input1 type i

input2 type i

returning value(result) type i .

endclass.

class c1 implementation.

method : m1.

result = input1 * 2 + input2.

endmethod.

endclass.

start-of-selection.

data : obj1 type ref to c1 .

create object obj1.

  • Syntax 1

call method obj1->m1 EXPORTING input1 = 5 input2 = 4

RECEIVING result = w_num.

write:/5 w_num .

  • Syntax 2

w_num = obj1->m1( input1 = 10 input2 = 20 ).

write:/5 w_num .

  • Syntax 3

move obj1->m1( input1 = 2 input2 = 3 ) to w_num .

write:/5 w_num .

</code>

Static method example

<code>

REPORT zstatic. .

data : num type i.

class testclass definition.

public section.

class-methods : testmethod.

endclass.

class testclass implementation.

method : testmethod.

num = 5.

write:/5 num.

endmethod.

endclass.

start-of-selection.

call method testclass=>testmethod.

</code>

Reward Points if u find helpful.

Thnks & Regards,

Rajesh

jaideeps
Advisor
Advisor
0 Kudos

hi,

check the standard example in abapdocu under the abap objects topic and chk out the methods category...there you can find how to use returning concepts..

thanks

jaideep

*reward points if useful