Can field definitions affect performance?
Friday, September 29, 2006
I’ve been always curious if the field definitions (DATA) could affect the performance, especially in the subroutines. In some languages the field definition actually compiles into 2 operations: definition itself and field initialization. It is obvious that in this case the less field definition the better, but I wasn’t completely sure about ABAP.
Today I had to make a change in the program where about 20 fields were defined inside a routine, which was called in a loop, so I finally decided to find out whether it would make any difference if I moved the field definitions outside of the loop.
For a clean test, I wrote a simple program:
DO 100 TIMES.
PERFORM routine.
ENDDO.
FORM routine.
DATA: w_matnr TYPE matnr,
w_posnr TYPE posnr.
WRITE: w_matnr.
ENDFORM.
Then I changed it like this:
DATA: w_matnr TYPE matnr,
w_posnr TYPE posnr.
DO 100 TIMES.
PERFORM routine.
ENDDO.
FORM routine.
WRITE: w_matnr.
ENDFORM.
I ran Runtime Analysis on both several times to get more accurate results (that really drives me crazy that you get different results almost every time) and here is the average “before” picture
and “after” picture.
Well, it’s not huge but now I know that it does make a difference. What’s interesting though – the runtime did not increase much when I changed the DO cycle to 1000 times. Hmm... If anyone can explain this, please let me know.
posted by Your Friendly ABAPer @ 22:14, Direct link to this post