0% found this document useful (0 votes)
108 views25 pages

ABAP Programming - An Integrated Overview: Horst Keller

abap

Uploaded by

Ahmed Hassane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
108 views25 pages

ABAP Programming - An Integrated Overview: Horst Keller

abap

Uploaded by

Ahmed Hassane
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 25

ABAP Programming — An Integrated Overview

Home

ABAP Programming —
An Integrated Overview
Horst Keller

ABAP has undergone a profound evolution. When it first came on the


scene, it was a mainframe-based macro assembler language used exclu-
sively for reporting purposes. Nowadays, ABAP is a hybrid language,
as shown in Figure 1, that encompasses two programming models.

In the classical ABAP programming model, program execution is


based on events that are triggered by the ABAP runtime environment.
The two classical types of application programs, reporting and dialog
programs, are governed by this programming model. In classical report-
ing you know these runtime events as START-OF-SELECTION, GET,
and so on. In classical dialog programming, the most important runtime
events are PROCESS BEFORE OUTPUT (PBO) and PROCESS
Horst Keller is a member of AFTER INPUT (PAI).
the ABAP language group,
where he is responsible for The second Figure 1
information rollout. He is ABAP programming
model, added just
documenting the ABAP
recently, is object- ABAP
language with an emphasis Object-Oriented Programming
oriented program- Objects
on ABAP Objects, and ming. In a pure
develops and teaches object-oriented
classes on ABAP world, the program
programming. Horst is execution is based Runtime Event-Oriented Programming
Classical
also writing presentation on the instantiation ABAP
programs for the ABAP of classes and on Dialog
method calls, but in Programming Reporting
documentation and the
ABAP, objects can
corresponding examples in also be used in
the R/3 Basis system. classical programs.
(complete bio appears on page 109)

No portion of this publication may be reproduced without written consent. 85


SAP Professional Journal January/February 2000

Just as the language has changed, so must our This is about as elementary as it gets.
usage and view of the language. Most ABAP pro- The REPORT statement opens the program
grammers are mired in the classical ABAP program- select_and_write. The DATA statement
ming model, building applications that revolve declares data named wa_splfi. The SELECT
around reports or dialogs. There tends not to be a lot statement reads data from a database table spfli
of crossover between these two development camps. into wa_splfi. The WRITE statement writes
Before Release 4.0, even SAP’s documentation and data to the screen.
training taught these topics separately, treating the
interconnection between the two — for example,
calling a dialog screen during list processing — as a The thing worth noting is that even this short
special feature. As a result, you find report program- and simple program showcases the most important
mers who don’t know the meaning of a module pool, features that are common to nearly every ABAP
and application specialists who know how to program: it declares data, and it communicates with
program advanced transactions, but can’t wield a the database as well as with a screen.
START-OF-SELECTION statement.

With Release 4.0 and the dawn of ABAP Objects, Now consider that an R/3 system has a complex,
we’re replacing the classical distinction between multi-tiered architecture with at least three software
reporting and transaction programming with an inte- layers, namely the presentation layer, the application
grated view in documentation and training, recogniz- layer, and the database layer. (Other layers, such as
ing the simple fact that all application logic is pro- the Internet-enabling layer, are extensions to the basic
grammed in ABAP and that the application can com- three-tiered architecture.)
municate with the user via screens and with the data-
base via a common interface. Changing between
programming types (i.e., doing reporting during a The connection between the layers depends
transaction) is, and technically always has been, on the hardware configuration of the system,
nothing special. This is a natural feature of the lan- but is generally realized by network links. So
guage — one that should be exploited if you want to the four statements in this short, simple coding
use ABAP efficiently. exercise are actually a complete example of client/
server computing: the program is executed on an
The aim of this article is to provide new ABAP application server; data is transferred from the
programmers with a fresh, integrated overview of the database server to the program; a screen with a
language, and to provide experienced ABAP pro- user interface is defined and sent to the presentation
grammers, who may be used to reporting or dialog server.
programming, with insights to overcome the gap
between these classical programming types and ulti- Don’t lose sight of this when writing ABAP
mately better prepare you for ABAP Objects. programs, especially when it comes to database
accesses, where the load on the network plays an
important role for the performance of a program.
Look closely at the code again. You see that all data
A Simple ABAP Program (*) of one database line is selected, but only three
fields are displayed. Already, in this simple program,
Let’s start our discussion with the very simplest of the network load can be reduced by replacing the *
ABAP programs — the kind you learn at the start with a list of field names. Of course such measures
of a beginners’ ABAP class, and which is shown in are more important when you select more than
Figure 2. one line.

86 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

Figure 2 A Very Simple ABAP Program


REPORT select_and_write.
DATA wa_spfli TYPE spfli.
SELECT SINGLE * FROM spfli
INTO wa_spfli
WHERE carrid = 'UA' AND connid = '0941'.
WRITE: wa_spfli-airpfrom, wa_spfli-airpto, wa_spfli-fltime.

Figure 3 Logical Components of the R/3 Basis System

The Runtime Environment logical components of the R/3 Basis system and how
they map to the R/3 multi-tiered architecture:
of ABAP Programs
The runtime environment has a direct impact on the • The presentation components are responsible
execution of ABAP programs and is the basis for the for the interaction between the R/3 system and
classical ABAP programming model. Anyone who the user.
wants to advance beyond simple programming needs
to understand it and how it enables client/server • The ABAP Workbench component is a full-
computing within an R/3 environment. fledged development environment for applica-
tions in the ABAP language. It is fully integrated
The central platform for all ABAP applications is in the R/3 Basis system, and, like other R/3 appli-
the R/3 Basis system. Figure 3 shows the three cations, is itself written in ABAP.

No portion of this publication may be reproduced without written consent. 87


SAP Professional Journal January/February 2000

Figure 4 The ABAP Runtime Environment

• The kernel and Basis services component pro- In addition to mediating the dialogs between
vides a hardware-, operating system-, and data- ABAP programs and screens or databases, the
base-independent runtime environment for ABAP runtime environment is also responsible for the ex-
programs (applications). This runtime environ- ecution of an ABAP program. Figure 4 also shows
ment is written mainly in C and C++. All ABAP the structure of ABAP programs. Each ABAP pro-
programs run on virtual machines (VM) within gram consists of a global data declaration part and
this component. self-contained processing blocks. Apart from its
global data declarations, any statement of an ABAP
All R/3 application programs are embedded in the program is definitely part of exactly one processing
R/3 Basis system. This makes them independent of block. Processing blocks cannot be nested. The
the hardware and operating system that you are using. ABAP runtime environment triggers the execution of
However, it also means that you cannot run them the processing blocks, and therefore steers the time
outside the R/3 system. In Figure 3, you see that the sequence in which ABAP programs are executed.
communication of the ABAP application programs The order of the processing blocks does not influence
with the screens of the presentation layer and the the program execution. When a processing block is
database system of the database layer is not direct. triggered, its coding is processed sequentially. There
These communications are mediated by the R/3 Basis are processing blocks that are triggered from the
system. We simplify this picture in Figure 4 by runtime environment and those that can be called with
saying that each ABAP program is encapsulated in a ABAP statements from other processing blocks.
runtime environment delivered by the R/3 Basis When the execution of a processing block is finished,
system. control is given back to the caller.

