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