1 REPORT y4_b4_test15.
2
3 DATA: lv_time_s TYPE timestampl, "loop前的时间点
4 lv_time_e TYPE timestampl, "loop后的时间点
5 lv_text TYPE timestampl.
6 DATA: lv_tabix TYPE i.
7
8 SELECT * FROM mara INTO TABLE @DATA(it_mara) UP TO 10000 ROWS.
9
10 CHECK it_mara IS NOT INITIAL.
11
12 SELECT * FROM marc INTO TABLE @DATA(it_marc) FOR ALL ENTRIES IN @it_mara WHERE matnr = @it_mara-matnr.
13
14 GET TIME STAMP FIELD lv_time_s. "获得loop前的时间点
15
16 DATA ls_data LIKE marc.
17 DATA lt_data LIKE TABLE OF marc.
18 LOOP AT it_mara INTO DATA(is_mara).
19 LOOP AT it_marc INTO DATA(is_marc) WHERE matnr = is_mara-matnr.
20 MOVE-CORRESPONDING is_marc TO ls_data.
21 APPEND ls_data TO lt_data.
22 CLEAR ls_data.
23 ENDLOOP.
24 ENDLOOP.
25 GET TIME STAMP FIELD lv_time_e.
26
27 lv_text = lv_time_e - lv_time_s.
28
29 DESCRIBE TABLE lt_data LINES DATA(lv_num_1).
30 WRITE: /(14) '普通循环时间:', lv_text, '条目数量:' ,lv_num_1.
31
32 CLEAR: lv_text, lv_time_e,lv_time_s,lt_data.
33
34 GET TIME STAMP FIELD lv_time_s.
35
36 **排序
37 SORT: it_mara BY matnr,
38 it_marc BY matnr.
39 LOOP AT it_mara INTO is_mara.
40 **取TABIX
41 READ TABLE it_marc TRANSPORTING NO FIELDS WITH KEY matnr = is_mara-matnr BINARY SEARCH.
42 IF sy-subrc = 0.
43 lv_tabix = sy-tabix.
44
45 LOOP AT it_marc FROM lv_tabix INTO is_marc.
46 IF is_mara-matnr <> is_marc-matnr.
47 EXIT.
48 ENDIF.
49
50 MOVE-CORRESPONDING is_marc TO ls_data.
51 APPEND ls_data TO lt_data.
52 CLEAR ls_data.
53 ENDLOOP.
54 ENDIF.
55 ENDLOOP.
56 GET TIME STAMP FIELD lv_time_e.
57
58 DESCRIBE TABLE lt_data LINES DATA(lv_num_2).
59 lv_text = lv_time_e - lv_time_s.
60
61 WRITE: /(14)'优化循环时间:', lv_text,'条目数量:' ,lv_num_2.