二维码

[性能] Field-symbols 和 Work area处理内表时性能分析

Twilight发表于 2016-10-11 10:24Twilight 最后回复于 2016-10-11 10:24 [复制链接] 2761 0

在ABAP Programming时,经常会遇到处理内表(如 appending & modifying)的记录,我们可以使用field-symbols,来减少处理的时间,提高程序性能。

因为field-symbols相当于C语言中的de-referenced指针,直接取内存中的值,不需要在开辟(work area)内存空间,move到此空间是需要花费时间的。

field-symbols performance测试案例:
  1. DATA: i_bseg TYPE STANDARD TABLE OF bseg,
  2.       wa_bseg LIKE LINE OF i_bseg.
  3. *
  4. DATA: lv_flag TYPE flag,
  5.       lv_sta_time TYPE timestampl,
  6.       lv_end_time TYPE timestampl,
  7.       lv_diff_w   TYPE p DECIMALS 5,
  8.       lv_diff_f   LIKE lv_diff_w,
  9.       lv_save     LIKE lv_diff_w.
  10. *
  11. FIELD-SYMBOLS: <fs_bseg> LIKE LINE OF i_bseg.
  12. *
  13. * data selection = 10,000 records
  14. SELECT * FROM bseg INTO TABLE i_bseg UP TO 10000 ROWS.
  15. *
  16. * Begin - Processing with Work area
  17. GET TIME STAMP FIELD lv_sta_time.
  18. LOOP AT i_bseg INTO wa_bseg.
  19.   IF lv_flag = 'X'.
  20.     wa_bseg-sgtxt = 'TEST'.
  21.     MODIFY i_bseg FROM wa_bseg.
  22.   ENDIF.
  23.   CLEAR wa_bseg.
  24.   IF lv_flag IS INITIAL.
  25.     lv_flag = 'X'.
  26.   ENDIF.
  27. ENDLOOP.
  28. GET TIME STAMP FIELD lv_end_time.
  29. lv_diff_w = lv_end_time - lv_sta_time.
  30. WRITE: /(15) 'Work area', lv_diff_w.
  31. * End   - Processing with Work Area
  32. *
  33. CLEAR: lv_flag,
  34.        lv_sta_time,
  35.        lv_end_time.
  36. * Begin - Processing with Field-Symbols
  37. GET TIME STAMP FIELD lv_sta_time.
  38. LOOP AT i_bseg ASSIGNING <fs_bseg>.
  39.   IF lv_flag = 'X'.
  40.     <fs_bseg>-sgtxt = 'TEST'.
  41.   ENDIF.
  42.   IF lv_flag IS INITIAL.
  43.     lv_flag = 'X'.
  44.   ENDIF.
  45. ENDLOOP.
  46. GET TIME STAMP FIELD lv_end_time.
  47. lv_diff_f = lv_end_time - lv_sta_time.
  48. WRITE: /(15) 'Field-Symbol', lv_diff_f.
  49. * End   - Processing with Work Area
  50. *
  51. * Net time saving
  52. lv_save = lv_diff_w - lv_diff_f.
  53. WRITE: /(15) 'Total Save', lv_save.
  54. WRITE: / 'Done'.
复制代码

测试结果:
field-symbols.jpg
由此可见field-symbols只花费原先Work area的1/5的时间
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表