如何使用新的 ABAP 语句 FOR 重新初始化 table 中的单个列

How can I reinitialize a single column in a table using the new ABAP statement FOR

我已将两个字段类别 table 附加在一起:

rt_joined = value #( ( lines of it_left ) ( lines of it_right ) ).

现在我想重新初始化新 table 的 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   

这不应该完全关闭,但是我不确定是否有必要为此使用新的 itab:

DATA(lt_initialized) = VALUE rt_joined(
                       FOR i = 1 THEN i + 1 WHILE i <= lines( rt_joined )
                       ( col_pos = i  ) ).

这使用测试示例实现了我想要的效果:

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.

必须手动移动结构中的每个字段,而且还有一个额外的 table 分配,所以我不确定它如何比较性能