88 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

Processing Blocks Figure 5 Event Keywords

Most of you know that all ABAP programs are made Program constructor event: LOAD-OF-PROGRAM
up of processing blocks. If you are familiar with This event is triggered exactly once, when an
classical reporting, you know the processing blocks ABAP program is loaded into the memory. The
that are defined by the statements START-OF- statements in this block can initialize the data of
SELECTION, GET, and so on. If you do dialog the program.
programming, you are well-acquainted with the dia-
log modules defined between the MODULE and Reporting events: INITIALIZATION, START-
ENDMODULE statements. Other processing blocks, OF-SELECTION, GET, END-OF-SELECTION
such as subroutines or function modules, are common These events are triggered by the ABAP runtime
to both classical programming styles. ABAP Objects environment while an executable program is
does not change this organization of ABAP programs, running. START-OF-SELECTION is the
but merely adds new types of processing blocks, such standard processing block of an executable ABAP
as methods, for example. program. Each procedural statement in an
executable program automatically belongs to
When you look at the statements of an ABAP START-OF-SELECTION if you do not define
program, you should always be able to recognize its other processing blocks explicitly. The statements
processing blocks. Only with this knowledge are you in the other blocks serve as application logic for
able to understand the program flow. report programs.

The following sections describe the different Selection screen events: AT SELECTION-
processing blocks and how they are executed in dif- SCREEN ...
ferent kinds of programs. Note that the ABAP This is a set of events that are triggered by the
Debugger supports you by showing the structure of a ABAP runtime environment when a selection
program and its processing blocks when you choose screen is processed. The statements in these
the function Overview. blocks can prepare the screen or process the
user’s input.

Event Blocks List events: TOP-OF-PAGE, END-OF-PAGE,


AT LINE-SELECTION, AT USER-COMMAND
Event blocks are introduced by one of the event
These events are triggered by the ABAP runtime
keywords listed in Figure 5. There is no explicit
environment while a list is being created or
statement to end an event block. It is concluded by when a user performs an action on a list. The
the next processing block. To make an ABAP pro- statement in these blocks can format the list or
gram more readable, it is always a good idea to con- process the user’s requests.
clude an event block with a comment line! Event
blocks have no local data area and no parameter Screen events: PROCESS BEFORE OUTPUT,
interface. Their execution is triggered by events in PROCESS AFTER INPUT
the ABAP runtime environment. These events, abbreviated by PBO and PAI, are
triggered by the ABAP runtime environment
before a screen is sent and after a user action
Dialog Modules on a screen. The respective event blocks are not
defined in the ABAP program but in the screen’s
Dialog modules are defined between the MODULE flow logic.
and ENDMODULE statements. They have no local
data area and no parameter interface. They are called

No portion of this publication may be reproduced without written consent. 89


SAP Professional Journal January/February 2000

during the PBO and PAI events from the screen flow distinguish between instance and static methods.
logic of the ABAP program’s screens, and they con- While instance methods are bound to the objects
tain the application logic for the screens. of a class, static methods can always be called.

Classes Looking back at our simple code example in


Figure 2, you see that there is no explicit processing
Classes are defined between the CLASS and block defined. This means that all procedural state-
ENDCLASS statements. The definition of a class ments implicitly belong to the standard event block
consists of a declaration part, where its components START-OF-SELECTION. Figure 6 shows
are declared, and an implementation part, where its a complete version of the program.
methods are implemented. Classes cannot be
executed but serve as patterns for objects.

Procedures
Program Execution
ABAP supports three types of procedures. They
have a local data area and a parameter interface. At this point, even for the new ABAP programmers
Procedures can be called internally from the same among us, it should be clear that an ABAP program
ABAP program or externally from another ABAP is a container for processing blocks that are either
program. In the latter case, the procedure’s ABAP triggered by the runtime environment or called by
program is loaded into the memory, in addition to the ABAP statements from other processing blocks.
calling ABAP program. When a program is executed, at least one processing
block must be triggered from outside the program by
We differentiate between: the runtime system. Therefore, starting an ABAP
program actually means to load it into memory and to
• Subroutines start a process in the runtime environment that trig-
Subroutines are defined between the FORM and gers the program’s processing blocks. The kind of
ENDFORM statements in any ABAP program process that is started in the runtime system and the
except class pools. They can have positional sequence in which it triggers the processing blocks is
parameters and are called with the PERFORM totally independent of their sequence in the program.
statement. It depends solely on the ABAP program’s type.

• Function modules You enter a program’s type in its attributes when


Function modules are defined between the you create a program. There are two types of pro-
FUNCTION and ENDFUNCTION statements in grams that can be started by the user: executable
programs of type function pool. They can have programs and module pools. Historically, executable
keyword parameters and are called with CALL programs are used for reporting, and module pools
FUNCTION. are used for dialog programming. Report program-
mers are therefore familiar with executables, and
• Methods dialog programmers are familiar with module pools.
Let us look now at the technical difference between
Methods are defined between the METHOD and them. This will help you to decide which type to
ENDMETHOD statements in the implementation choose when you create a new program.
part of classes. They can have keyword param-
eters and are called with CALL METHOD or
triggered by events of ABAP Objects. Functional Executable Programs (Type 1)
methods that have exactly one resulting param-
eter can be used as operands in expressions. We An executable program is introduced with the

90 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

Figure 6 A Second Look at Our Simple ABAP Program


REPORT select_and_write.
***********************************************************************
* Global data declarations
***********************************************************************
DATA wa_spfli TYPE spfli.
***********************************************************************
* Processing blocks
***********************************************************************
START-OF-SELECTION.
SELECT SINGLE * FROM spfli
INTO wa_spfli
WHERE carrid = 'UA' AND connid = '0941'.
WRITE: wa_spfli-airpfrom, wa_spfli-airpto, wa_spfli-fltime.
***********************************************************************

