‎2018 Feb 28 12:02 PM
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
‎2018 Feb 28 2:19 PM
data(messages) = thingy->do_stuff( ).
append lines of thingy->do_more_stuff( ) to messages.
‎2018 Feb 28 1:00 PM
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.
‎2018 Feb 28 2:19 PM
data(messages) = thingy->do_stuff( ).
append lines of thingy->do_more_stuff( ) to messages.
‎2018 Feb 28 2:32 PM
Nice 🙂 I did not know that APPEND LINES supports "functional operand".
‎2018 Feb 28 2:35 PM
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)...
‎2018 Feb 28 3:52 PM
The following should work:
APPEND LINES OF zcl_class=>method( ) TO rt_return.
But even better:
rt_return = VALUE #( ( LINES OF zcl_class=>method( ) ) ).
‎2018 Feb 28 4:19 PM
Shouldn't it be this?
rt_return = value #( base rt_return ( lines of zcl_class=>method( ) ) ).
‎2018 Feb 28 4:48 PM
‎2018 Feb 28 5:39 PM
If you read the documentation for LINES OF, you see, that there is a functional operand position behind.
‎2018 Mar 01 1:19 PM
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
‎2018 Mar 01 4:30 PM
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) ).
‎2018 Mar 02 3:27 PM
An append receiver would be nice but i don´t think it´s possible. Or is it?
‎2018 Mar 02 3:39 PM
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...