SAP ABAP program performance optimization

xiaoxiao2021-03-06  22

Performance Tuning Contributed by Henrik Frank

For all entries Nested selects Select using JOINS Use the selection criteria Use the aggregated functions Select with view Select with index support Select ... Into table Select with selection list Key access to multiple lines Copying internal tables Modifying a set of lines Deleting a sequence of lines Linear search vs. binary Comparison of internal tables Modify selected components Appending two internal tables Deleting a set of lines Tools available in SAP to pin-point a performance problem Optimizing the load of the database for all entries The for all entries creates a where clause, where all the entries in the driver table are combined with OR. If the number of entries in the driver table is larger than rsdb / max_blocking_factor, several similar SQL statements are executed to limit the length of the WHERE clause. The plus

Large Amount of Data Mixing Processing and Reading of Data Fast INTERNAL REPROCESSING OF Data Fast the minus

Difficult to Program / Understand Memory Could Be critical (Use Free Or Package Size) Some Steps That Might Make for All Entries More Efficient:

Removing duplicates from the driver table Sorting the driver table If possible, convert the data in the driver table to ranges so a BETWEEN statement is used instead of and OR statement: FOR ALL ENTRIES IN i_tab WHERE mykey> = i_tab-low and

mykey <= i_tab-high.

NESTED SELECTS The PLUS:

Small Amount of Data Mixing Processing and Reading of Data Easy to Code - and Understand The Minus:

Large Amount of Data When Mixed Processing Isn't Needed Performance Killer No. 1 SELECT Using Joins The Plus

Very large amount of data Similar to Nested selects - when the accesses are planned by the programmer In some cases the fastest Not so memory critical The minusVery difficult to program / understand Mixing processing and reading of data not possible Use the selection criteriaSELECT * FROM SBOOK.

Check: Sbook-carrid = 'lh' and

SBOOK-connid = '0400'.

Endselect.

SELECT * from FROM SBOOK

WHERE carrid = 'lh' and

CONNID = '0400'.

Endselect.

Use the aggregated functionsc4a = '000'.

SELECT * from T100

Where sprsl = 'd' and

ArbGB = '00'.

CHECK: T100-MSGNR> C4A.

C4a = t100-msgnr.

Endselect.

SELECT MAX (MSGNR) from T100 INTO C4A

Where sprsl = 'd' and

ArbGB = '00'.

Select with viewselect * from DD01L

Where domname like 'char%'

And as4local = 'a'.

SELECT SINGLE * FROM DD01T

Where domname = DD01L-Domname

And as4local = 'a'

And as4vers = dd01l-as4vers

And ddlanguage = SY-LANGU.

Endselect.

SELECT * FROM DD01V

Where domname like 'char%'

And ddlanguage = SY-LANGU.

Endselect.

SELECT WITH INDEX SupportSelect * from T100

WHERE ARBGB = '00'

And msgnr = '999'.

Endselect.

Select * from T002.

SELECT * from T100

Where sprsl = t002-spras

And arbgb = '00'

And msgnr = '999'.

Endselect.

Endselect.

SELECT ... INTO TABLEREFRESH X006.

SELECT * from T006 INTO X006.

Append X006.

Endselect

Select * from t006 INTO TABLE X006.

SELECT WITH SELECTION LISTSELECT * FROM DD01L

Where domname like 'char%'

And as4local = 'a'.

Endselect

SELECT DOMNAME FROM DD01L

INTO DD01L-DOMNAME

Where domname like 'char%'

And as4local = 'a'.

Endselect

Key Access To Multiple Linesloop At Tab.

Check tab-k = kVal.

"...

Endloop.

Loop at tab where k = kVal.

"...

Endloop.

Copying Internal TableSRefresh Tab_Dest.

Loop at tab_src INTO TAB_DEST.

Append tab_dest.

Endloop.

Tab_DEST [] = Tab_src [].

Modifying a set of linesloop at tab.

IF Tab-flag is initial.

TAB-FLAG = 'x'.

ENDIF.

Modify Tab.

Endloop.

TAB-FLAG = 'x'.

Modify Tab Transporting Flag

WHERE flag is initial.

DELETING a SEQUENCE OF LINESDO 101 TIMES.

Delete Tab_Dest INDEX 450.

Enddo.

DELETE TAB_DEST FROM 450 TO 550.

Linear Search vs. binaryRead Table Tab with key k = 'x'.

Read Table Tab with Key K = 'x' binary search.

Comparison of Internal TableSDescribe Table: Tab1 Lines L1,

Tab2 Lines L2.

IF L1 <> L2.

Tab_different = 'x'.

Else.

Tab_different = Space.

Loop

AT Tab1.

Read Table Tab2 INDEX SY-Tabix.

IF Tab1 <> Tab2.

Tab_different = 'x'. EXIT.

ENDIF.

Endloop.

ENDIF.

If Tab_DIFFERENT = Space.

"...

ENDIF.

IF Tab1 [] = Tab2 [].

"...

ENDIF.

Modify SELECTED Componentsloop At Tab.

Tab-Date = SY-DATUM.

Modify Tab.

Endloop.

WA-date = SY-DATUM.

Loop at tab.

Modify Tab Wa Transporting Date.

Endloop.

Appending TWO INTERNAL TABLOOP At Tab_src.

Append tab_src to tab_dest.

Endloop

Append lines of tab_src to tab_dest.

DELETING A SET OF LINESLOOP At Tab_Dest Where K = KVAL.

DELETE TAB_DEST.

Endloop

DELETE TAB_DEST WHERE K = kVal.

Tools Available In Sap To Pin-Point A Performance Problem · The runtime analysis (se30)

· SQL TRACE (ST05) · Tips and Tricks Tool

· The Performance Database

. Optimizing the load of the database Using table buffering Using buffered tables improves the performance considerably Note that in some cases a statement can not be used with a buffered table, so when using these statements the buffer will be bypassed These statements are.:

Select DISTINCT ORDER BY / GROUP BY / HAVING clause Any WHERE clause that contains a sub query or IS NULL expression JOIN s A SELECT ... FOR UPDATE If you wan t to explicitly bypass the buffer, use the BYPASS BUFFER addition to the SELECT clause . Use the ABAP SORT clause Instead of ORDER BY The ORDER BY clause is executed on the database server while the ABAP SORT statement is executed on the application server. The database server will usually be the bottleneck, so sometimes it is better to move the sort from the database server to the application server. If you are not sorting by the primary key (Eg using the ORDER bY PRIMARY key statement) but are sorting by another key, it could be better to use the ABAP SORT statement to sort the data in an internal table. Note however that for very large result sets it might not be a feasible solution and you would want to let the database server sort it. Avoid the SELECT DISTINCT Statement As with the ORDER BY clause it could be better To Avoid Using Select Distinct, IF Some of The Fields Are Not Part of An Index. INSTEAD USE ABAP SORT DELETE Adjacent Duplicates on An Innal Table, To Delete DuPlicate Rows.

转载请注明原文地址:https://www.9cbs.com/read-61106.html

New Post(0)