Figure 7 The Runtime Sequence of Events

REPORT statement. You can start it by simply typing sequence of events. If the program contains event
its name in an appropriate R/3 screen, for example blocks for some or all of those events, they are ex-
after choosing System → Services → Reporting. By ecuted in exactly that sequence. If there are no event
starting an executable, you start a special process in blocks defined for some events, the respective events
the ABAP runtime environment that triggers a given are simply disregarded. Figure 7 shows the sequence

No portion of this publication may be reproduced without written consent. 91


SAP Professional Journal January/February 2000

of events triggered by the runtime environment when logical database can be processed — e.g., in an inter-
executing an executable program. nal table. Without a logical database, an event block
for END-OF-SELECTION does not make much
As for all ABAP programs, the program construc- sense, because the statements can also be coded in
tor LOAD-OF-PROGRAM is triggered first. Then, the event block for START-OF-SELECTION.
a reporting-specific sequence is processed. If there is
a standard selection screen defined in the program, Finally, the runtime system automatically dis-
this screen is automatically displayed after the plays the list that was defined in these event blocks.
event INITIALIZATION. In the respective When the user leaves the list, the program is either
event block, the selection screen can be initialized. stopped, or, if a selection screen was displayed, the
User actions on the selection screen trigger execution of the program is automatically started
AT SELECTION-SCREEN events, where the again. In the latter case, the program is only stopped
user’s input can be processed. Then, the standard when the user leaves the selection screen.
event START-OF-SELECTION is triggered.
From Figure 7 you can now fully understand the
The following GET events are triggered only if execution of the program in Figure 6. It is an execut-
the executable program is connected to a logical able program and START-OF-SELECTION is the
database. Logical databases are special ABAP pro- single event block of that program. There is no
grams that contain the definition of a selection screen selection screen defined, but a list is written with the
and a set of special subroutines for reading data from WRITE statement. After executing the event block,
database tables. During the execution of an execut- the list is displayed by the runtime environment.
able program with a logical database, the selection
screen of the logical database is displayed and its The program flow as shown in Figure 7 supports
subroutines are called by the runtime environment classical reporting. But since you do not need to
in a sequence that results from the logical database’s program event blocks for all possible events, you can
hierarchical structure. When a subroutine in the use executable programs for all other types of appli-
logical database has selected a line from the database, cation programs, for example, by calling screen
the runtime system triggers the respective GET event sequences during START-OF-SELECTION.
and the executable program can process the data
that is delivered in a common data area. Logical
Module Pools (Type M)
databases are reusable components that hide the
details of the data selection from the main ABAP A module pool is introduced with the PROGRAM
program. statement. You cannot start it by simply typing its
name. You must use a transaction code. Defining a
Note that from Release 4.5A on, it is also possible transaction code for a program simply means to link a
to call logical databases from any ABAP program, screen of the program to this transaction code. There-
and that we plan to encapsulate them in classes in a fore, in order to be executable, a module pool must
coming release. The latter measure will clearly dis- have at least one screen. Transaction codes are usu-
tinguish their functions and data from their ABAP ally connected to menu entries in the R/3 user inter-
program’s clients. face. A user can start a program via a transaction
code by choosing such a menu entry or by typing the
When the logical database has finished its data code directly into the OK field of the standard toolbar
selection or directly after START-OF-SELECTION, of any R/3 screen.
if there is no logical database connected, the runtime
system triggers END-OF-SELECTION. In the re- When a program is started via a transaction
spective event block, all data that is selected by the code, it is loaded into memory, and the runtime

92 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

environment triggers the PROCESS BEFORE OUT- automatically modularized. Besides this kind of
PUT (PBO) event of the screen that is connected to modularization, you can use a special class of pro-
the transaction code. Then, the program flow is cessing blocks, namely procedures, for a program-
controlled by a sequence of screens that usually driven modularization and for code reuse. In classical
depends on the user’s actions. ABAP, you are probably familiar with subroutines and
function modules. ABAP Objects adds methods as
A module pool contains the dialog modules that new kinds of procedures. Principally, we can distin-
are called during the PBO and PROCESS AFTER guish between internal and external modularization.
INPUT (PAI) events of its screens. Therefore, the
program type “module pool” is appropriate for ABAP
programs that are mainly dialog-driven. Nevertheless, Internal Modularization
module pools may contain not only dialog modules,
but also all the event blocks for those events that can If you want to reuse sequences of code and to encap-
be triggered during their execution. While reporting sulate functions and data within your ABAP program,
events never occur during the execution of a module you can modularize your program either with local
pool, the events for selection screen and list processing subroutines or methods of local classes. After defin-
can be triggered, if such screens are defined in the ing the procedures in your program, you can call
program. them with the respective statements. You can pass
data to and from these procedures. They both support
Module pools can be started via transaction codes a local data area.
only. Therefore, they must contain screens and
dialog modules for those screens. But note that trans-
action codes and dialog modules are not restricted to External Modularization
module pools — they can be defined for all programs If you want to create procedures that are accessible
that have their own screens. So executable programs not just inside one program, but for all ABAP pro-
can be handled exactly as module pools — they just grams of the R/3 system, you can create function
do so without the support of reporting. modules or methods in global classes. Function
modules and global classes cannot be defined in
A module pool contains the dialog executable programs or module pools. Therefore,
modules that are called during the PBO you must create special types of ABAP programs
and PAI events of its screens. Therefore, called function pools (Type F) and class pools (Type
the program type “module pool” is K). Function pools and class pools cannot be created
appropriate for ABAP programs that are by simply choosing the program type in the ABAP
mainly dialog-driven. Nevertheless, Editor. You must use the tools Function Builder and
module pools may contain not only dialog Class Builder of the ABAP Workbench. These tools
modules, but also all the event blocks for create ABAP programs of the respective type and
those events that can be triggered during structure and support you in defining the parameter
their execution. interfaces of the procedures.

You define the function of such procedures by


typing its procedural statements inside processing
Program Modularization blocks that are generated by the tools. One function
pool can contain several function modules and one
Since ABAP programs must provide processing class pool can contain one global class with several
blocks in order to be executed and to react on the methods. Function pools can be modularized inter-
triggers from the runtime environment, they are nally by local subroutines or methods of local classes.

No portion of this publication may be reproduced without written consent. 93


SAP Professional Journal January/February 2000

Figure 8 Program Modularization in Classical ABAP Programming Model

