如何使用新的ABAP语句重新初始化表中的单个列
我将两个fieldcategory表附加在一起:如何使用新的ABAP语句重新初始化表中的单个列,abap,Abap,我将两个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. rt_处的循环。 -col_pos=sy tabix。 结束循环。
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.
rt_处的循环。
-col_pos=sy tabix。
结束循环。
是否可以使用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
报告test1。
类型:
行的开始,
col1Ⅰ型,
col2Ⅰ型,
col3Ⅰ型,
行尾,
带空键的行的itab类型标准表。
数据:带空键的行的itab2类型标准表。
“用一些初始数据填充表格
数据(itab)=值itab(
对于j=11,则j+10,直到j>40
(col1=j col2=j+1 col3=j+2))。
“结果如下:
“COL1 COL2 COL3
" 11 12 13
" 21 22 23
" 31 32 33
“现在我将该表复制到第二个表中,并尝试将col1设置为索引
itab2=itab1。
itab2=值itab(对于i=1,而i这不应该完全关闭,但是我不确定是否有必要为此使用新的itab:
DATA(lt_initialized) = VALUE rt_joined(
FOR i = 1 THEN i + 1 WHILE i <= lines( rt_joined )
( col_pos = i ) ).
DATA(lt\u初始化)=值rt\u(
对于i=1,则i+1,而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.
在itab分配时循环。
-col1=sy tabix。
结束循环。
有必要手动移动结构中的每个字段,另外还有一个额外的表分配,因此我不确定它在性能方面如何比较谢谢你的回答,Andreas。这个解决方案的问题是它清除了表中的其他列。看起来你确实需要新的itab,这意味着他说,这个解决方案并不比原来的好。如果你愿意测试,我会用一个简化的例子来更新我的问题。我自己做了这个练习后才看到这个答案。是的,我同意,在这个例子中,“经典”方法仍然是最好的。