SAP GLOBAL DECLAR - Guide



Get Example source ABAP code based on a different SAP table
  



Global Declarations of a Program

ABAP_BACKGROUND
Each ABAP program has a global declaration part where data types, interfaces, classes, and data objects that are visible throughout the program can be declared.
From a technical viewpoint, the global declaration part consists of all declarations that cannot be assigned to a more local context (class, procedure). All declarations implemented in processing blocks without their own contexts (in event blocks and dialog modules) and declarations declared between completed processing blocks are assigned to the global context. Event blocks of GET and AT SELECTION-SCREEN events are exceptions. Variables declared here are only valid in the event block.
In an ABAP statement, it is only ever possible to refer to the previous declarations of the currently visible contexts.

ABAP_RULE
Implement global declarations centrally
Place the global declaration part of a program at a central, context-related point at the beginning of the program.

ABAP_DETAILS
The global declaration part should only ever be the area between the program-initiating statement and the first implementation. This the only place where global declarations should be made in a meaningful order. This ensures that the declarations intended for global use can really be used in all subsequent implementations.
There should not be any declarative statements in contexts that do not support local data (provided that they are still used). Otherwise, a false impression of local validity is created when the program is read, which may lead to the program not being correctly understood.
This rule is only of explicit relevance when working with program types other than class or interface pools. Class Builder implicitly specifies which declarations occur and where. These are the declarations of the global class or global interface itself as well as optional local data types, classes, and interfaces in class pools. The developer cannot directly access the master program of a class pool or interface pool. This is still the case even if the source code-based Class Builder is introduced, because it only shows the declaration and implementation of the global class.
For other program types (subroutine pools, function pools, and executable programs), the developer can access the entire master program. If these program types are used, adherence to the rule is the developer's responsibility. The top include is helpful here. It is especially suited to all programs that are organized using include programs. The