Class pools can be modularized internally by in memory as long as the executable program is
local classes only. Function pools may contain, and running.
therefore encapsulate screens. Class pools do not
support screens yet. In a future release, the introduc-
tion of a package concept is planned, to restrict the
access to global classes to members of the same Source Code Modularization
package.
There is another kind of modularization that
Figure 8 gives an overview of the different types you should never confuse with real program
of program modularization in classical ABAP pro- modularization. This is source code modularization
gramming. The ABAP runtime environment triggers with Include programs (Type I). Include programs
START-OF-SELECTION in an executable program. are not separately compiled units. Their source code
There, a function module is called. The function pool is inserted into the programs in which a correspond-
of that function module is loaded into the memory if ing INCLUDE statement occurs. Include programs
it is not already there. The function module itself allow you to manage complex programs in an orderly
makes an internal subroutine call. Then, the control way. For example, function pools and module pools
returns to the executable program, and an internal use Include programs to store parts of the program
subroutine is called there. The function pool stays that belong together. The ABAP Workbench sup-

94 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

ports you extensively when you create such complex program after executing the called programs. It is
programs by creating the Include programs automati- interesting to note that executable programs are al-
cally and by assigning them unique names. A special ways started via a SUBMIT statement. When a user
Include is the TOP Include of a program. If you enters the program name in a transaction like SA38,
name it by post-fixing TOP behind the program’s he or she is already working with a running ABAP
name, it is always included in program navigation and program, and when he or she chooses Execute, a
in the syntax check. But you should never forget that SUBMIT statement is executed somewhere in a dialog
an ABAP program always has the structure shown module of the transaction. From a technical point of
back in Figure 4, although it may be composed of view the principal characteristic of an executable
many, even deeply, nested Include programs. It is a program is that it can be called by SUBMIT. Its
good exercise to open a function module with the principal characteristic from a user’s point of view is
Function Builder and to display the respective func- that it can be executed by typing its name.
tion pool. Now try to match the coding of the
function pool with the structure of Figure 4.

There is another kind of modularization About ABAP Types and Data


that you should never confuse with real
program modularization. This is source It is clear that the main task of ABAP as a business
code modularization with Include application language is to handle and process data.
programs (Type I). Include programs Now that we know how ABAP programs are struc-
are not separately compiled units. tured and executed, it is time to look at how various
Their source code is inserted into the types of data are realized in ABAP.
programs in which a corresponding
INCLUDE statement occurs. Include In ABAP, data appears as the contents of data
programs allow you to manage complex objects (fields). The prototype statement to define
programs in an orderly way. data objects is DATA. Each data object has appropri-
ate memory assigned to it and a data type that de-
scribes its technical attributes. Data types can be
mere attributes of data objects, but you can also de-
fine data types using the TYPES statement. Then,
Calling ABAP Programs data objects can be viewed as instances of such data
types. This concept of standalone data types was
In addition to calling procedures from external pro- introduced with Release 3.0. Before that, you knew
grams, you can also start the execution of executable data types only as attributes of data objects. Since
programs or module pools from other ABAP pro- Release 4.5, the ABAP “type” concept is also mir-
grams, either with the SUBMIT statement or with rored in the ABAP Dictionary. Prior to Release 4.5,
CALL TRANSACTION. The called programs are you used the ABAP Dictionary mainly as a tool for
loaded into memory and executed by the runtime creating and maintaining database tables, and you
environment. With the SUBMIT statement, you start could create ABAP data objects that referred to the
exactly the same process in the runtime environment structure of such tables. Besides, the only data types
that you saw in Figure 7. With CALL TRANSAC- you could create in the ABAP Dictionary were so-
TION, the runtime environment triggers the PBO called structures, which behaved like database tables
event of the screen that is connected to the transaction without contents. Nowadays, you can use the ABAP
code named in the statement. You can decide Dictionary as an unrestricted tool and repository for
whether you want to exit the calling program or global data types that are part of the “ABAP type
whether the control should return to the calling universe.”

No portion of this publication may be reproduced without written consent. 95


SAP Professional Journal January/February 2000

Figure 9 The ABAP Type Universe

The ABAP Type Universe ABAP Workbench. Global data types are created in
the ABAP Dictionary, and global object types are
Data types and objects are part of the ABAP type created with the class builder in the class library.
universe, which is shown in Figure 9. While the types in the R/3 repository are visible in all
ABAP programs, local types are visible only inside
Types are descriptions that do not occupy the defining program.
memory. Objects are instances of types, and do
occupy their own memory space. A type describes When you define a local type with the TYPES
the technical attributes of all of the objects with that statement, or a data object with the DATA statement,
type. Data types describe data objects. Object types you can refer with the TYPE clause to all data types
are used in ABAP Objects. that are visible in the context of the definition. Or
you can use the LIKE clause to refer to another data
All types of the ABAP type universe can either object that is visible within this context. In both
be defined locally, inside an ABAP program using cases, the newly defined data type or object inherits
the TYPES, CLASS, or INTERFACE statements, the attributes of the type or object that is being
or globally, in the R/3 repository, using tools of the referred to.

96 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

For the elementary data types, ABAP provides TYPES|DATA myref TYPE REF TO
predefined patterns that you can use to define your DATA|otype.
own types or objects. The predefined data types with
fixed lengths are: This statement creates a reference type or refer-
ence variable myref. Pointers in variables of that
• Numeric types F (floating point), I (integer), and type may either point to data objects or to instances of
P (packed number in BCD format) all classes that are specializations of the object type
• Character types C (character), N (numeric text), otype.
D (date), and T (time)
Going back to the code listing featured in
• Hexadecimal type X (hexadecimal field) Figure 6, we can now understand its data declaration.
A data object named wa_spfli is declared by refer-
The predefined data types with variable lengths ring to a type spfli. Since there is no type of this
are: sort defined locally in the program, spfli must be a
• Character string STRING type from the ABAP Dictionary. As can be seen in
the WRITE statement, wa_spfli is a structure with
• Byte string XSTRING different components, and spfli is a structured data
type. As for all repository objects, you can navigate
While the length of data objects with fixed length from the ABAP Editor to the type’s definition by
types is constant at runtime, the length of data objects double-clicking its name.
with variable length types will vary according to their
contents.
Local Data and Global Data in ABAP Programs
Complex types are composed from any other data When we speak about data in ABAP programs, it is
types that can be elementary, itself complex, or refer- very important to look at the places where you can
ence types. While structures are sequences of other declare data, and where that data is visible. The
data types, internal tables consist of a dynamic ABAP Workbench supports this with its forward
sequence of lines, all with the same data type. There navigation. If you double-click on names of types or
are no predefined complex types — you must define data anywhere in an ABAP program, the Workbench
them yourself in a program or in the ABAP Dictio- leads you to the place of definition.
nary. For example, the ABAP statement for defining
an internal table is: There are exactly three contexts where data
objects and types can be defined inside ABAP
TYPES|DATA itab TYPE|LIKE TABLE programs:
OF line WITH key.
• Local data in procedures
This statement creates a data type or data object When you use the statements DATA or TYPES
itab, where the data type of the lines is taken from in a procedure (subroutine, function module,
data type or object line. The key addition specifies or method), you define local data or types in that
the internal table’s key. procedure. They are visible only inside the
procedure and live as long as the procedure is
Reference variables contain references (pointers) executed. The parameters of the procedure’s
that can either point to data objects or to instances of parameter interface also behave like local data.
classes in ABAP Objects. There are no predefined
reference types, but you must define them yourself in • Attributes in classes
a program or in the ABAP Dictionary. The ABAP When you use the statements DATA or TYPES
statement for defining a reference is: between the statements CLASS and ENDCLASS,

