Showing posts with label Statements in ABAP Objects. Show all posts
Showing posts with label Statements in ABAP Objects. Show all posts

Tuesday, June 23, 2009

Statements in Class and Interface Pools

Class and interface pools are the ABAP programs in the Class Library. They are defined using the Class Builder tool in ABAP Workbench and are used as a repository for global classes and interfaces.

  • A program with the program type class pool is launched using the statement CLASS-POOL.
  • A program with the program type interface pool is launched using the statement INTERFACE-POOL.

These statements are generated by Class Builder.

Each class pool or interface pool can only contain a single global class or a single global interface. These classes or interfaces are declared using the following statements:

  • CLASS ... PUBLIC. ... ENDCLASS.
  • INTERFACE ... PUBLIC. ... ENDINTERFACE.

Class Builder uses the properties entered here to generate these statements.

Further Statements in Class Pools

As well as the declaration of the global class, a class pool can only contain the following statements:

  • Declaration of local data types using the statement TYPES. These data types can be used by the global class in the private visibility section and in the implementation part.
  • Declaration of local interfaces using the interfaces INTERFACE ... ENDINTERFACE. These interfaces can be used by the global class in the private visibility section and in the implementation part.
  • Declaration and implementation of local classes using the statements CLASS ... ENDCLASS. These classes can be used by the global class in the private visibility section and in the implementation part.
  • Definition of macros using DEFINE ...END-OF-DEFINITION . These macros can be used by the global class in the implementation part.

Locally defined types, classes, and interfaces in class pools can be used in the following ways:

  • Only the methods of the global class access the local declarations and implementations in the program. These methods can provide utility methods, for example, which are invisible in the interface of the global class. This is the most common scenario. Any changes made to local declarations in the program do not influence the interface of the global class.
  • As well as the methods in the global class, declarations in the private visibility section of the class also reference local declarations in the program. This is a more unusual scenario, in which changes made to the local declarations influence the interface of the global class, and subclasses and friends of the global class are recompiled before the program is executed again.

Further Statements in Interface Pools

An interface pool cannot contain any local declarations or implementations as well as the declaration of the global interface. The interface pool cannot contain any of its own declarations or implementations.

Program Organization

Like any other ABAP program, class pools and interface pools consist of a global declaration part for declarations and an implementation part for implementations (or procedures).

  • This means that the global declaration part of a class pool can contain the declarations of local data types, local interfaces, and local classes, as well as the actual declaration part of the global class. The implementation part of a class pool can contain the implementation parts of local classes, as well as the implementation part of the global class.
  • The global declaration part of an interface pool can only contain the declaration of type groups alongside the declaration of the global interface. The implementation part of an interface pool is always empty.

Class Builder organizes the various declarations and implementations of a class pool or interface pool in include programs.The developer cannot usually view the names of these programs. A Class Builder function allows you to open the associated include programs in ABAP Editor and edit them. Include programs exist for:

  • Each visibility section in the declaration part of the global class
  • Each implementation of a method from the global class
  • Local declarations and implementations in programs
  • Test classes from ABAP Unit

As well as the editing functions for the individual include programs, Class Builder also provides you with a source code-based mode where you can display all the include programs as a single program, and edit them.

Restrictions

Apart from the statements listed above, class pools and interface pools do not require any other statements outside of CLASS - ENDCLASS orINTERFACE - ENDINTERFACE, nor are these statements allowed. The stricter syntax for ABAP Objects applies to all permitted statements.

The following restrictions are particularly important:

  • No processing blocks except methods
Event blocks such as START-OF-SELECTION, AT SELECTION-SCREEN, GET, or AT LINE-SELECTION are not allowed, and neither are dialog modules (defined by MODULE - ENDMODULE). This means that runtime environment events cannot be processed. ABAP Objects has its own event concept. Nor can you define function modules or subroutines using FUNCTION - ENDFUNCTION or FORM - ENDFORM. The methods of a class pool can still call external function modules and subroutines, as well as methods.
  • No shared data areas with other programs
The statements TABLES, NODES, and the addition COMMON PART of the DATA statement are not possible. This means that class pools and interface pools do not support any global data areas across programs within a single internal mode.
  • No separate screens
Screen processing as implemented in other ABAP programs is not possible. No screens ("dynpros") can be defined in a class pool or interface pool. If you want to use classic dynpros, including selection screens, we recommend that you encapsulate them in function groups. We also recommend that you use alternatives to classic lists, for example classes from SAP List Viewer (ALV) such as CL_SALV_TABLE, for displaying lists in tables.. For simple text output, we recommend browser control wrappers such as dynamic documents or text edit control wrappers.
  • No processing of extracts
In global classes, extract data sets can be edited, since the defining statement FIELD-GROUPS is forbidden in class or interface pools.

Statements for Defining Classes and Interfaces

he following statements define classes and interfaces and their components. You can use them in any ABAP program in which class and interface can be defined.

Statements for Defining Classes

Defining the Declaration Part

CLASS ... DEFINITION ...
...
ENDCLASS ...

Defining the Implementation Part

CLASS ... IMPLEMENTATION ...
...
ENDCLASS ...

Statements for Defining Class Components

Statements in the Declaration Part

PUBLIC SECTION.
PROTECTED SECTION.
PRIVATE SECTION.

TYPES ...

INTERFACES ...
ALIASES ...

CONSTANTS ...

CLASS-DATA ...
DATA ...

CLASS-METHODS ...
METHODS ...

CLASS-EVENTS ...
EVENTS ...

Statements in the Implementation Part

METHOD ...
...
ENDMETHOD.

Statements for Defining Interfaces

Declaring the Interface

INTERFACE ...
...
ENDINTERFACE ...

Statements for Declaring Interface Components

In interfaces, you can use the same statements to declare interface components as those used in the declaration part of classes.

Note

In the declaration part of a class or in interface, you declare its components, that is, its attributes, methods, and events. You can declare local data types using the TYPES statement. You can also declare alias names for the components of implemented interfaces using the ALIASES statement. In a class, all declarations must belong to one of the four visibility sections introduced by the relevant statement.

The implementation part of a class only contains method implementations in METHOD - ENDMETHOD blocks. In a method, you can only use the statements for method implementations.

No statements other than those listed above are necessary for defining classes or interfaces. Consequently, no other statements are allowed between CLASS and ENDCLASS or INTERFACE - ENDINTERFACE except within methods.

The stricter syntax in ABAP Objects applies to all statements for defining classes and interfaces.

ABAP Objects - Keywords

The following list displays the keywords specially introduced for ABAP objects.

ALIASES Declaration of an alias name
CALL METHOD Call of a method
CLASS ... ENDCLASS Definition of a class
CLASS-DATA Declaration of a static attribute
CLASS-EVENTS Declaration of a static event
CLASS-METHODS Declaration of a static method
CREATE OBJECT Creation of an object
EVENTS Declaration of an instance event
INTERFACE ... ENDINTERFACE Definition of an interface
INTERFACES Including an interface
METHOD ... ENDMETHOD Definition of a method
METHODS Declaration of an Instance method
PRIVATE SECTION Start of private visibility section
PROTECTED SECTION Start of a protected visibility section
PUBLIC SECTION Start of the public visibility section
RAISE EVENT Triggering an event
SET HANDLER Registering an event

Blog Archive