Table Of ContentBen Meijs, Albert Krouwels,
Wouter Heuvelmans, Ron Sommen
Enhancing the Quality of
ABAP® Development
Contents
Preface 11
1 Introduction 13
1.1 The Technical Quality of ABAP Software .................................................... 16
1.1.1 Aspects of Technical Quality .......................................................... 17
1.1.2 Standards and Guidelines .............................................................. 19
1.2 ABAP Objects and Unicode-Enabling ........................................................ 19
1.2.1 ABAP Objects ............................................................................... 20
1.2.2 Unicode-Enabling ......................................................................... 30
1.3 The Structure of This Book ......................................................................... 32
2 Quality of the Development Organization 37
2.1 Introduction ............................................................................................... 37
2.1.1 What You Need to Organize to Facilitate ABAPDevelopments ..... 37
2.1.2 Factors That Complicate the Organization of Developments .......... 38
2.2 The Impact of Using ERP Functionality ...................................................... 39
2.2.1 Testing the Quality in a Complex Environment .............................. 40
2.2.2 Documenting ABAP Developments ............................................... 42
2.3 The Impact of a Multi-System SAP Landscape ........................................... 52
2.3.1 Basics of a Multi-System Landscape ............................................... 52
2.3.2 Basic Variants of an SAP System Landscape ................................... 56
2.3.3 Pitfalls of Monitoring Transports ................................................... 62
2.4 The Impact of a Multi-Application Landscape ........................................... 65
2.4.1 Requirements ................................................................................ 66
2.5 The Impact of Several SAP R/3 Production Systems .................................. 67
2.5.1 Drawbacks of a Roll-Out Scenario ................................................. 68
2.5.2 Recommendations ........................................................................ 69
2.6 Summary .................................................................................................... 71
Contents 5
3 Correctness 73
3.1 Typical Correctness Categories .................................................................. 73
3.2 Selecting Data ............................................................................................ 74
3.2.1 Selecting One Unique Row ........................................................... 74
3.2.2 Complex WHERE Conditions ........................................................ 77
3.2.3 Validity of Selected Data .............................................................. 78
3.2.4 Selections Based on Database Views ............................................. 82
3.2.5 Authorizations .............................................................................. 89
3.3 Processing Data ......................................................................................... 91
3.3.1 Processing Quantities and Amounts .............................................. 91
3.3.2 Rounding Problems ...................................................................... 94
3.3.3 Misunderstandings About Control Statements ............................... 98
3.3.4 Misunderstandings About Interactive Reporting ............................ 105
3.4 Managing Data in Memory ........................................................................ 109
3.4.1 Availability of Data Within One Program ....................................... 109
3.4.2 Availability When Calling an External Subroutine .......................... 112
3.4.3 Shared Availability of Data (TABLES) ............................................. 113
3.4.4 Availability of Data in Module Pools .............................................. 116
3.4.5 Availability of Data Using Function Modules ................................ 120
3.4.6 Parameter IDs ............................................................................... 123
3.4.7 Why ABAP Objects Will Improve Management of Data ................. 124
3.5 Inconsistencies in Database Updates ........................................................ 128
3.5.1 Avoiding Simultaneous Database Updates ..................................... 128
3.5.2 Keeping Updates of Several Tables Consistent ............................... 136
3.6 Checking the Unicity of Interface Data ...................................................... 140
3.6.1 An Example of Incorrect Data Exchange ........................................ 140
3.6.2 Quality Levels for Exchanging Data ............................................... 140
3.6.3 Implementing Data Exchange Scenarios ........................................ 142
4 Stability 145
4.1 Stability Problems ...................................................................................... 145
4.2 Programming Errors That Promote Instability ............................................ 147
4.2.1 Field Types .................................................................................... 147
4.2.2 Endless Loops ............................................................................... 159
4.3 Risks of Dynamic Programming ................................................................. 165
4.3.1 Dynamic Data ............................................................................... 166
4.3.2 Dynamic Calls ............................................................................... 180
4.4 Changes in an ABAP Program’s Environment ............................................ 189
4.4.1 User Authorizations ....................................................................... 189
4.4.2 Native OS commands ................................................................... 190
4.4.3 Filenames ..................................................................................... 191
4.4.4 Code-Page Use ............................................................................. 193
4.4.5 Client Applications ........................................................................ 194
6 Contents
4.5 Using an ABAP Program Incorrectly ........................................................... 195
4.5.1 Restrictions of Dialog Processing ................................................... 196
4.5.2 Restrictions for the Distribution of Tasks ....................................... 205
4.5.3 Restrictions of Batch Data Communication .................................... 209
4.5.4 Questions to Ask in Order to Avoid Wrong Program Use .............. 217
5 Exceptions and Error Handling 219
5.1 The Importance of Exception Handling ...................................................... 219
5.2 Implementation of Exception Handling ..................................................... 221
5.2.1 Generating and Intercepting an Exception Signal ........................... 222
5.2.2 Implementing the Actual Exception Handling ................................ 226
5.3 Class-Based Exception Handling ................................................................ 231
5.3.1 Basic Implementation .................................................................... 231
5.3.2 Exception Classes .......................................................................... 232
5.3.3 Details of Class-Based Exception Handling .................................... 233
5.3.4 Making Existing Exception Handling Class-Based ........................... 240
5.3.5 Creating Your Own Exception Classes ........................................... 241
5.4 Conclusions ............................................................................................... 243
6 User-Friendliness 245
6.1 The Importance of Standardization ............................................................ 245
6.2 Guidelines for The Look-and-Feel and Behavior of Your Programs ............ 247
6.2.1 Things to Be Standardized in The Look-and-Feel of an
ABAP Application .......................................................................... 247
6.2.2 Things to Be Standardized in The Behavior of an ABAP Application 254
6.3 Guidelines for Navigation and Support ...................................................... 260
6.3.1 Assisting Users During Screen Input .............................................. 260
6.3.2 Limiting Unnecessary Screen Navigation ........................................ 261
6.3.3 Avoiding Unnecessary Repetitions of Input ................................... 263
6.3.4 Avoiding Unnecessary Messages .................................................... 264
6.4 Conclusion ................................................................................................. 265
7 Performance 267
7.1 Introduction ............................................................................................... 267
7.2 Optimizing Processing on the Database Server: Using Indexes ................. 269
7.2.1 Primary and Secondary Indexes ..................................................... 270
7.2.2 What You Can Do to Prevent the Creation of Extra Indexes .......... 273
Contents 7
7.3 Minimizing Data Traffic Between the Database Server and
the Application Server ............................................................................... 293
7.3.1 Limiting the Number of Rows Selected ......................................... 295
7.3.2 Limiting the Number of Fields Selected ......................................... 300
7.3.3 Limiting the Number of Times That Data Is Selected ..................... 302
7.4 Optimizing Processing on the Application Server ...................................... 308
7.4.1 Performance Issues Related to Internal Table Processing ................ 309
7.4.2 Basics of Internal Table Types ........................................................ 310
7.4.3 How to Use Internal Tables ........................................................... 311
7.4.4 When to Choose Which Internal Table Type ................................. 319
7.4.5 Semi-Persistent Memory .............................................................. 321
7.4.6 Parallel Processing ......................................................................... 324
7.5 Minimizing Data Traffic Between the Application Server and a Client ...... 327
7.5.1 Uploads and Downloads ............................................................... 327
7.5.2 Control Flushing ........................................................................... 328
7.6 Summary .................................................................................................... 329
8 Maintainability 331
8.1 Maintainability of Standard SAP Software ................................................. 332
8.1.1 OSS Notes .................................................................................... 332
8.1.2 Changes Made by the Customer ................................................... 333
8.2 Maintainability of Customized ABAP Software .......................................... 336
8.2.1 Separating Different Actions .......................................................... 336
8.2.2 Improving Recognizability ............................................................. 337
8.2.3 Reusing Standard SAP Software ..................................................... 344
8.2.4 Practical Tips ................................................................................. 359
8.3 Enhancing Maintainability with ABAP Objects .......................................... 365
8.3.1 Using Subclasses ........................................................................... 365
8.3.2 Using Interfaces ............................................................................ 372
8.4 Summary .................................................................................................... 377
9 Checking Robustness and Troubleshooting 379
9.1 Changes and New Developments .............................................................. 379
9.1.1 General Guidelines for Testing ...................................................... 380
9.1.2 Colleague Checks .......................................................................... 385
9.1.3 Checklists for Testing Robustness .................................................. 390
9.1.4 Tools for Testing and Quality Checks ............................................. 402
9.2 Troubleshooting Incidents ......................................................................... 439
9.2.1 Basic Incident Analysis .................................................................. 439
9.2.2 Correctness Incidents .................................................................... 443
9.2.3 Stability Incidents .......................................................................... 446
9.2.4 Performance Problems ................................................................. 449
9.3 Summary .................................................................................................... 455
8 Contents
A A Proposal for Naming Standards 457
A.1 Program Internal Data ............................................................................... 457
A.2 Formal Interface Parameters ...................................................................... 458
A.3 ABAP Dictionary Objects ........................................................................... 459
A.4 ABAP Workbench Objects ......................................................................... 459
B Example of an Exception Handling Class 461
C Template for an ALV Report 473
D Bibliography 493
On Performance ......................................................................................... 493
On Unicode-Enabling ................................................................................. 494
On Stability and Correctness ....................................................................... 494
Other Subjects ............................................................................................ 494
Other References ........................................................................................ 495
Author Portraits 497
Index 499
Contents 9
5 Exceptions and Error Handling
One of the best ways to make a program behave more predictably, and thereby,
enhance a program’s technical quality, is by implementing proper exception han-
dling. Simply put, good exception handling will result in fewer errors. And,
because one of the goals of exception handling is to make it easier for the user to
respond to any outstanding errors, it will have a positive effect on user accep-
tance as well.
We broadly define an exception to mean “any deviation from the normal program
flow.”1 Consider, for example, an implicitly generated returncode not equal to
zero that is returned by a SELECT statement, or an unexpected value of a variable
that is used in an IF condition. You should note that an exception is not the same
thing as a coding error. An exception is an unanticipated situation or event encoun-
tered during the execution of program logic.
Exception handling is the way in which deviations are detected, caught, and han-
dled. Dealing with exceptions is directly related to the two previously discussed
main topics—correctness and stability—because both of these software require-
ments are directly affected by the following results of sloppy exception handling:
runtime errors (program dumps), obscure error messages, incorrect data on lists
or screens, and even inconsistent database tables. To a certain extent, you could
view adding elegant exception handling as adding the finishing touch to a pro-
gram in order to support its correctness and stability. You could even argue that
exception handling is actually integral to ensuring technical quality.
5.1 The Importance of Exception Handling
It’s hard to predict and anticipate all the possible circumstances in which a pro-
gram will be used. Which exceptions are actually considered often depends
directly on the context in which a program is used. It’s quite difficult to predict all
the exceptional situations that may arise. To a certain extent, a program’s context
will be clear, and so will the logic that is applied and the data that is processed.
However, there’s always a point at which the developer’s (and other people’s)
knowledge about the context ends, and particular exceptions need to be taken
into account. Ignoring these types of situations is not an option. Therefore, usu-
ally, a developer must deal with the typical details of programming techniques in
general and the ABAP programming language in particular. And most often, these
details aren’t explicitly included; for example, in the functional specifications for a
new program.
1 Note that an exception is defined more strictly in the second volume of Horst Keller, Joachim
Jacobitz, ABAP Objects: The Official Reference, SAP PRESS 2003.
Exceptions and Error Handling 219
On the other hand, even without knowing the context in which a program is
used, it’s not really that difficult to address each imaginable deviation from the
normal program flow. All that is required is a proper and unbiased look at the pro-
gram code (which makes exception handling an excellent topic to be checked
during a peer review (see Section 9.1). Moreover, the ABAP language provides all
the necessary means to conduct this kind of check—to raise exceptions, intercept
them, and take the appropriate action when necessary, in current releases and
those prior to Web AS 6.20.
And yet, it’s well known that exception handling in most customized ABAP devel-
opments is incomplete. We can think of various reasons for this:
1. Because the programmer doesn’t know how to implement exception hand-
ling.
Imagine, for example, that a piece of program code deep down the Call Stack
of a program causes an error: a subroutine calls a function module; this function
module, in turn, calls another function module; and this last function module
generates an exception. The question then is: Where should the exception be
handled? If it’s better to wait to give an error message until the main line of the
program is reached again, all the context information about the error must also
be returned through the Call Stack.
2. Because the assumptions of initial development aren’t expected to become
invalid.
Customized developments are often made to rely on assumptions that, accord-
ing to the developer, make additional exception handling superfluous. As such,
this may be true. However, this ignores the fact that maintenance may have to
be applied later. At the time of initial development, the assumptions that are
made usually cannot be questioned (“This simply can’t go wrong. We have only
two material types.”). However, this will make the program more fragile. Unfor-
tunately, this usually doesn’t become obvious until a small change is imple-
mented (for example, related to the introduction of a new material type). Par-
ticularly if the change itself comprises only a few lines of code, no one will
consider it justifiable to reinvestigate all the assumptions made during the ini-
tial development—this would take much more time than applying the actual
change. Nevertheless, even a small change can introduce exceptions that didn’t
exist. Therefore, it isn’t that the assumptions are invalid when they’re first
made; the problem is that they can become invalid once the program is
changed.
3. Because it takes too much time.
Like testing and documenting developments, implementing exception hand-
ling is hardly the most exciting of all development activities; however, it can
220 Exceptions and Error Handling
require a large amount of the total development time of a program. And, if
there are many exceptions to consider, it’s easy to predict the following all too
common scenario: every exception that doesn’t appear to be essential or criti-
cal, or whose exception handling seems difficult to implement, will be ignored.
For programmers, who may look for ways to avoid this activity and get away
with it, skipping exception handling is a way to deliver a program according to
plan and budget.
In this chapter, we’ll address these basic dilemmas. We’ll discuss which excep-
tions can be used. We’ll explain the types of exception handling that are less fre-
quently applied but that can nevertheless be useful for customized ABAP pro-
grams. And finally, we’ll show you how to avoid the Call Stack dilemma by using
the so-called class-based exception handling (that is, exception handling using
ABAP Objects).
In Section 5.2, we’ll first provide you with an overview of the basics of exception
handling in an ABAP environment. Next, in Section 5.3, we’ll present the main
characteristics of class-based exception handling, and show you how to combine
class-based with existing exception handling. In Section 5.4, we summarize the
most important conclusions.
5.2 Implementation of Exception Handling
Exception handling distinguishes among three different elements (see Figure 5.1):
(cid:1) Generating or raising the exception event
(cid:1) Noticing or intercepting the exception
(cid:1) Acting on the exception
Figure 5.1 Raise—Intercept—Act
The first step in exception handling is raising the exception, that is, giving a signal
that something has gone wrong. On the one hand, there are implicit exceptions;
for example, a returncode that is not equal to zero when using an ABAP com-
mand such as SELECT, or a runtime exception such as divide-by-zero. On the
Implementation of Exception Handling 221
other hand, explicit exceptions are the ones caused deliberately by the program
logic itself; for example, by setting a specific flag, or by using the RAISE EXCEP-
TION TYPE <exception class> command.
Independently of how an exception is raised, it must then be explicitly recognized
(or detected, caught, intercepted) by the program code before anything can be
done with it. Lastly, of course, the appropriate action must be taken. For example,
consider sending a message to the end user. To summarize these steps, think of
them as Raise, Intercept, and Act.
This section discusses the standard possibilities for implementing exception han-
dling in an ABAP environment. In Section 5.2.1, we’ll review the available options
for generating and intercepting the exception signal. Next, in Section 5.2.2, we’ll
discuss the most important ways of implementing the exception handling.
5.2.1 Generating and Intercepting an Exception Signal
In this section, we’ll give you an overview of how to intercept the following types
of exceptions: a returncode; unexpected data in IF and CASE statements; an
interface parameter of a subroutine; an exception generated by a function mod-
ule; a class-based exception; and a runtime error. For the explicit types of excep-
tions, we’ll also show you how each of them is generated.
Returncode
The first exception signal that each ABAP developer is likely to think of is a return-
code that is not equal to zero (sy-subrc <> 0). The system field sy-subrc is used
by many ABAP commands to indicate whether the execution of the command has
been successful: all SQL commands; internal table commands such as READ and
LOOP AT <itab>; and file-handling commands such as OPEN DATASET. However,
even if programmers know this, they often don’t explicitly check the returned
value, especially if they expect that nothing will go wrong.
Note that not every returncode indicates an exception. In most situations, such as
when reading database tables or internal tables, a returncode not equal to zero
represents an exception, even if the result is not immediately disastrous. But,
sometimes, a returncode is checked as part of the program logic. To see the dif-
ference, consider the following two pieces of ABAP code. The first piece of code
is an example of the use of a returncode that represents a genuine exception:
OPEN DATASET tp_filename FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
* Exception Handling here--
ENDIF.
222 Exceptions and Error Handling
Description:1 Note that an exception is defined more strictly in the second volume of Horst Keller, Joachim. Jacobitz, ABAP Objects: The Official Reference, SAP PRESS