No portion of this publication may be reproduced without written consent. 97


SAP Professional Journal January/February 2000

you define attributes or types of that class. In at the top of the program, and never inside event
classes, you must define explicitly the visibility blocks or dialog modules. A source code
of attributes and types. In general, you define modularization with a TOP Include supports
private attributes that are visible only in the this issue.
methods of the same class, but public attributes
that are visible for the outside client are also Figure 10 shows how the program in Figure 6
possible. For class data we distinguish between can be rewritten in order to get rid of the global data.
instance and static data. While instance data Now, the data object wa_splfi is declared locally
is bound to the objects of a class, static data in a subroutine get_data. Another subroutine,
is always available. output_data, has a parameter interface and
writes the data to the screen.

• Global program data


When you use the statements DATA or TYPES
anywhere else in an ABAP program, especially if Screens
you use them in event blocks or dialog modules,
you define global data or types of that program. The preceding sections gave you an overview of the
They are visible in all the program’s processing structure, execution, and data of ABAP programs
blocks that are defined behind their definition. embedded in the ABAP runtime environment at the
application server. This section explains how ABAP
Working with global program data is dangerous, programs communicate with the user via screens.
especially in large and complex programs. Since
global data can be changed from everywhere, it is not As a user of an R/3 system, you are always
easy to keep it consistent. Imagine a function pool confronted with screens. From the moment you log
with global data declarations in its declaration part. on, you see a screen and you must perform actions
Any function module of that function pool can on this screen. All those screens are components
work with that data. A function pool is loaded into of ABAP programs.
memory when the first of its function modules is
called. Then it stays in memory and holds its global Generally, you define the screens of an ABAP
data as long as the calling program is running. If program with the Screen Painter tool of the ABAP
in the same program, maybe much later, another Workbench. In the classical programming model,
function module of the same function pool is called; general screens were mainly used for dialog program-
this one will find the old contents of the preceding ming with module pools. The use of screens, how-
function modules in the global data. In some cases ever, is not restricted to module pools. Executable
this effect might be desired, but it can also lead to programs and function pools can contain and use
errors, especially if you forget to initiate the data screens, too. Besides the general method, there are
before using it. also special screens that can be defined with ABAP
statements within the program. These are the selec-
This is why you should try to work with encapsu- tion screens and lists, which are widely used in
lated local data in classes or procedures as much as classical reporting.
possible. Except for a few cases, there is no real need
to work with global data in ABAP. In cases where
you must work with global data — for example, to General Screens
transport data from and to a screen or to receive data
from a logical database — for the sake of readability, In the R/3 system, screens are program objects that
be sure to define all global data in the declaration part consist of two parts. First, they have a layout that

98 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

Figure 10 Simple ABAP Program with No Global Data

REPORT select_and_write_with_forms.
***********************************************************************
* Processing blocks
***********************************************************************
START-OF-SELECTION.
PERFORM get_data.
***********************************************************************
FORM get_data.
DATA wa_spfli TYPE spfli.
SELECT SINGLE * FROM spfli
INTO wa_spfli
WHERE carrid = 'UA' AND connid = '0941'.
PERFORM output_data USING wa_spfli.
ENDFORM.
***********************************************************************
FORM output_data USING l_spfli TYPE spfli.
WRITE: l_spfli-airpfrom, l_spfli-airpto, l_spfli-fltime.
ENDFORM.
***********************************************************************

defines the frontend appearance of the window that is • PROCESS BEFORE OUTPUT
presented to the user. Second, they have a flow logic
The respective event (PBO) is triggered after the
that is executed on the backend by the application
PROCESS AFTER INPUT (PAI) processing of
server. The screen flow logic is a program layer
the previous screen and before the current screen
between the frontend and the actual ABAP applica-
is displayed.
tion program at the backend. The language used to
program screen flow logic has a similar syntax to
• PROCESS AFTER INPUT
ABAP, but is not part of ABAP itself. Unlike ABAP
programs, the screen flow logic contains no explicit The respective event (PAI) is triggered when the
data declarations. You define the screen fields by user chooses a function on the current screen.
placing elements on the screen mask instead. When
you define screen fields by referring to data types in The main task of these processing blocks is to call
the ABAP Dictionary, the runtime environment auto- ABAP dialog modules using the MODULE statement.
matically creates dialogs for field help, input help, During the PBO event, you can call any dialog
and error handling that depend on the semantics of module in the ABAP program that is marked with the
the data type in the dictionary. addition OUTPUT. In the PAI event, you can call
any dialog module program that is marked with the
The screen flow logic is similar to an ABAP addition INPUT. The screens of an ABAP program
program in that it contains processing blocks. These can share the dialog modules of that program. You
processing blocks are event blocks that are triggered use the dialog modules called during PBO to prepare
by the ABAP runtime environment. The most impor- the screen and the dialog modules called during PAI
tant event blocks are: to react to the user input.

No portion of this publication may be reproduced without written consent. 99


SAP Professional Journal January/February 2000

Figure 11 Calling a Screen Sequence

