Login Form

Best viewed in IE 7.0

ADVERTISEMENTS
ADVERTISEMENT

ABAP Performance "Do's and Don'ts"

DO

DON’T

Standard and Hashed[1] internal table types.

Sorted internal table type.

READ on sorted standard table using ‘BINARY SEARCH’.[2]

 

Addition TRANSPORTING on READ and MODIFY

 

Parallel Cursor

* TAB2 is sorted by K in ascending order
LOOP AT TAB1.
 CLEAR V_TABIX.
 READ TABLE TAB2 WITH KEY K = TAB1-K BINARY SEARCH.
 CHECK SY-SUBRC = 0.
 V_TABIX = SY-TABIX.
 LOOP AT TAB2 FROM V_TABIX.
  IF TAB2-K TAB1-K.
    EXIT.
  ENDIF.
 ENDLOOP.
ENDLOOP.

Nested Loop

LOOP AT TAB1.
  LOOP AT TAB2 WHERE K = TAB1-K.
  ENDLOOP.
ENDLOOP.

Use index operations like
  LOOP AT …FROM …TO and
  MODIFY …FROM …TO

WHERE clause on internal table operations e.g.
LOOP, MODIFY, etc.

Mark for deletion using MODIFY in a LOOP.
Perform mass delete using DELETE WHERE after the loop.

DELETE WHERE in a LOOP.

 

MOVE-CORRESPONDING

Other:

Table pointers for MOVE, COMPARE and mass internal table operations (itab1[] = itab2[])

Addition ASSIGNING for internal table modification and processing.

Typed field symbols.[3]

Pass internal tables into subroutines by reference[4]

FREE internal tables

Other:

SORT inside a LOOP[5]

DELETE or SORT on a hashed table

INTERNAL TABLES

MODIFY TAB FROM WA TRANSPORTING DATE

  WHERE DATE IS INITIAL.

With the MODIFY variant MODIFY itab ... TRANSPORTING f1 f2 ... WHERE condition, the task of updating a set of lines of an internal table can be accelerated considerably.

APPEND LINES OF TAB_SRC TO TAB_DEST.

 

 

 

DELETE TAB_DEST WHERE K = KVAL.

 

 

Check for empty table:

IF TAB1[ ] is initial.

* Empty internal table

ENDIF.

 

Recommendation

·          Type STANDARD should be used as default type

·          Type HASHED if the internal table contains a large number of records and your program requires a large number of primary (unique) key accesses

·          Avoid using SORTED tables since the performance gain compared to a standard table is minimal, and it includes the risk that the sort sequence is corrupted by using INSERT, APPEND or MODIFY with Index option

 

·          Key Search: READ TABLE TAB WITH KEY = .

·          Key/Binary Search: READ TABLE TAB WITH KEY = BINARY SEARCH.

·          Search with Table Index: READ TABLE TAB INDEX .

The READ using the Table Index search is the fastest and the Key Search is the slowest.

 

LOOP AT TAB.

  MODIFY TAB FROM WA TRANSPORTING DATE.

ENDLOOP.

 

 

LOOP AT TAB_SRC.

  APPEND TAB_SRC TO TAB_DEST.

ENDLOOP.

 

LOOP AT TAB_DEST WHERE K = KVAL.

  DELETE TAB_DEST.

ENDLOOP.

Check for empty table:

DESCRIBE TABLE TAB1 LINES L1.

IF L1 = 0.

*Empty internal table

ENDIF.



[1] Use a hashed table whenever many single record accesses are required for an internal table via a fully specified key

[2] READ without BINARY SEARCH on a standard table forces sequential read.

[3] The runtime of a typed ASSIGN statement is around 40% less than that required for an equivalent untyped ASSIGN statement.

[4] Passing by value results in data and memory duplication.

[5] Sort is an expensive ABAP statement. It should be use outside of a loop.

ADVERTISEMENT
Free software downloads