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

append returning lines

Former Member
5,410

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
Read only

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

Softwaris
Participant
0 Likes
4,189

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.

Read only

pokrakam
Active Contributor
4,190
data(messages) = thingy->do_stuff( ). 
append lines of thingy->do_more_stuff( ) to messages. 
Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
4,189

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

-- Tomas --
Read only

0 Likes
4,189

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

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
4,189

The following should work:

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

But even better:

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

Read only

4,189

Shouldn't it be this?

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

4,189

Depending on the use case sure ...

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
4,189

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

Read only

Former Member
4,189

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

Read only

4,189

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

0 Likes
4,189

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

Read only

4,189

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