Each screen of an ABAP program has a unique triggers the PBO event, and the corresponding coding
screen number. The screens of an ABAP program is executed in the screen’s flow logic (shown in gray).
can be combined to form screen sequences. Screen After processing PBO, the screen is displayed at the
sequences are either built statically by setting the frontend where a user action triggers PAI. After
following screen in the Screen Painter or dynamically processing PAI, the runtime system triggers PBO of
by overriding the static setting in the ABAP program. the next screen in the sequence. This is repeated until
The last screen of a screen sequence is always the one the number of the next screen in the sequence is zero.
where the following screen is set to zero. The small- Depending on how the first screen was called, the
est screen sequence is a single screen that is directly program either terminates, and control returns to
followed by screen zero. Figure 11 shows how you the point from where the transaction code was used,
call screens or, to be precise, a screen sequence. or the program continues processing directly after
the CALL SCREEN statement.
You call a screen sequence either by using a
A user can interact in various ways with screens.
transaction code from outside the ABAP program, or
We distinguish between actions that trigger PAI and
by using the CALL SCREEN statement in the same
those that don’t. In general, filling input fields with
ABAP program. As you already know, a transaction
values does not trigger PAI. Actions that do trigger
code is always connected to a screen of an ABAP
PAI include:
program. When you use a transaction code or the
CALL SCREEN statement, the runtime system • Choosing a pushbutton on the screen.

100 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

Figure 12 Data Transport Between the Screen and the ABAP Program

• Choosing a specially prepared check box or radio with the corresponding function code when the user
button on the screen. chooses a function. As for all other screen fields, the
contents of that field can be evaluated in the ABAP
• Choosing a function in the menu, standard program in order to react to the user’s input.
toolbar, or application toolbar.

• Choosing a function key on the keyboard. Figure 12 shows the data transport between the
screen and the ABAP program. During PAI, the
What all of these actions have in common is that system automatically transports all screen fields to
they are all linked to a function code. The function identically named global ABAP program fields. At
codes of elements on the screen are defined with the the end of the last PBO module, and before the screen
Screen Painter. The function code in menus, standard is displayed, all of the data is transported from the
toolbar, application toolbar, or those assigned to func- ABAP program to any identically named fields in the
tion keys are defined in a GUI status. A GUI status is screen. By standard, all screen data is transported
an independent component of an ABAP program that immediately before PAI processing starts. But for the
provides the user with a range of functions in the user dedicated handling of screen fields — for example, to
interface of the screen. It is defined with the Menu carry out an error dialog — you can control the mo-
Painter tool of the ABAP Workbench. One GUI ment at which data is passed from screen fields to
status can be reused by several screens. Each screen their corresponding ABAP fields by using the FIELD
automatically contains a special field that is filled statement in the screen flow logic.

No portion of this publication may be reproduced without written consent. 101


SAP Professional Journal January/February 2000

The time when the ABAP dialog modules process responsible for displaying a list and for interpreting
the data for the screens is called a “dialog step.” A user actions on the list. You call the list processor
dialog step extends between a user action on one with the LEAVE TO LIST-PROCESSING state-
screen and the appearance of the following screen. ment. If the program is an executable, the ABAP
This time comprises the processing of PAI and PBO runtime environment automatically calls the list pro-
of two successive screens. Note that during a user cessor after triggering the last event of the program.
dialog with the R/3 system, only the dialog steps As for selection screens, the PBO and PAI handling
occupy the application server, and not the time where is encapsulated in the runtime environment and user
the screen accepts a user’s input. actions on a list trigger events (e.g., AT LINE-
SELECTION). Output statements in the respective
event blocks create detail lists, which are then auto-
Special Screens matically displayed at the end of the event block.
You can create up to 19 detail lists for a single basic
ABAP provides two types of special screens: selec- list. The user can navigate between the different
tion screens and lists. These screens and their flow levels by choosing functions from the list’s GUI
logic are generated from ABAP statements. In this Status.
case, you do not have to work with the Screen
Painter.

Selection screens are special screens used to enter Using Screens


values in ABAP programs. You can define selection
screens in the global declaration part of any ABAP From the facts you learned in this and the preceding
program that can contain screens using the following sections, it should be clear that the usage of the dif-
special declaration statements: SELECTION- ferent types of screens is not restricted to special
SCREEN defines and formats selection screens, and program types. General screens are not restricted to
PARAMETERS and SELECT-OPTIONS define input module pools and selection screens, and lists are not
fields for single values or intervals. An executable restricted to executable programs. Which screen you
program or a logical database may have a standard use depends merely on which dialog your program
selection screen with the reserved number 1,000. shall perform with the user. So you might start a
You call a selection screen in the same ABAP pro- module pool with a transaction code connected to a
gram using the CALL SELECTION-SCREEN state- general screen, send a selection screen during the
ment. If the program is an executable, the ABAP PBO processing of that screen, and define and pro-
runtime environment automatically calls the standard cess a list during PAI. Vice versa, you might start an
selection screen after the INITIALIZATION event. executable program, take advantage of its standard
The PBO and PAI handling of selection screens selection screen, and after processing it, call a
is encapsulated in the ABAP runtime environment sequence of general screens. And finally, don’t
and user actions on selection screens trigger the forget that any kind of screens can also be defined in
AT SELECTION-SCREEN events. function pools. For example, by defining selection
screens in function pools, you can completely encap-
Lists are output-oriented screens that display sulate data selections, including the respective user
formatted, structured data. Data in list format can be dialogs.
sent to the R/3 spool system for printing. You define
lists using a special set of statements (WRITE, SKIP, The program in Figure 13 adds a selection
ULINE, and so on). With these statements, a list is screen to the program we just reviewed. This screen
created and buffered on the application server. An is defined as screen number 500 in the global data
internal system program called the “list processor” is declaration part. It has two input fields —

102 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

Figure 13 Adding a Selection Screen to Our Simple ABAP Program

REPORT select_with_selection_screen.
***********************************************************************
* Selection Screen
***********************************************************************
SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW.
PARAMETERS: p_carrid TYPE spfli-carrid VALUE CHECK,
p_connid TYPE spfli-connid VALUE CHECK.
SELECTION-SCREEN END OF SCREEN 500.
***********************************************************************
* Processing blocks
***********************************************************************
START-OF-SELECTION.
PERFORM get_data.
***********************************************************************
FORM get_data.
DATA wa_spfli TYPE spfli.
CALL SELECTION-SCREEN 500 STARTING AT 10 10.
SELECT SINGLE * FROM spfli
INTO wa_spfli
WHERE carrid = p_carrid AND connid = p_connid.
PERFORM output_data USING wa_spfli.
ENDFORM.
***********************************************************************
FORM output_data USING l_spfli TYPE spfli.
WRITE: l_spfli-airpfrom, l_spfli-airpto, l_spfli-fltime.
ENDFORM.
***********************************************************************

