2 | Working with Objects
method processing block, you can implement the behavior of the class using reg-
ular ABAP statements in much the same way you would implement a procedural
subroutine or function module. However, note that many obsolete/deprecated
statements cannot be used in ABAP Objects classes. Ifyou're not sure which state-
ments have become deprecated over the years, don't worry, the compiler will tell
you where you've gone wrong. Specific details concerning individual language
elements are also described in the online help documentation (http://help.
sap.com).
Method implementations can define local variables internally using the DATA key-
word. Local variables are used to support the implementation of the method (e.g.,
as counters, temporaiy value placeholders, etc.). A general convention for defin-
ing local variable names is to prefix the name with an i. For example, a counter
variable might have the name lv_counter. This naming convention is useful for
avoiding potential naming conflicts with attributes created in the declaration part
of the class definition. Although it is possible to create a local variable with the
same name as an attribute, this is considered bad form because the local variable
hides the attribute inside the scope of the method. Subtle scoping usages like this
are hard to read and often cause errors that are difficult to debug.
2.2 Creating and Using Objects
Now that you have learned how to define classes in ABAP Objects, let's take a
look at how you can create and use objects based on those class definitions. The
following subsections will show you how to declare object reference variables,
create object instances, and access components of those objects/classes. In Sec-
tion 2.3, Building Your First Object-Oriented Program, we will put all of these
pieces together to create a fully functional program.
2.2.1 Object References
The ABAP runtime environment does not allow direct access to objects inside a
program. Therefore, to obtain access to an object at runtime, you must first
declare an object reference variable. An object reference variable contains a refer-
ence (or pointer) to an object. When we examine the object creation process in
Chapter 4, Object Initialization and Cleanup, you will come to appreciate the
52