Application Development and Automation 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: 
Read only

write method in diif ways

Former Member
0 Likes
420

Hi,

i heard that i can write method in 2 ways.

1. CALL METHOD
  lp_ukm_easy->add
  EXPORTING
    it_key_mapping = lt_mappings
  IMPORTING
    es_messages    = ls_messages.

2. ls_messages = lp_ukm_easy->add (exporting = lt_mappings) .

but when i write like 2 i have error what i doing wrong ?

Regards

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
394

Lots of things wrong.

1. If the method has only one IMPORTING parameter (or one is marked as preferred), you can leave out EXPORTING in the call to the method.

2. If es_messages was a returning parameter you could use

ls_messages = lp_ukm_easy>add( lt_mappings ) .

3. No space between add and (

4. Always have a space inside the brackets.

5. Short form of what you wrote is:

  lp_ukm_easy->add(   EXPORTING it_key_mapping = lt_mappings
                      IMPORTING es_messages    = ls_messages ). 

matt

2 REPLIES 2
Read only

matt
Active Contributor
0 Likes
395

Lots of things wrong.

1. If the method has only one IMPORTING parameter (or one is marked as preferred), you can leave out EXPORTING in the call to the method.

2. If es_messages was a returning parameter you could use

ls_messages = lp_ukm_easy>add( lt_mappings ) .

3. No space between add and (

4. Always have a space inside the brackets.

5. Short form of what you wrote is:

  lp_ukm_easy->add(   EXPORTING it_key_mapping = lt_mappings
                      IMPORTING es_messages    = ls_messages ). 

matt

Read only

uwe_schieferstein
Active Contributor
0 Likes
394

Hello Vijay

The second variant you describe



DATA: lo_msglist   TYPE REF TO if_reca_message_list.

  CALL METHOD cf_reca_message_list=>create
    RETURNING
      ro_instance = lo_msglist.   " or functional method call:

  lo_msglist = cf_reca_message_list=>create( ).

is the so-called functional method call. It works - as Matt explained - only if the method has a RETURNING parameter. If a method has a RETURNING parameter it is the only returned parameter. You cannot have additional EXPORTING or CHANGING parameters besides a RETURNING parameter.

Regards

Uwe