p_carrid and p_connid — and is formatted as a In the R/3 system, long-life data is stored in the
dialog window. The type of the input fields refers to tables of one relational database. Each database
types in the ABAP Dictionary. The runtime system system has a programming interface that allows you
provides help and error dialogs for these fields. The to access the database tables using SQL (Structured
screen is called in the subroutine get_data. The Query Language) statements. The ABAP runtime
user can enter single values that are then used in the environment provides a database interface to make
WHERE clause of the data selection. the R/3 system independent of the database system
and differences in the SQL syntax between various
databases. ABAP programs communicate with the
database by means of this interface. The database
ABAP Database Access interface converts all of the database requests from
the R/3 system into the correct Standard SQL state-
Looking back at Figure 4, we see that one topic is still ments for the database system. There are two ways of
missing in our overview — how ABAP programs accessing the database from an ABAP program —
access databases. This is what we will discuss now. with Open SQL or Native SQL statements.

No portion of this publication may be reproduced without written consent. 103


SAP Professional Journal January/February 2000

Open SQL simultaneously creates an equally named data type in


the ABAP Dictionary. This type is structured and its
Open SQL statements, a subset of Standard SQL, are components have the same types and names as the
fully integrated in ABAP. They allow you to access database table’s columns. You can use these types
data irrespective of the database system that the R/3 for creating data objects as work areas for Open SQL
installation is using. Open SQL consists of the Data statements in your ABAP programs.
Manipulation Language (DML) part of Standard
SQL; in other words, it allows you to read (SELECT) You should never confuse the roles of types, data
and change (INSERT, UPDATE, DELETE) data. objects (work areas), and database tables. Note that
in our example programs, the data object wa_spfli
Open SQL goes beyond Standard SQL to provide is declared by referring to the type spfli in the
statements that, in conjunction with other ABAP dictionary while the Open SQL statement SELECT
constructions, can simplify or speed up database accesses the equally named database table spfli
access. It also allows you to buffer certain tables on and reads data into the work area wa_spfli. Need-
the application server, saving excessive database less to say, assigning the work area the same name as
access. the database table can be a source of confusion. In
R/3 releases prior to 4.0, it was necessary to declare
such equally named work areas with the TABLES
Native SQL statement in order to use Open SQL. Now you
can do so without the TABLES statement and this
Native SQL is only loosely integrated into ABAP. statement is obsolete for database accesses.
It allows access to all the functions contained in the
programming interface of the respective database
system, but unlike Open SQL statements, are not
checked and converted. They are sent directly to the
database system. When you use Native SQL, the The SELECT Statement
function of the database-dependent layer is minimal.
Take a look now at Figure 14. In this example
Programs that use Native SQL are specific to the
of ABAP’s Open SQL, the SELECT statement is
database system for which they were written.
divided into a series of simple clauses, each of
When writing R/3 applications, you should avoid
which has a different part to play in selecting,
using Native SQL wherever possible. It is used,
placing, and arranging the data from the database.
however, in some parts of the R/3 Basis system — for
example, for creating or changing database table
definitions in the ABAP Dictionary.

Open SQL contains no statements from


the DDL (Data Definition Language)
The Role of the ABAP Dictionary part of Standard SQL, because normal
Open SQL contains no statements from the DDL application programs should not create
(Data Definition Language) part of Standard SQL, or change their own database tables.
because normal application programs should not Instead, the ABAP Dictionary tool of the
create or change their own database tables. Instead, ABAP Workbench uses DDL internally,
the ABAP Dictionary tool of the ABAP Workbench allowing you to create and administer
uses DDL internally, allowing you to create and database tables. Open SQL statements
administer database tables. Open SQL statements can only access tables that are created
can only access tables that are created by the ABAP by the ABAP Dictionary tool.
Dictionary tool. For each database table, the tool

104 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

Figure 14 Functions of the SELECT Statement

The SELECT clause defines the structure of the The WHERE clause specifies which lines are to
data you want to read — i.e., defining whether you be read by specifying conditions for the selection.
want to read one line or several, which columns you The GROUP BY clause produces a single line of
want to read, and whether identical entries are accept- results from groups of several lines. The HAVING
able or not. The INTO clause determines the ABAP clause sets logical conditions for the lines combined
fields into which the selected data is to be read. using GROUP BY. The ORDER BY clause defines
The FROM clause specifies the database table or a sequence for the lines resulting from the
tables from which the data is to be selected. selection.

No portion of this publication may be reproduced without written consent. 105


SAP Professional Journal January/February 2000

Figure 15 A SELECT Statement Example

SELECT p~carrid p~connid f~fldate b~bookid


INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( spfli AS p
INNER JOIN sflight AS f ON p~carrid = f~carrid AND
p~connid = f~connid )
INNER JOIN sbook AS b ON b~carrid = f~carrid AND
b~connid = f~connid AND
b~fldate = f~fldate )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' AND
f~seatsmax > f~seatsocc
ORDER BY p~carrid p~connid.

Figure 15 shows a SELECT statement and the ABAP Objects is a nearly 100 percent upward-
usage of some of its clauses. Note that this code compatible extension to the ABAP language that
listing consists of a single ABAP statement. The includes a full set of object-oriented (OO) features.
FROM clause assigns alias names to the database The extension consists of a set of new statements
tables spfli, sflight, and sbook, and links the that define classes or interfaces, and which handle
columns carrid, connid, fldate, and bookid objects. These statements can be used in any
of these tables as an inner join. With the INTO kind of ABAP program.
clause, a list of booking numbers for all flights from
Frankfurt to New York that are not fully booked are The basis for ABAP Objects is classes. Classes
written into an internal ABAP table itab. are coding sequences that define the components of
objects. Possible components are attributes (data),
When you program database accesses with the methods (functions), and events. Interfaces allow you
SELECT statement, you should always keep an eye to decouple the declaration of public components
on performance. The performance of an ABAP pro- from the class definition. Classes and interfaces can
gram is largely determined by the efficiency of its either be defined locally in an application program, or
database accesses. It is therefore worth analyzing globally in the class library using the Class Builder
your SQL statements closely. To help you do this, tool of the ABAP Workbench. Similar to the function
you can use the Performance Trace and Runtime library, the class library is part of the R/3 repository.
Analysis tools of the ABAP Workbench.
Objects are instances of classes and are accessed
only via reference variables. Object reference vari-
ables contain references (pointers) to objects and
must be declared before creating an object. There is
ABAP Objects almost no difference between creating objects based
on global classes and creating them on local classes.
In the final section of this article, we’ll take a brief Instances (objects) can be created with the CREATE
look at ABAP Objects and how this object-oriented OBJECT statement only from classes, not from inter-
concept fits in with the classical concepts we have faces. Nevertheless, object reference variables can
been discussing. refer either to classes or to interfaces.

106 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

