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: 

append returning lines

Hi ABAP-Experts,

i wonder if there is a better way of appending return lines to a internal table.
I have a lot of methods returning a bapiret2 tables and one main return table.

Everytime i call one of those methods i have to do this:

DATA: lt_return_temp type bapiret2_t.
lt_return_temp = zcl_class=>method().
APPEND LINES OF lt_return_temp TO rt_return.

Is there a way to write it more inline?

Something like that:

append lines of { fill_zdata( EXPORTING is_idoc_data = <s_idoc_data> CHANGING cs_customer = ls_customer ) } to rt_return.

Regards

Fabian

1 ACCEPTED SOLUTION

pokrakam
Active Contributor
data(messages) = thingy->do_stuff( ). 
append lines of thingy->do_more_stuff( ) to messages. 
12 REPLIES 12

Softwaris
Participant
0 Kudos

This might not completely answer your question but you could start with changing it to an inline data declaration which saves you at least one line 🙂

DATA(lt_return_temp) = zcl_class=>method().
APPEND LINES OF lt_return_temp TO rt_return.

Now for your append function, I don't think there is such an ABAP expression, but I could be wrong.

pokrakam
Active Contributor
data(messages) = thingy->do_stuff( ). 
append lines of thingy->do_more_stuff( ) to messages. 

0 Kudos

Nice 🙂 I did not know that APPEND LINES supports "functional operand".

-- Tomas --

0 Kudos

Thanks for sharing. How about :

append lines of thingy->do_more_stuff() to DATA(messages).

Does that work? (Since I'm currently not on a SAP system)...

horst_keller
Product and Topic Expert
Product and Topic Expert

The following should work:

APPEND LINES OF zcl_class=>method( ) TO rt_return.

But even better:

rt_return = VALUE #( ( LINES OF zcl_class=>method( ) ) ).

Shouldn't it be this?

    rt_return = value #( base rt_return ( lines of  zcl_class=>method( ) ) ).

horst_keller
Product and Topic Expert
Product and Topic Expert

Depending on the use case sure ...

horst_keller
Product and Topic Expert
Product and Topic Expert

If you read the documentation for LINES OF, you see, that there is a functional operand position behind.

THANKS.

append lines of thingy->do_more_stuff()tomessages.

or

rt_return = value #( base rt_return ( lines of  zcl_class=>method( ) ) ).

worked for me. (I thought i already tried "append lines of..". Sorry.)

I think i should take a deeper look at "value #".

Thank you all for your input and help.

Regards

Fabian

The choice comes down to what is clear and easy to read.

As an aside, I used to use messages as a returning parameter, but these days I prefer not to. Technically it’s correct and it works, but semantically having an assignment makes the log the ‘focus’ of the statement, whereas it’s really a by-product.

I think an exporting parameter puts the focus back onto what’s being executed and makes it easy for a someone to understand straight away with a quick skim of the code. As there will be a few lines, performance is not a significant factor either, so I would write it as:

thingy->do_stuff( exporting messages = data(messages) ).

thingy->do_whatever( exporting messages = data(add_messages) ).
append lines of add_messages to messages.

What would be nice (sorry can’t un-code-format this) is an append receiver function:
thingy->do_more_stuff( exporting messages = append(messages) ).

0 Kudos

An append receiver would be nice but i don´t think it´s possible. Or is it?

No, there is no such thing in ABAP. It should be technically feasible to use a function in a writer position as an implicit receiver of whatever is being written to it. It's basically what an inline declaration does.

Maybe it will happen one day, who knows what the boys and girls in Walldorf are cooking up...