Trik Tunning ABAP
Tunning sangat diperlukan ketika kita akan membuat sebuah report custom di SAP dikarenakan data akan terus semakin besar dan akan mempengaruhi kecepatan proses pengambilan data yang akan di tampilkan di report, oleh karena itu di perlukan tunning performance untuk membantu proses pengambilan data agar lebih cepat. Berikut contoh yang menggunakan tunning dan tidak, akan terlihat perbedaan waktu yang dibutuhkan untuk memproses data . Ada beberapa cara untuk melakukan tunning program di ABAP, namun disini saya hanya menulis tunning dengan type internal table saja.
TYPES:
BEGIN OF ty_vbpa,
vbeln TYPE vbpa-vbeln,
posnr TYPE vbpa-posnr,
parvw TYPE vbpa-parvw,
kunnr TYPE vbpa-kunnr,
END OF ty_vbpa.
DATA: t_std TYPE STANDARD TABLE OF ty_vbpa.
DATA: t_sorted TYPE SORTED TABLE OF ty_vbpa WITH UNIQUE KEY vbeln.
DATA: t_hashed TYPE HASHED TABLE OF ty_vbpa WITH UNIQUE KEY vbeln.
TYPES:
BEGIN OF ty_vbak,
vbeln TYPE vbak-vbeln,
found TYPE flag,
END OF ty_vbak.
DATA: t_vbak TYPE STANDARD TABLE OF ty_vbak.
DATA: lt_vbak TYPE STANDARD TABLE OF ty_vbak.
FIELD-SYMBOLS: <lfs_vbak> LIKE LINE OF t_vbak.
DATA: lv_flag TYPE flag,
lv_sta_time TYPE timestampl,
lv_end_time TYPE timestampl,
lv_diff TYPE p DECIMALS 5.
DATA: lv_num_main TYPE i,
lv_num_sub TYPE i.
START-OF-SELECTION.
lv_num_main = 5000000. " Change for different number of records
lv_num_sub = lv_num_main / 2.
*
SELECT vbeln
FROM vbak
INTO TABLE t_vbak
UP TO lv_num_main ROWS.
*
SELECT vbeln posnr parvw kunnr
INTO TABLE t_std
FROM vbpa
UP TO lv_num_sub ROWS
FOR ALL ENTRIES IN t_vbak
WHERE vbeln = t_vbak-vbeln
AND parvw = 'AG'.
* Copying into the Sorted and Hashed table
t_sorted = t_std.
t_hashed = t_std.
t_hmtbl[] = t_std.
*----
* READ on Standard Table
GET TIME STAMP FIELD lv_sta_time.
LOOP AT t_vbak ASSIGNING <lfs_vbak>.
READ TABLE t_std TRANSPORTING NO FIELDS
WITH KEY vbeln = <lfs_vbak>-vbeln.
IF sy-subrc EQ 0.
"..
ENDIF.
ENDLOOP.
GET TIME STAMP FIELD lv_end_time.
lv_diff = lv_end_time - lv_sta_time.
WRITE: /(30) 'Standard Table', lv_diff.
*
*----
* READ on Standard table with Binary Search
GET TIME STAMP FIELD lv_sta_time.
SORT t_std BY vbeln.
LOOP AT t_vbak ASSIGNING <lfs_vbak>.
READ TABLE t_std TRANSPORTING NO FIELDS
WITH KEY vbeln = <lfs_vbak>-vbeln
BINARY SEARCH.
IF sy-subrc EQ 0.
"..
ENDIF.
ENDLOOP.
GET TIME STAMP FIELD lv_end_time.
lv_diff = lv_end_time - lv_sta_time.
WRITE: /(30) 'Standard Table - Binary', lv_diff.
*
*----
* READ on Sorted Table
GET TIME STAMP FIELD lv_sta_time.
LOOP AT t_vbak ASSIGNING <lfs_vbak>.
READ TABLE t_sorted TRANSPORTING NO FIELDS
WITH KEY vbeln = <lfs_vbak>-vbeln.
IF sy-subrc EQ 0.
"..
ENDIF.
ENDLOOP.
GET TIME STAMP FIELD lv_end_time.
lv_diff = lv_end_time - lv_sta_time.
WRITE: /(30) 'Sorted Table', lv_diff.
*
*----
* READ on HASHED table
GET TIME STAMP FIELD lv_sta_time.
LOOP AT t_vbak ASSIGNING <lfs_vbak>.
READ TABLE t_hashed TRANSPORTING NO FIELDS
WITH TABLE KEY vbeln = <lfs_vbak>-vbeln.
IF sy-subrc EQ 0.
"..
ENDIF.
ENDLOOP.
GET TIME STAMP FIELD lv_end_time.
lv_diff = lv_end_time - lv_sta_time.
WRITE: /(30) 'Hashed Table', lv_diff.
Berikut perbandingan waktu yang di butuhkan untuk memproses data :
sumber : http://zevolving.com/2013/02/abap-internal-table-performance-for-standard-sorted-and-hashed-table/
Comments
Post a Comment