Google Search - Blog...........

ABAP - Use Of Returning Parameters In Method - OOPS Concept.

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.
-------------------------------------------------------------------------------------------
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 .

Output 14
40
7

1 comment: