Skip to Content
0

ABAP 740 inline VALUE FOR - able to create a table sourced from 2 different tables?

Jun 07, 2017 at 01:48 PM

137

avatar image

Hi everyone,

This may be a stupid question, so apologies if so. I'm aware of the VALUE iterator and the FOR iterator in order to declare a table inline, but is it possible to use 2 FOR statements to utilize 2 separate tables during declaration?

For example, tables A and B are the same type (tables of VBELN and POSNR). Normally I'd just append 1 to the other, but for the sake of understanding what's possible syntactically, can I do something like below?:

DATA(lt_vbeln_comb) = VALUE ty_vbeln_t(
FOR ls_A IN table_A   #first table
FOR ls_B IN table_B   #second table
( vbeln = #I want to use both ls_A-vbeln and ls_B-vbeln here
  posnr = 1 )

).
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Fabian Lupa Jun 07, 2017 at 02:55 PM
1

Sorry, that's the best I can come up with. Maybe look into BASE and if it can help appending the tables in an inline expression to loop over in a for expression.

TYPES: BEGIN OF gty_struct,
         name TYPE string,
         date TYPE d,
       END OF gty_struct,
       BEGIN OF gty_line,
         text   TYPE string,
         number TYPE i,
       END OF gty_line,
       gty_tab        TYPE STANDARD TABLE OF gty_line WITH DEFAULT KEY,
       gty_struct_tab TYPE STANDARD TABLE OF gty_struct WITH DEFAULT KEY,
       gty_ref_tab    TYPE STANDARD TABLE OF REF TO gty_struct_tab WITH DEFAULT KEY.

DATA(gt_tab_a) = VALUE gty_struct_tab(
  ( name = `Teststring1` date = sy-datum )
  ( name = `Teststring2` date = sy-datum )
  ( name = `Teststring3` date = sy-datum )
  ( name = `Teststring4` date = sy-datum )
).

DATA(gt_tab_b) = VALUE gty_struct_tab(
  ( name = `Teststring5` date = sy-datum )
  ( name = `Teststring6` date = sy-datum )
  ( name = `Teststring7` date = sy-datum )
  ( name = `Teststring8` date = sy-datum )
).

DATA(gt_combined) = VALUE gty_tab(
  LET tab = VALUE gty_ref_tab( ( REF #( gt_tab_a ) ) ( REF #( gt_tab_b ) ) ) IN
    FOR a IN tab
      FOR b IN a->*
      ( text = b-name number = line_index( a->*[ table_line = b ] ) )
).

cl_demo_output=>display( gt_combined ).
Share
10 |10000 characters needed characters left characters exceeded
Horst Keller
Jun 07, 2017 at 03:10 PM
0

https://help.sap.com/http.svc/rc/abapdocu_751_index_htm/7.51/en-US/index.htm?file=abenvalue_constructor_params_itab.htm

I see the option of several FORs there, furthermore, there is a BASE, a LET ...

Share
10 |10000 characters needed characters left characters exceeded
Matt Jacoby Jun 07, 2017 at 03:51 PM
0

@Horst, @Fabian, thank you, I had tried using the 2 FOR statements and had issues originally, but just tried again and now I've got the behavior I was looking for. However, I found BASE to be what I was looking for, as the 2 FOR statements caused duplicate entries the way I was trying to use them.

Share
10 |10000 characters needed characters left characters exceeded