共计 3282 个字符,预计需要花费 9 分钟才能阅读完成。
在 SAP 开发我的项目,这两个概念开发人员根本都晓得。然而没有去比照其性能区别。
首先,咱们遍及一下原理。
Workarea: 相当于在内存堆栈外面开拓了一块内存。
Field Symbols: 相当于存了内存的地址。所以实际上是不占用内存的。相当于 C 语言的曾经被解除援用的指针。
所以咱们进行一项性能测试:
1. 比照单纯 Loop 的性能,不进行数据批改。
REPORT zloop_performance_test.
DATA : v_start_time TYPE timestampl,
v_end_time TYPE timestampl,
v_diff_w TYPE p DECIMALS 5.
TYPES : BEGIN OF ty_vbrp,
vbeln TYPE vbrp-vbeln,
END OF ty_vbrp.
DATA : lt_vbrp TYPE STANDARD TABLE OF ty_vbrp,
ls_vbrp TYPE ty_vbrp.
FIELD-SYMBOLS : <fs_vbrp> TYPE ty_vbrp.
PARAMETERS p_count TYPE n LENGTH 6.
* Start of selection
START-OF-SELECTION.
* Get billing item data
SELECT vbeln
FROM vbap
INTO TABLE lt_vbrp
UP TO p_count ROWS.
END-OF-SELECTION.
* 1 . Loop with work area
GET TIME STAMP FIELD v_start_time.
LOOP AT lt_vbrp INTO ls_vbrp.
ENDLOOP.
GET TIME STAMP FIELD v_end_time.
v_diff_w = v_end_time - v_start_time.
WRITE :/(30) 'Loop with Work area', v_diff_w.
CLEAR : v_start_time, v_end_time, v_end_time.
* 2 . Loop with work area inline declaration
GET TIME STAMP FIELD v_start_time.
LOOP AT lt_vbrp INTO DATA(ls_vbrp_inline).
ENDLOOP.
GET TIME STAMP FIELD v_end_time.
v_diff_w = v_end_time - v_start_time.
WRITE:/(30) 'Loop with Inline Work area', v_diff_w.
CLEAR : v_start_time, v_end_time, v_end_time.
* 3 . Loop with Field symbol
GET TIME STAMP FIELD v_start_time.
LOOP AT lt_vbrp ASSIGNING <fs_vbrp>.
ENDLOOP.
GET TIME STAMP FIELD v_end_time.
v_diff_w = v_end_time - v_start_time.
WRITE:/(30) 'Loop with Field Symbol', v_diff_w.
CLEAR : v_start_time, v_end_time, v_end_time.
* 4 . Loop with Field symbol inline declaration
GET TIME STAMP FIELD v_start_time.
LOOP AT lt_vbrp ASSIGNING FIELD-SYMBOL(<fs_vbrp_inline>).
ENDLOOP.
GET TIME STAMP FIELD v_end_time.
v_diff_w = v_end_time - v_start_time.
WRITE:/(30) 'Loop with Inline Field Symbol', v_diff_w.
CLEAR : v_start_time, v_end_time, v_end_time.
2. 比照 loop,并将数据批改如上面的代码:
REPORT zloop_performance_test.
DATA : v_start_time TYPE timestampl,
v_end_time TYPE timestampl,
v_diff_w TYPE p DECIMALS 5.
TYPES : BEGIN OF ty_vbrp,
vbeln TYPE vbrp-vbeln,
END OF ty_vbrp.
DATA : lt_vbrp TYPE STANDARD TABLE OF ty_vbrp,
ls_vbrp TYPE ty_vbrp.
FIELD-SYMBOLS : <fs_vbrp> TYPE ty_vbrp.
PARAMETERS p_count TYPE n LENGTH 6.
* Start of selection
START-OF-SELECTION.
* Get billing item data
SELECT vbeln
FROM vbrp
INTO TABLE lt_vbrp
UP TO p_count ROWS.
END-OF-SELECTION.
* 1 . Loop with work area
GET TIME STAMP FIELD v_start_time.
LOOP AT lt_vbrp INTO ls_vbrp.
ls_vbrp-vbeln = 1.
MODIFY lt_vbrp FROM ls_vbrp.
ENDLOOP.
GET TIME STAMP FIELD v_end_time.
v_diff_w = v_end_time - v_start_time.
WRITE :/(30) 'Loop with Work area', v_diff_w.
CLEAR : v_start_time, v_end_time, v_end_time.
* 2 . Loop with work area inline declaration
GET TIME STAMP FIELD v_start_time.
LOOP AT lt_vbrp INTO DATA(ls_vbrp_inline).
ls_vbrp_inline-vbeln = 1.
MODIFY lt_vbrp FROM ls_vbrp_inline.
ENDLOOP.
GET TIME STAMP FIELD v_end_time.
v_diff_w = v_end_time - v_start_time.
WRITE:/(30) 'Loop with Inline Work area', v_diff_w.
CLEAR : v_start_time, v_end_time, v_end_time.
* 3 . Loop with Field symbol
GET TIME STAMP FIELD v_start_time.
LOOP AT lt_vbrp ASSIGNING <fs_vbrp>.
<fs_vbrp>-vbeln = 1.
ENDLOOP.
GET TIME STAMP FIELD v_end_time.
v_diff_w = v_end_time - v_start_time.
WRITE:/(30) 'Loop with Field Symbol', v_diff_w.
CLEAR : v_start_time, v_end_time, v_end_time.
* 4 . Loop with Field symbol inline declaration
GET TIME STAMP FIELD v_start_time.
LOOP AT lt_vbrp ASSIGNING FIELD-SYMBOL(<fs_vbrp_inline>).
<fs_vbrp_inline>-vbeln = 1.
ENDLOOP.
GET TIME STAMP FIELD v_end_time.
v_diff_w = v_end_time - v_start_time.
WRITE:/(30) 'Loop with Inline Field Symbol', v_diff_w.
CLEAR : v_start_time, v_end_time, v_end_time.
论断:
在两个测试后果中能够看出,loop 到工作区实际上有一个内表到工作区的赋值过程。从工作区 modify 到内表也有一个赋值的过程。而在 Field Symbol 中则是间接批改了内表值。所以速度会比拟快很多。
所以在能用 Field Symbol 的中央尽量应用 Field Symbol。
正文完