2017 Jun 07 2:48 PM
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 )
).
2017 Jun 07 3:55 PM
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 ).
2017 Jun 07 4:10 PM
I see the option of several FORs there, furthermore, there is a BASE, a LET ...
2017 Jun 07 4:51 PM
@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.