‎2008 Jun 09 7:35 AM
Hi Experts !
plz tell me the difference between exporting/importing /returning parameters while defining class.
thanks
‎2008 Jun 09 8:04 AM
Hi Ranjna,
Parameters are used in the implementation part of the CLASS not the definition part that too in the methods.
Methods are internal procedures in classes that determine the behavior of the
objects. They can access all attributes in their class and can therefore change the
state of other elements.
Methods have a signature (interface parameters and exceptions) that enables them
to receive values when they are called and pass values back to the calling program.
Methods can have any number of IMPORTING, EXPORTING, and CHANGING
parameters. All parameters can be passed by value or reference.
One method return value can be defined using the RETURN parameter. It
must always be transferred as a value. In this case, you cannot then define the
EXPORTING and CHANGING parameters. You can also use the RETURNING
parameter to define functional methods. This will be discussed in more detail
later.
All input parameters (IMPORTING and CHANGING parameters) can be defined
as optional parameters in the declaration using the OPTIONAL or DEFAULT
additions. These parameters then do not necessarily have to be transferred when
the object is called. If you use the OPTIONAL addition, the parameter remains
initialized according to type, whereas the DEFAULT addition allows you to enter
a start value.
Like function modules, methods also support the return value SY-SUBRC,
but only if the signature exceptions were defined using EXCEPTIONS. As of
SAP Web AS 6.10, the RAISING addition can be used in its place to propagate
class-based exceptions. The caller then handles these class-based exceptions
without evaluating the SY-SUBRC return value.
Methods also have to be assigned to a visibility section. This determines whether
the methods are called from outside the class or only from within the class. Thus,
private methods only serve the purpose of internal modularization.
You define private methods in the PRIVATE SECTION of a class. You define
public attributes in the PUBLIC SECTION.
It is not possible to directly access private methods from outside. However, a
private method can be called by a public method.
Hope this is useful to you. Reward points if useful.
Regards,
Sekhar
‎2008 Jun 09 8:54 AM
Hi!
Thanks for your useful reply .but plz explain me RETURN parameter in details .
‎2008 Jun 09 8:57 AM
You know that the above answer was just taken from the help documentation? You could have saved time looking it up yourself.
‎2008 Jun 09 11:28 AM
‎2008 Jun 12 10:26 AM
Hi,
The return works like the inline function in C++. So you can have only one returning parameter. But one can export multiple values.
On the other hand Changing corresponds to the pass by reference school of thought.
These are not exact explanations, but just to make u understand.
Please reward, if it is helpful.
Regards,
Subhra
‎2008 Jun 12 10:46 AM
Hi,
There are generally 4 parameters:
1. Importing
2. Exporting/Changing/Returning.
Importing is used for passing value from the calling program.
For returning the value one can use Exporting/Changing/Returning.
Returning has some limitations.
a. Only one value can be returned. (a simple example is constructor which returns object)
b. If returning is used Exporting/Changing cannot be used.
Exporting is used to transfer multiple values, while changing is used if you have a huge data in the calling program that needs to be accesed here. This is more to do with memory management.
I hope this clarifies.
Regards,
Saurabh