Skip to Content
0

append returning lines

Feb 28 at 12:02 PM

114

avatar image

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

10 |10000 characters needed characters left characters exceeded

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

1
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Mike Pokraka Feb 28 at 02:19 PM
3
data(messages) = thingy->do_stuff( ). 
append lines of thingy->do_more_stuff( ) to messages. 
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Nice :-) I did not know that APPEND LINES supports "functional operand".

0

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

0
Horst Keller
Feb 28 at 03:52 PM
0

The following should work:

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

But even better:

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Shouldn't it be this?

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

Depending on the use case sure ...

1
Fabian Schmidt Mar 01 at 01:19 PM
0

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

Show 3 Share
10 |10000 characters needed characters left characters exceeded

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

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

0

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

2
Aris van Mazijk Feb 28 at 01:00 PM
-2

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.

Share
10 |10000 characters needed characters left characters exceeded