puzzled for a long time at end of the sort of figure out ... Haha
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 to Gw_out.
write:/Gw_out-num,gw_out-str.
Endloop.
Using the at end of the statement, the main is to crawl the repeating field as NUM 100 of the last record of the BBB.
In the structure defined in this example, the field num is before the field str, so that when the at END of statement is used, str in the inner table becomes * * *.
The data in the table Gt_tab before the loop loop is:
AAA
BBB
AAA
BBB
CCC
The first cycle, the data in the table Gt_tab is AAA after executing the at END of statement, the data in table Gt_tab is AAA
The second cycle, the data in the table Gt_tab is in the execution of the at end of the statement, the data in table Gt_tab is 100 * * *, after the execution of the at end of the statement, the data in the table Gt_tab is BBB
Third cycle, the data in the table Gt_tab is triple AAA after executing the at END of statement, the data in table Gt_tab is triple AAA
Fourth cycle, the data in the table Gt_tab is BBB after executing the at END of statement, the data in table Gt_tab is
The fifth cycle, the data in the table Gt_tab is CCC in the execution of the at end of the statement, the data in table Gt_tab is 200 * * *, after the execution of the at end of the statement, the data in the table Gt_tab is CCC
In order to get the last piece of data we want, we need to transfer the data of the inner table to another workspace gw_tab before executing the at END of statement, otherwise the desired data in STR is * * *.
The last data obtained are:
BBB
CCC
Also, as with the use of the at new statement, this instance will be at end of NUM, after changing to at New NUM, the final result is:
AAA
AAA
Abap-at END of Use