‎2015 Jan 16 2:40 PM
Hi Experts,
we have many way to change a variable value.
for example:
or
I would like to know what is the best way to use CHANGING or RETURNING and in which case we have to use it ?
Thank your very much.
Rachid.
‎2015 Jan 16 2:48 PM
‎2015 Jan 16 3:08 PM
Thank you Raymond, for your answer.
Yes I know about nesting methods... I am just wondering about memory allocation?
Cause in Returning type, at the end of the method we have 2 identical memomry allocation:
and not through CHANGING type...
Any suggestion?
Rachid.
‎2015 Jan 16 7:08 PM
What's to wonder about? With returning you pass by value. With changing you can choose to pass by value or by reference. Passing by value copies the values, pass by references refers to the data object directly.
This is standard and common and not limited to OO or ABAP for that matter.
‎2015 Jan 18 7:43 PM
Hi,
yes I know about the different kind of passing data.
My question concerns the case when we have only one parameter: Which type we have to use CHANGING or RETURNING and also, why?
Rachid.
‎2015 Jan 19 6:42 AM
Which ever you want. I use returning when I want a function like call for use in expressions, changing when there's more than one value, or I want to pass by reference.
‎2015 Jan 16 8:38 PM
Hello Rachid,
newer Netweaver releases allow both a RECEIVING and CHANGING parameters. You can also introduce a parameter object and pass it as an IMPORTING parameter.
In your case I would propose to pass a pointer to your table TYPE REF TO Table_Type so you can change the table entries in the method. You could return the changed table as a value parameter without impact if it was never changed later (check table sharing in
ABAP Keyword Documentation → ABAP - Reference → Processing Internal Data → Internal Tables
As Matthew once said: There's the right way of doing things (my way)
regards,
JNN