Few points that should be considered for performance optimization of your code:
1. Avoid using SELECT...ENDSELECT and use SELECT ... INTO TABLE
2. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved
3. Design your Query to Use as much index fields as possible from left to right in your WHERE statement
4. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot
5. Avoid using nested SELECT statement & SELECT within LOOPs.Instead, make use of different internal tables to fetch the data, and Use Nested LOOPS to read them.
6. Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
7. Avoid using SELECT * and Select only the required fields from the table
8. Avoid nested loops when working with large internal tables
9. Use assign instead of into in LOOPs for table types with large work areas
10. When in doubt call transaction SE30 and use the examples and check your code
11. Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search otherwise the table is read from top to bottom until a field matching the KEY is found.This is a general thumb rule but typically if you are sure that the data in internal table is less than 200 entries you need not do SORT and use BINARY SEARCH since this is an overhead in performance.
12. Use "CHECK" instead of IF/ENDIF whenever possible
13. Use "CASE" instead of IF/ENDIF whenever possible
14. Use "MOVE" with individual variable/field moves instead of "MOVE-CORRESPONDING".It creates more coding but is more effcient.
15. If the entire key can be qualified, code a SELECT SINGLE not a SELECT … ENDSELECT. If all the keys are not available, we should use SELECT UPTO 1 ROWS if we are interested only in the first record.
16. When accessing the database, careful consideration should be given to index access in order to make the program as efficient as possible. Tune the Query so that optimum indexing will happen.Use the Where clause appropriately to use the proper index both should be in same order use ST05 or SE30 to analyse which index is used.
17. Before using FOR ALL ENTRIES command, check that the :
(i) Corresponding Internal table is not empty. If the Internal table is empty, the statement will select ALL the entries in the Database
(ii) The Internal table is sorted by the File used in the Where Clause: This makes selection faster. (And delete adjacent duplicates for the key fields.)
18. Whenever it's possible avoid SELECT DISTINCT, instead select data into internal table, sort and use DELETE ADJACENT DUPLICATES.
19. Do not use OR when selecting data from DB table using an index because the optimizer generally stops if the WHERE condition contains an OR expression.
e.g.
Instead of
SELECT * FROM spfli WHERE carrid = ‘LH’