Professional Documents
Culture Documents
in ABAP Objects.
The concept of classes is the foundation for all object-oriented thinking. This
will examine the individual concepts. The node on the left shows that the public
components of the class can be accessed .from outside.. On the other hand,
A class is a set of objects that have the same structure and the same behavior.
A class is therefore like a blueprint based on which all objects in that class are
created.
All components of the class are defined in the definition part. The components are
The CLASS statement cannot be nested, that is, you cannot define a class within a class
Figure 35: Example of Attributes
Attributes contain the data that can be stored in the objects of a class. Class
In classes, you can only use the TYPE addition to refer to data types. The LIKE
reference is allowed for local data objects or SY fields (for example SY-DATE,
The READ-ONLY addition means that a public attribute that was declared with
DATA can be read from outside, but can only be changed by methods in the same
class. You can currently only use the READ-ONLY addition in the public visibility
With TYPE REF TO, an attribute can be typed as any reference. This will be
You can protect attributes against access from outside by characterizing them
directly from outside. They are not visible to the outside user.
Attributes that an outside user can access directly are public attributes. The public
encapsulation. In part, this is to protect the user of a class: Assume that the private
components of a class are changed at some point, but its interface remains the
same. All external users can only access their components through the interface
of the class, and so can continue to work with the class as usual after the change
is made. The user does not notice the change. Only the internal implementation
was changed.
outside user would have to take these changes into account. You should therefore
However, this is possible using public methods that output or change the attributes.
direct value assignment) is taken into account to satisfy the encapsulation concept:
The signature of the public method clearly establishes which values must or
can be transferred, and what types are to be assigned to them. This relieves
the outside user of all responsibility. The method itself is only responsible for
For this example, imagine that the MAKE and MODEL attributes are public.
The risk would be too large, since a user might forget to supply one of the two
attributes or specify two inconsistent attributes. Instead, you could use a public
method SET_TYPE to ensure that values are specified for both attributes. A
strict syntax check governs method calls to check that all obligatory parameters
are transferred. It would even be possible for the method itself to perform a
consistency check (to see if a certain vehicle make produces the chosen model),
To save runtime, individual attributes are sometimes defined in the public visibility
objects. They can access all attributes in their class and can therefore change the
Methods have a signature (interface parameters and exceptions) that enables them
to receive values when they are called and pass values back to the calling program.
One method return value can be defined using the RETURN parameter. It
must always be transferred as a value. In this case, you cannot then define the
EXPORTING and CHANGING parameters. You can also use the RETURNING
later.
the object is called. If you use the OPTIONAL addition, the parameter remains
initialized according to type, whereas the DEFAULT addition allows you to enter
a start value.
Like function modules, methods also support the return value SY-SUBRC, but
only if the signature exceptions were defined using EXCEPTIONS (see point 1 on
the graphic). As of SAP Web AS 6.10, the RAISING addition can be used in its
place to propagate class-based exceptions (see point 2 on the graphic). The caller
return value.
the methods are called from outside the class or only from within the class. Thus,
method SET_TYPE. The instruction to initialize the attributes could exist in other
You could use classes to write complete applications by only using static
characteristics that all objects of the class have in common. During the program
runtime, the class is used to create discrete objects (instances) in the memory. This
process is called instantiation. If this is the first time the class is accessed, the
The statement CREATE OBJECT creates an object in the memory. Its attribute
values are then either initial or assigned according to the VALUE specification.
Figure 49: Reference Semantics of Object References
In this section you learn how you can use classes and their instances. That is, you
will learn about the entire process, starting with the static connections of various
An object that requires the services of another object sends a message to the object
providing the services. This message names the operation to be executed. The
The example shows the shorter syntax for method calls (supported as of SAPWeb
When calling an instance method from within another instance method, you
can omit the instance name ref. The method is automatically executed for the
current object.
A shorter syntax is also supported as of SAP Web AS 6.10. In this case, CALL
METHOD is omitted and the parameters are listed in parentheses. There must
be no space before the parentheses, but there must be at least one after the
parentheses. When you call a method that has only one import parameter, you can
specify the actual parameter in the parentheses without any other additions. When
you call a method that only has import parameters, you can omit the EXPORTING
addition.
exclusive. Please see the section about functional methods for more details.
Otherwise, the same rules apply here as they do for calling a function module.