Visibility of ABAP Data Objects
Visibility of ABAP Data Objects
The following rules apply for data objects that are defined using the DATA statement:
If the DATA statement appears between FORM and ENDFORM, it defines a local
data object of a subroutine.
If the DATA statement appears between FUNCTION and ENDFUNCTION, it
defines a local data object of a function module.
In all other positions, the DATA statement defines a global data object, which is
visible in the entire program.
If a global data object and a local data object have the same name, only the local data
object is visible within the modularization unit. In technical terms, it ignores the
identically named global data object.
Caution: Data objects in modules and event blocks are always global. If the DATA statement
appears between MODULE and ENDMODULE, the object you define is still a global data
object that is visible in the entire program. Likewise, data objects that you declare in an
ABAP event block are visible globally.
To avoid misunderstandings, SAP recommends that you declare such data at the start of the
program, and avoid declaring DATA statements completely in modules and event blocks.
The TABLES statement always creates data objects that are visible throughout the program.
Data objects that you create using the TABLES statement are always visible in the entire
program, even if the statement appears within a subroutine or function module.
If you use objects (instances of ABAP classes) in your application, the visibility of data is
determined in a different way.
Data objects that are defined in the declaration part of a class are called attributes.
Private attributes
Private attributes are visible only within the object or class. All the methods of the
object can read and change the data. External access to these attributes is possible
only when you use a suitably defined method.
Public attributes
Public attributes are also visible and accessible outside of the object or class.
Protected attributes
Protected attributes are visible within the object or class, and also to instances of any
subclasses.