ABAP Programming - An Integrated Overview: Horst Keller
ABAP Programming - An Integrated Overview: Horst Keller
Home
ABAP Programming —
An Integrated Overview
Horst Keller
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.
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.
• 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.
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.
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.
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.
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
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
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.
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-
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.
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.
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,
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.
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.
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.
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.
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.
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.
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.
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.
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
REPORT select_and_write_with_objects.
***********************************************************************
* Processing blocks
***********************************************************************
CLASS flight DEFINITION.
PUBLIC SECTION.
METHODS: get,
output IMPORTING l_spfli TYPE spfli.
PRIVATE SECTION.
Figure 16 (continued)
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.
Home
No portion of this publication may be reproduced without written consent. 109