ABAP中的指针

这篇博客展示了在ABAP中如何使用指针处理不同结构的表格数据。通过示例,作者创建了两个不同结构的表格:原始数据table和实际需求展示的table,并用field-symbols和指针进行数据转换。在循环遍历原始数据并将其转换后,将结果写入到实际需求展示的table中,最后输出结果。
*&---------------------------------------------------------------------*
*& 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
-= <fs_line>-col3.      "line表中不同名称的列
  temp-= '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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值