我已将两个fieldcategory表附加在一起:
rt_joined = value #( ( lines of it_left ) ( lines of it_right ) ).
现在我想重新初始化新表的col_pos字段。
以前我会做这样的事情:
loop at rt_joined assigning <ls_fcat>.
<ls_fcat>-col_pos = sy-tabix.
endloop.
是否可以使用FOR语句(ABAP 7.4 SP8)执行此操作?
编辑:一个简单的测试示例:
report test1.
types:
begin of line,
col1 type i,
col2 type i,
col3 type i,
end of line,
itab type standard table of line with empty key.
data: itab2 type standard table of line with empty key.
"Fills the table with some initial data
data(itab) = value itab(
for j = 11 then j + 10 until j > 40
( col1 = j col2 = j + 1 col3 = j + 2 ) ).
"Results IN:
" COL1 COL2 COL3
" 11 12 13
" 21 22 23
" 31 32 33
"Now I copy the table to a second table and try to set col1 as an index
itab2 = itab1.
itab2 = value itab( for i = 1 while i <= lines( itab )
( col1 = i ) ).
"Results IN:
" COL1 COL2 COL3
" 1 0 0
" 2 0 0
" 3 0 0
"I would like this to be:
" COL1 COL2 COL3
" 1 12 13
" 2 22 23
" 3 32 33
答案 0 :(得分:4)
使用测试示例执行此操作:
itab2 = value #( for wa in itab index into idx
( col1 = idx
col2 = wa-col2
col3 = wa-col3 ) ).
itab = itab2.
但我认为这不比以前更好:
loop at itab assigning <wa>.
<wa>-col1 = sy-tabix.
endloop.
有必要手动移动结构中的每个字段,还有一个额外的表分配,所以我不确定它如何比较性能
答案 1 :(得分:1)
这不应该完全关闭,但是我不确定是否需要使用新的itab:
DATA(lt_initialized) = VALUE rt_joined(
FOR i = 1 THEN i + 1 WHILE i <= lines( rt_joined )
( col_pos = i ) ).