More on ABAP/4 optimization
There are a number of strategies you can use to help improve the performance of ABAP/4 programs. This tip is the second part of a list of such strategies excerpted from Matt Wong's SAP Basis site.
- Whenever possible, design the program to access a relatively constant number of records (for instance, if you only access the transactions for one month, then there probably will be a reasonable range, like 1200-1800, for the number of transactions inputted within that month). Then, use a SELECT A B C INTO TABLE ITAB statement.
- Get a good idea of how many records you will be accessing. Log into your productive system, and use SE80 -> Dictionary Objects (press Edit), enter the table name you want to see, and press Display. Go To Utilities -> Table Contents to query the table contents and see the number of records. This is extremely useful in optimizing a program's memory allocation.
- Try to make the user interface such that the program gradually unfolds more information to the user, rather than giving a huge list of information all at once to the user.
- Declare your internal tables using OCCURS NUM_RECS, where NUM_RECS is the number of records you expect to be accessing. If the number of records exceeds NUM_RECS, the data will be kept in swap space (not memory).
- Use SELECT A B C INTO TABLE ITAB whenever possible. This will read all of the records into the itab in one operation, rather than repeated operations that result from a SELECT A B C INTO ITAB... ENDSELECT statement. Make sure that ITAB is declared with OCCURS NUM_RECS, where NUM_RECS is the number of records you expect to access.
- If the number of records you are reading is constantly growing, you may be able to break it into chunks of relatively constant size. For instance, if you have to read all records from 1991 to present, you can break it into quarters, and read all records one quarter at a time. This will reduce I/O operations. Test extensively with GET RUN TIME when using this method.
- Know how to use the 'collect' command. It can be very efficient.
- Use the SELECT SINGLE command whenever possible.
- Many tables contain totals fields (such as monthly expense totals). Use these avoid wasting resources by calculating a total that has already been calculated and stored.
Did you like this tip? If so (or if not) let us know. Send an email to sound off. Or go to our tips page and rate this and other tips, or send us one of your own.
Title: Writing SAP ABAP/4 Programs
Author: Ted Hoffman
Cover Type: Soft Cover
Published: April 1998
SAP is the largest pure applications software vendor in the world, but gaining high-level SAP expertise can be difficult. Now a SAP insider offers the first guide to writing specific types of reports and programs within SAP using real-world ABAP Release 4 examples. This book and CD-ROM tame the massive nature of the information and integration inherent to SAP as well as the complex ABAP programing language. Writing SAP ABAP/4 Programs will be invaluable to IS professionals who must remain the SAP system once the initial consultant has more.
To buy the book, or read more, go to our TechTarget.com Learning Zone.