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: 

Method chaining

Former Member

Got a simple question on method chaining. I understand this is not a new topic and there are several threads showing examples on how to chain methods but there seems to be a small thing that makes understanding of this concept a little difficult.

I am using the class CL_SALV_TABLE where in the variable ALV is an instance of the class CL_SALV_TABLE.

While chaining, we use the below code.

alv->get_columns( )->set_optimize( ).

Now the method "get_columns" of the instance ALV returns a parameter of type CL_SALV_COLUMNS_TABLE thru which we call the method "set_optimize".

Question -> for the method call "get_columns" the returning parameter is NOT OPTIONAL. So what exactly happens behind the scenes which allow us to skip the helper variable? The instance of the variable ALV and the return parameter of the method "get_columns" are not of the object.

Can some help me understand the concept behind this?

8 REPLIES 8

former_member182550
Active Contributor

This type of method call is called a 'Functional Method' and as such can be used directly in assignments, conditions etc etc. It cannot be used for example as an argument to a function module.

There is nothing strange about things happening behind the scenes - it's a parameter with a 'Returning' rather than a 'Changing' or 'Exporting' type.

You would define it in a local class something like:

 Close_Notification         Final
                            Importing i_Notif_No              Type Notification_Number
                            Returning Value(r_State)          Type Notification_State,

And specify it in SE80 basically the same way.

0 Kudos

"It cannot be used for example as an argument to a function module."

Yes it can.

https://help.sap.com/http.svc/rc/abapdocu_751_index_htm/7.51/en-US/index.htm?file=abapcall_function_...

0 Kudos

Is that "yes it can, now", or "yes it can and it's been possible since 46c"? 😉

0 Kudos

Our system chokes:

So I think Matt nailed it. I was going to query it but I thought I'd wait till I got on a system....

raymond_giuseppi
Active Contributor
0 Kudos

Just consider that alv->get_columns( ) to be the returned parameter/object. (or read your course on OO functional syntax)

hubert_heitzer
Contributor
0 Kudos

Your statement

"Now the method "get_columns" of the instance ALV returns a parameter of type CL_SALV_COLUMNS_TABLE thru which we call the method "set_optimize"."

is not true.

Method "get_columns" of the instance ALV returns a parameter of type REF TO CL_SALV_COLUMNS_TABLE.

Your Question:

  1. alv->get_columns( )->set_optimize( ) is evaluated from left side to right
  2. alv->get_columns( ) yields a reference to an CL_SALV_COLUMNS_TABLE object
  3. message "set_optimize" is sent to this CL_SALV_COLUMNS_TABLE object
  4. CL_SALV_COLUMNS_TABLE object provides method set_optimize( ) to react on message "set_optimize"