1

I have the following code snippet, that I would like to write in functional style :

 data(lt_es) = me->prepare_process_part_ztoa1( ).
 APPEND LINES OF me->prepare_process_part_protocol( ) to lt_es.

How to rewrite the code above in new ABAP 7.5?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
softshipper
  • 32,463
  • 51
  • 192
  • 400
  • Indeed, appending lines returned from one method to lines on second method of the same class is a bad architecture, this logic can be merged into single one – Suncatcher Jun 03 '19 at 10:27

2 Answers2

4

Use the LINES OF construct (available since ABAP 7.40 SP 8).

For instance, it could be something like this:

lt_es = VALUE #( BASE me->prepare_process_part_ztoa1( )
                 ( LINES OF me->prepare_process_part_protocol( ) ) ).

Whether it is better/simplier than the original, that's another question :)

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
József Szikszai
  • 4,791
  • 3
  • 14
  • 24
2

It can be also done without BASE. However one must specify the type explicitly (usage of # ends with a syntax error).

REPORT ZZZ.

DATA: lt_t1 TYPE string_table,
      lt_t2 TYPE string_table.

DATA(lt_t3) = VALUE string_table( ( LINES OF lt_t1 ) ( LINES OF lt_t2 ) ).

Would be interesting to know if this is maybe more performant than the usage of BASE if used in a loop for example.

Jagger
  • 10,350
  • 9
  • 51
  • 93
  • See [here](https://blogs.sap.com/2014/09/29/abap-news-for-740-sp08-start-value-for-constructor-expressions/#comment-82547). Seems like LINES OF really makes a copy, while BASE bascially is a move. – peterulb May 12 '19 at 17:43