Tuesday, April 19, 2011

Getting down with ABAP memory analysis and management

Mostly, ABAP programmers doesn't care too much on the memory being consumed by the application or reports they are creating during runtime. Though, yes sometimes, memory consumption is not the main issue when comes to abap programming. But, for me, having an efficient memory allocation and management of your application is one way of showing how keen you are and not only that, it shows also how much you care to the overall performance of your SAP system where your apps resides. It starts from 1 to reach 1000 and so on. Meaning, if you don't know how to manage or to free-up even 1bit of your memory garbage, it will lead to be a problem/disaster later on. So why wait for your apps/system to crush when you can manage it right now? In this topic, I will show you the different tools available from SAP that could help us in managing memory issues and if how can we minimize and clean up some of those.


First, let us look at what really happened when we run our application inside SAP.  Once a certain transaction has been triggered to run (inputting the tcode for example), it will automatically consume a different memory allocation from variable declarations, calling db tables, creating an object and so on. These memory allocations will be retained and compounded ( pressing f8) as long as the transaction is currently active or has not been exited/terminated yet. I.e if you are running a report repeatedly by returning back to the selection screen and run it again and so on without terminating, then this will increase the memory being consumed in allocated addresses like heap, paging etc. Doing such, will result to a memory overflow until your current transaction will be forcefully terminated by the system. Of course, addressing this issue can be done by a proper, careful, and efficient program design.

Memory related problems i.e leaks, can be identified using STAD and SM04/SM50 tcodes of SAP.

STAD ideally used to detect resource consumption after running a transaction or has finished processing. While, SM04/SM50 is ideal for monitoring online, real-time or running transactions.

Using the ABAP debugger is also helpful in looking for memory consumptions of ABAP.

Initializing Internal tables to a specific number of records, if you're sure, and or initializing it to zero or using the new itab declarations i.e TYPE STANDARD TABLE are advisable. These will help significantly in addressing memory leaks. Other best practice approach is to use FREE/REFRESH and CLEAR statement to your variables or itabs. Remember that using DELETE doesn't decrease or eliminate memory allocations but rather only delete the records or data of your itab. Thus if a certain itab will not be used anymore, it is advisable to refresh the content to minimize memory leaks or to avoid it completely.

No comments:

Post a Comment