The blog presents SAP Best Practices (Tips & Tricks) for SAP ABAP development. Using SAP ABAP performance techniques, we can save server resource, reduce network traffic and improve end-user interaction experience; all these lead to increase in productivity of user.
Below are the performance techniques needs to be followed:
- Database Techniques:
- Secondary index:There are two types of indexes: Primary index and secondary index. Primary index is automatically created using primary keys defined.
Secondary index could be created as per the user requirement. With a secondary index, we can reduce the record scaning time and improves performance.
- Where clause in select query:Always specify your conditions in where clause rather than first selecting all record then using the check syntax.
The database system can then use an index and the network load is considerably less.
- Select data into internal table:Selecting data into internal table is faster than select — appending the table.
SELECT in LOOP will increase database hit and lead to high network traffic. SELECT INTO TABLE is retrieving the max possible rows per fetch and puts it into the internal table.
- Select single and select…. endselect:If you want one database record then use select single instead of select… end select.
When you use SELECT * … END SELECT statement to access your table, the system will access the database for value each time you loop. This will cause the traffic to increase and memory usage. If you use SELECT SINGLE and using KEYS in where condition, this will limit the search and keep the memory usage low plus reducing the execution time at database side.
- Use for all entries in <itab>:It’s increase the performance tremendously. Duplicates are automatically removed from the resulting data set. This statement is very useful to help us processing data using separate internal tables, although some of the process can be achieved using simple join statement, the FOR ALL ENTRIES statement can give you more processing Independency working with many internal tables. We can use this method to avoid “select” statement within loop.IMPORTANT – Before using FOR ALL ENTRIES check table is not initial otherwise query will return all records from table.
- ABAP Processing Techniques:
- Read table using binary Search:The binary search algorithm helps faster search of a value in an internal table. It is advisable to sort the internal table before doing a binary search. Binary search repeatedly divides the search interval in half.
If the value to be searched is less than the item in the middle of the interval, so it will consider 1st half part otherwise 2nd half part.
- Use of move statements:If two work area have same structure then, use move statement instead of move-corresponding. MOVE statement is used for similar structures, means sequence of field is same in both work area and MOVE-CORRESPONDING is used for non-similar structures.
- Copying internal tables:To copy entire contents of one table into another, use tab1  = tab2  instead of append tab2 in Loop…Endloop.
- Comparing internal tables:Internal tables can be compared in a much faster way by if tab1  = tab2 .
If you want to address the body of the table in a comparison, you must place two brackets ([ ]) after the table name.
- Sorting internal tables:Before every Read statement it is better to have sort internal table on key (with Key) fields.
- Number of records in an internal table:TO find out number of records are in an internal table use DESCRIBE statement.
This command to check whether an internal table contains data. The system field SY-TFILL gets affected after select … into… statement.
- Deleting a set of lines from internal Table:Use delete where to delete a set of lines. You can specify any logical expression log_exp after WHERE, all rows for which the logical expression is true are deleted.
- Unused variables: Delete unused variables form program.
Use program –> check –> extended program to check for the variables, which are not used. – Unnecessarily memory allocation at runtime.
In case you need assistance SAP ABAP performance techniquesand best practice, please contact us. Please send us your questions, comments or assistance request, and our team would be glad to assist you.
Please send us your questions, comments or assistance, and our team would be glad to assist you.
By Abhishek Khandelwal (on behalf of SAP Consulting Team)
SAP :: Streamlined
We offer variety of services including SAP ECC ,SAP HR,SAP BW,SAP CRM, SAP SCM,SAP BPM, Business Objects, SAP ABAP Development, SAP BASIS and SAP NetWeaver consulting. We have expertise in providing implementation,development, SAP Migration and SAP support services to SAP customers across diverse industries at a global level.
Have a question on SAP? Write to our SAP Architect.
(We promise a no-obligation consulting reply)