01-02-2014 3:18 PM
Hi Experts,
I would like know if there are some differences between :
CALL METHOD me->myMethod
EXPORTING
field = value.
and
me->myMethod(
EXPORTING
field = value
).
Performance ? Best pratices ? One of both obsolete ?
Many thx!
Rachid.
01-02-2014 3:57 PM
HI Rachid,
There is one difference.
There are four type of parameter in Class while defining the Parameter.
1. Importing
2.Exporting
3.Changing
4.Returning.
When you are using the statement call method you can't use the return parameter.
Return parameter means you need to hold that value in same type of the returning parameter. This can't be possible using the call method.
CALL METHOD me->myMethod
EXPORTING
field = value.
But in this statement it is possible.
Suppose your Method has one return parameter with name R_ITem with the Int2 and you must be hold the value of the parameter.
me->myMethod(
EXPORTING
field = value
).
Ebelp = me->mymethod( ).
Now the return value is automatically store in the ebelp Field.
Regards,
Nishant Bansal
01-02-2014 3:31 PM
Hi,
There is no difference me->method( ) is short version of call method. actualy you can write method( ) too,
But if you need to call your method dynamic you cant use shorted version you need to write call method. example from CALL METHOD help (F1)
TRY.
CALL METHOD (class)=>(meth)
PARAMETER-TABLE
ptab
EXCEPTION-TABLE
etab.
CASE sy-subrc.
WHEN 1.
...
...
ENDCASE.
CATCH cx_sy_dyn_call_error INTO exc_ref.
exc_text = exc_ref->get_text( ).
MESSAGE exc_text TYPE 'I'.
ENDTRY.
and for static method call, CALL METHOD object=>static_method is obsolete.
Regards
01-02-2014 3:46 PM
and for static method call, CALL METHOD object=>static_method is obsolete.
How do you newly call a Static Method ?
01-02-2014 3:53 PM
Hi Rachid,
Just look at call method help you can see obsolete usage of call method.
here is the recommended way
c1=>do_something(
EXPORTING p1 = 333
p2 = 444
IMPORTING p3 = result ).
01-02-2014 3:57 PM
HI Rachid,
There is one difference.
There are four type of parameter in Class while defining the Parameter.
1. Importing
2.Exporting
3.Changing
4.Returning.
When you are using the statement call method you can't use the return parameter.
Return parameter means you need to hold that value in same type of the returning parameter. This can't be possible using the call method.
CALL METHOD me->myMethod
EXPORTING
field = value.
But in this statement it is possible.
Suppose your Method has one return parameter with name R_ITem with the Int2 and you must be hold the value of the parameter.
me->myMethod(
EXPORTING
field = value
).
Ebelp = me->mymethod( ).
Now the return value is automatically store in the ebelp Field.
Regards,
Nishant Bansal
01-02-2014 4:00 PM
Actualy you can use for returning too.
CALL METHOD object->method
RECEIVING
return_param = lv_param.
But you cant use it like variable
for example.
IF object->is_exist( ) EQ 'X'.
* Do something.
ENDIF.
you cant use call method like this
01-02-2014 5:23 PM