The important concept of polymorphism, mean- use to code any other processing block. Nevertheless,
ing that you can point with one type of reference the syntax is stricter in some places inside ABAP
variable to objects of different classes, is provided by Objects in order to purge some obsolete features from
the concepts of single inheritance and interfaces. the language. For example, in classes you cannot use
Class reference variables that are typed with reference header lines for internal tables, or the TABLES
to a superclass can point to objects of all subclasses, statement.
and interface reference variables can point to objects
of all classes that implement the respective interface. If you have some experience in ABAP program-
ming, you can learn the concept and syntax of ABAP
ABAP Objects fits smoothly into the concepts Objects in a few hours. With that knowledge you
of ABAP as discussed in this article. As you have are able to use methods that are provided in public
already seen in the preceding section, classes are classes as you have used function modules before.
handled syntactically as processing blocks, and meth- For example, since Release 4.6, the ability to display
ods are procedures that are very similar to function GUI controls for pictures, trees, text editors, etc., on
modules. ABAP programs with classes and methods screens is encapsulated in the public classes of the so-
are embedded in the ABAP runtime system just as called Control Frame Work (CFW). By using these
any other ABAP program. classes in existing ABAP programs, you can strongly
improve the layout and usability of your applications.
You can instantiate and handle objects during the
execution of all classical ABAP programs. But with The program in Figure 16 gives you a sense for
ABAP Objects, there will also be another kind of the syntax that characterizes ABAP Objects. The
program execution that decouples object-oriented function of the program is the same as the function of
programming from the runtime event-oriented pro- the program shown back in Figure 10. Here, how-
gramming to a great extent. From Release 4.6C on, ever, we use ABAP Objects within the framework of
you will be able to create transaction codes that are an executable program. After starting the program, a
directly linked to methods of either global or local static method start of a class main is called during
classes. When you call such a transaction, the system the START-OF-SELECTION event. There, an
loads the program where the class is defined into the object of class flight is created and its methods
memory, automatically creates an instance of that are called. You can type the program in the ABAP
class, and then executes the method. Editor and execute it in R/3 Release 4.5 or higher.
ABAP Objects is fully integrated in the ABAP
The procedural statements that you use to code Debugger, and you might debug the program
the functionality of methods are the same ones you to learn more. You may want to try replacing the

Figure 16 Sample Program with Classes and Objects

REPORT select_and_write_with_objects.
***********************************************************************
* Processing blocks
***********************************************************************
CLASS flight DEFINITION.
PUBLIC SECTION.
METHODS: get,
output IMPORTING l_spfli TYPE spfli.
PRIVATE SECTION.

(continued on next page)

No portion of this publication may be reproduced without written consent. 107


SAP Professional Journal January/February 2000

Figure 16 (continued)

DATA wa_spfli TYPE spfli.


ENDCLASS.
CLASS flight IMPLEMENTATION.
METHOD get.
SELECT SINGLE * FROM spfli
INTO wa_spfli
WHERE carrid = 'UA' AND connid = '0941'.
CALL METHOD me->output EXPORTING l_spfli = wa_spfli.
ENDMETHOD.
METHOD output.
WRITE: l_spfli-airpfrom, l_spfli-airpto, l_spfli-fltime.
ENDMETHOD.
ENDCLASS.
***********************************************************************
CLASS main DEFINITION.
PUBLIC SECTION.
CLASS-METHODS start.
ENDCLASS.
CLASS main IMPLEMENTATION.
METHOD start.
DATA flight TYPE REF TO flight.
CREATE OBJECT flight.
CALL METHOD flight->get.
ENDMETHOD.
ENDCLASS.
***********************************************************************
START-OF-SELECTION.
CALL METHOD main=>start.
***********************************************************************

definition of the classical list with the WRITE Let me end this brief ABAP Objects
statement by using methods of the global class discussion with a note of caution. Knowing
CL_GUI_ALV_GRID instead. This class is an how to use an object-oriented language is not the
example of classes in the Control Frame Work. It same as knowing how to develop a complete
serves as an ABAP List Viewer. In future releases, object-oriented application. Object-oriented
we plan to implement many standard components development has logical advantages that are
(e.g., logical databases in such classes). independent of the concrete implementation. The
most important (and most time-consuming) part of
With the new SAP initiatives EnjoySAP and developing a real object-oriented application is the
mySAP.com, you can take full advantage of ABAP object-oriented modeling. Object-oriented languages
Objects by programming or using standardized inter- such as ABAP Objects simply provide the coding
faces for the new presentation layers that will be support for the implementation of an object-oriented
supported then. model.

108 www.SAPpro.com ©2000 Wellesley Information Services. All rights reserved.


ABAP Programming — An Integrated Overview

Conclusion And last, but not least, programming with ABAP


Objects is just more fun!

Following a simple example, we took you on a tour


from the ABAP runtime environment, over program
structure and program execution, to data types and Horst Keller studied and received his doctorate in
objects. You learned the principles of screen han- physics at the Darmstadt University of Technol-
dling and database accesses. Finally, we gave you a ogy, Germany. After doing research in several
short introduction to ABAP Objects, the basis of the
international laboratories, he joined SAP in 1995,
new ABAP programming model, which in coming
releases will have at least the same importance where he worked in the ABAP Workbench Support
as the classical programming model. Group for three years. During that time, he
authored the books on ABAP programming in the
Much of ABAP’s strength comes from the fact printed ABAP Workbench Documentation Set for
that you can program small applications in a complex R/3 Release 3.0. With R/3 Release 4.0, he started
client/server environment with a few simple state- to reorganize the ABAP online documentation
ments. The background information in this article in order to realize an integrated view of the
will be helpful for you if you want to program more
programming environment.
complex applications or try to understand existing
programs.
Horst is now a member of the ABAP language
Let us pick up the example of local/global data group, where he is responsible for information
another time. When you find data or type declara- rollout. He is documenting the ABAP language
tions in an event block or a module pool, you know with an emphasis on ABAP Objects. He
now that these declarations are not local, but global. also develops and teaches classes on ABAP
Avoid such mistakes when you program yourself.
programming, and is writing productive programs
Use procedures to create encapsulated local data.
For this purpose, we recommend using local classes that display the ABAP documentation and the
and their methods instead of subroutines. Even when corresponding examples in the R/3 Basis system.
implementing only internal modularizations, you will Horst can be reached at horst.keller@sap.com.
profit from a cleaner and safer programming style
that is enforced by the improved syntax rules and type
checks of ABAP Objects.

Home
No portion of this publication may be reproduced without written consent. 109

You might also like