At new ...endat和At end of ...endat用法

At new…erdat and at end of …endat usage

1.Introduction

In the passage I will introduce how to use at new …endat and at end of …endat.
First ,they are used in the loop. At new …endat means that we only fetch the first row if the many rows are same. At end of …endat means that we only fetch the last row if the many rows are same. I will demostrate it in following demo.

2.Demo

2.1 At new … endat usage
TYPES: begin of ty_tab ,
num(3) type i,
str(3) type c,
end of ty_tab.
data: gw_tab TYPE ty_tab ,
gt_tab TYPE TABLE OF ty_tab WITH HEADER LINE.
data: gt_out TYPE TABLE OF ty_tab,
gw_out TYPE ty_tab.
gw_tab-num = 100.
gw_tab-str = 'AAA'.
append gw_tab to gt_tab.
gw_tab-num = 100.
gw_tab-str = 'BBB'.
append gw_tab to gt_tab.
gw_tab-num = 200.
gw_tab-str = 'AAA'.
append gw_tab to gt_tab.
gw_tab-num = 200.
gw_tab-str = 'BBB'.
append gw_tab to gt_tab.
gw_tab-num = 200.
gw_tab-str = 'CCC'.
append gw_tab to gt_tab.
CLEAR gw_tab.
sort gt_tab by num.
loop at gt_tab .
MOVE gt_tab to gw_tab.
at NEW  num.
gw_out-num = gw_tab-num.
gw_out-str = gw_tab-str.
APPEND gw_out to gt_out.
endat.
CLEAR gw_tab.
endloop.
LOOP AT gt_out into gw_out.
write:/ gw_out-num,gw_out-str.
ENDLOOP.

There are same data in the table.
在这里插入图片描述
The reuslt
在这里插入图片描述

2.2 at end of …endat usage
TYPES: begin of ty_tab ,
num(3) type i,
str(3) type c,
end of ty_tab.
data: gw_tab TYPE ty_tab ,
gt_tab TYPE TABLE OF ty_tab WITH HEADER LINE.
data: gt_out TYPE TABLE OF ty_tab,
gw_out TYPE ty_tab.
gw_tab-num = 100.
gw_tab-str = 'AAA'.
append gw_tab to gt_tab.
gw_tab-num = 100.
gw_tab-str = 'BBB'.
append gw_tab to gt_tab.
gw_tab-num = 200.
gw_tab-str = 'AAA'.
append gw_tab to gt_tab.
gw_tab-num = 200.
gw_tab-str = 'BBB'.
append gw_tab to gt_tab.
gw_tab-num = 200.
gw_tab-str = 'CCC'.
append gw_tab to gt_tab.
CLEAR gw_tab.
sort gt_tab by num.
loop at gt_tab .
MOVE gt_tab to gw_tab.
at END OF  num.
gw_out-num = gw_tab-num.
gw_out-str = gw_tab-str.
APPEND gw_out to gt_out.
endat.
CLEAR gw_tab.
endloop.
LOOP AT gt_out into gw_out.
write:/ gw_out-num,gw_out-str.
ENDLOOP.

There are same data in the table.
在这里插入图片描述
The result
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值