Application Development 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: 

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

Former Member
0 Kudos

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 )

).
3 REPLIES 3

fabianlupa
Contributor

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

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

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

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

Former Member
0 Kudos

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