ABAP Keyword Documentation → ABAP - Reference → Declarations → Declaration Statements → Data Types and Data Objects → Types and Objects - Overview
Validity and Visibility
The context of a declarative statement in the source code of a program determines the validity and visibility of the declared component. In ABAP programs, there are three contexts in which data types and data objects can be declared:
- Locally in procedures
Local data in procedures is valid while a procedure is being executed. It is created when the procedure is called, and deleted when the procedure is exited. In addition to their local data and formal parameters, procedures also 'see' the global data of the master program. Methods also 'see' the components of their class.
- As components of classes
Static attributes of classes exist for as long as the internal session of the ABAP program. Instance attributes of classes are related to the lifetime of objects. They are created when an object is instantiated and deleted along with the object by the garbage collector. Classes also see the global data of the master program.
- Globally in the master program
Global program data exists as long as the internal session of the ABAP program. The data is created when the program is loaded in the internal session, and deleted from the internal session when the program is removed. An ABAP program normally only sees its own global data (with the exception of interface work areas).
All contexts see the program-independent type definitions of ABAP Dictionary and the type definitions and data declarations in the public visibility areas of global classes. Local declarations, however, hide global declarations with the same name. In statements, in which a dynamic specification of a data type, a class or an interface is possible, the hiding of a global type by a local type can be cancelled by specifying an absolute type name.
In addition to context-dependent visibility, the position of the declaration in the source code also plays a role. In a statement of an ABAP program only previous declarations are visible, regardless of the context. To enable the order in the program to match the context-dependent visibility, all global declarations of a program should be specified at the start of the source code, before the first processing block, and all local declarations should be specified directly after the introduction of a procedure. Viewed like this, the definition of an interface and the declaration part of a class are both global declarations. Remember that reference variables that reference a class cannot be declared until after the class has been declared. The implementation part, on the other hand, is one of the processing blocks.
Other versions: 7.31 | 7.40 | 7.54
Note
All data declared in the declaration part of an ABAP program is global to the program. With the exception
of the event blocks AT SELECTION-SCREEN
, all data declared within event blocks
and dialog modules is global to the program. The data declared in the above event blocks is local to these event blocks. Data that is declared between discrete processing blocks is also global for the program.