我有一组值:" foo"," bar"," blue"。
我有一个看起来像这样的桌子:
ID | my_col
-----------
1 | foo
2 | bar
我想要设置值减去所有可用的my_col值。
[foo,bar,blue]减去[foo,bar]
结果应为"蓝色"。
如何在ABAP中执行此操作?
您是...
REPORT YYY.
TYPES string_table TYPE HASHED TABLE OF string WITH UNIQUE KEY TABLE_LINE.
DATA(gt_set1) = VALUE string_table( ( `foo` ) ( `bar` ) ( `blue` ) ).
DATA(gt_set2) = VALUE string_table( ( `foo` ) ( `bar` ) ).
DATA(gt_set1_except_set2) = FILTER string_table( gt_set1 EXCEPT IN gt_set2 WHERE table_line = table_line ).
但是,仅与HASHED
和SORTED
表一起使用。
带有标准表的其他示例:
data: set type table of string, " initial set
tab type table of string, " you table
res type table of string. " the result
set = value #( ( `foo` ) ( `bar` ) ( `blue` ) ).
tab = value #( ( `foo` ) ( `bar` ) ).
选项1:假设初始集和选项卡是标准表,您可以简单地为初始集循环,然后查看表值
在这种情况下
LOOP AT set into data(lv_set).
read table tab from lv_set transporting no fields.
check sy-subrc > 0.
append lv_set to res.
ENDLOOP.
选项2:您可以使用
中所述的临时散布表se38->环境 ->绩效示例(内部表的交集)
data: htab type hashed table of string with unique key table_line.
htab = tab. " use Hashed table as temporary working table
loop at set into lv_set.
" fast table lookup accessing with unique key O(1)
read table htab from lv_set transporting no fields.
check sy-subrc > 0.
append lv_set to res.
endloop.
free htab.
最好的问候!