*&---------------------------------------------------------------------*
*& Report ZTEST *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZTEST .
* 原始结果数据table
data: begin of line occurs 0,
col1 type i value '11',
col2 type i value '22',
col3 type i value '33',
end of line.
* 实际需求展示的table有个别字段和原始数据不同
data: begin of display occurs 0,
col1 type i value '9',
y type i value '100',
x type i value '10',
end of display.
data: begin of temp,
x type i,
y type i,
end of temp.
* 初始数据
line-col1 = '44'.line-col2 = '55'.line-col3 = '66'.append line.
line-col1 = '4'.line-col2 = '5'.line-col3 = '6'.append line.
field-symbols: <fs_line> like line.
* 指针并不和特定table类型绑定
* 因此这里可以用同一段代码使不同类型的结构表从line中取值
field-symbols: <any>.
field-symbols: <t_any> type table.
assign display to <any>.
assign display[] to <t_any>.
loop at line assigning <fs_line>.
move-corresponding <fs_line> to <any>.
temp-y = <fs_line>-col3. "line表中不同名称的列
temp-x = '1000'. "其它需求结果
move-corresponding temp to <any>.
append <any> to <t_any>.
endloop.
loop at display.
write: / display-col1, display-y, display-x.
endloop.
output:
44 66 1000
4 5 3
这篇博客展示了在ABAP中如何使用指针处理不同结构的表格数据。通过示例,作者创建了两个不同结构的表格:原始数据table和实际需求展示的table,并用field-symbols和指针进行数据转换。在循环遍历原始数据并将其转换后,将结果写入到实际需求展示的table中,最后输出结果。
1889

被折叠的 条评论
为什么被折叠?



