Copyright 2024 - BV TallVision IT

Abap memory and "memory span" can maybe be best understood by understanding namespacing effects. A technical object has a unique name, and it's uniqueness is checked in it's namespace. A transaction code and a report name can have the very same name, because they are not in the same namespace. The variables in your report are also in a "namespace".

When a global variabele (variabele that is defined in report's main data definition) is declared, an attempt to declare it again will result in an error message "SUCH_AND_SUCH" Has already been declared. So what happens if you declare a local variabele with the same name as the global one ? Variables in the routine do not share namespace with the calling program, so declaring these variables is not an issue:

data: ga_var type char20 value 'Cookies'.

write: / ga_var.
perform kaas.
write: / 'more', ga_var.

form kaas.
  data: ga_var type char20 value 'Cream'.
  write: / ga_var.
endform.

The outcome of the above:

Cookies
Cream
more Cookies

Now if the local declaration in routine KAAS was removed, the outcome would be:

Cookies
Cookies
more Cookies

So in effect: globally declared variables are available from anywhere in the program, except in the routines they are re-declared in. Global/local naming convention should avoid this in practice.