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: 

Difference between "me->" and "Call Function me->" ?

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

nishantbansal91
Active Contributor
0 Kudos

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

6 REPLIES 6

tolga_polat
Active Participant
0 Kudos

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

0 Kudos

and for static method call, CALL METHOD object=>static_method is obsolete.

How do you newly call a Static Method ?

0 Kudos

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

nishantbansal91
Active Contributor
0 Kudos

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

0 Kudos

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

0 Kudos

interesting! Thx you guys!