You are on page 1of 54

152.book Seite 3 Donnerstag, 11.

Oktober 2007 7:18 19

Karl-Heinz Khnhauser

Discover ABAP

Bonn Boston
152.book Seite 5 Donnerstag, 11. Oktober 2007 7:18 19

Contents at a Glance

Preface ..................................................................... 15

1 ABAP and Getting Started with the SAP System ....... 21

2 Data Dictionary ........................................................ 43

3 Programming in the ABAP Editor ............................. 69

4 Fields and Calculations ............................................. 97

5 Modifying Character Strings ..................................... 121

6 Debugging Programs ................................................ 139

7 Modifying Transparent Database Tables ................... 159

8 Calculating Dates, Times, Quantities,


and Currencies ......................................................... 199

9 Modifying Data in a Database Table ......................... 231

10 Program Flow Control and Logical Expressions ......... 261

11 Selection Screens ..................................................... 311

12 Internal Tables ......................................................... 369

13 Modularizing Programs ............................................ 429


152.book Seite 7 Donnerstag, 11. Oktober 2007 7:18 19

Contents

Preface ........................................................................... 15
Who This Book Is For .................................................................. 15
What Youll Discover ................................................................... 16
Navigational Tools for This Book ................................................. 16
System Requirements .................................................................. 16
Whats In This Book? ................................................................... 17
Code Samples for Download ....................................................... 19
Acknowledgments ....................................................................... 19

1 ABAP and Getting Started with the SAP System .... 21


Overview of the Architecture of an SAP System ........................... 22
Technical Architecture .......................................................... 23
Business Organization Architecture ....................................... 24
Platform-Independence ......................................................... 27
Application Programs and Runtime Environment ......................... 28
Work Processes ..................................................................... 29
Structure of ABAP Programs .................................................. 31
Logging On and Off the System ................................................... 33
Overview of Business Modules .............................................. 35
ABAP Workbench ................................................................. 37

2 Data Dictionary ........................................................ 43


Getting Started with the ABAP Dictionary ................................... 44
Database Tables .................................................................... 44
Creating and Maintaining Tables ........................................... 46
Data Elements and Domains ........................................................ 50
Creating a Data Element ....................................................... 50
Creating Domains ................................................................. 55
Checking and Activating a Data Element ............................... 60
Maintaining the Technical Settings of the Table .................... 62
Creating Data Records ................................................................. 64
Entering Data Records ........................................................... 65
Displaying the Contents of the Table ..................................... 66

7
152.book Seite 8 Donnerstag, 11. Oktober 2007 7:18 19

Contents

3 Programming in the ABAP Editor ............................ 69


Creating an ABAP Report ............................................................ 69
ABAP Editor: Overview ............................................................... 73
Modes of the ABAP Editor ................................................... 74
Controlling the ABAP Editor ................................................. 75
Understanding and Editing ABAP Programs ................................ 81
Executing an ABAP Report .......................................................... 83
Reading and Outputting Database Tables ................................... 85
Formatting Lists .......................................................................... 86
Chain Statement ................................................................... 87
Lines .................................................................................... 87
Blank Lines ........................................................................... 87
Writing and Editing Source Code ................................................ 88
Notes on the Source Code .................................................... 89
List Screen from Our Sample Source Code ............................ 94

4 Fields and Calculations ............................................ 97


Preparing the Report .................................................................. 98
Declaring Fields .......................................................................... 102
Declaring Variables ............................................................... 103
Declaring Constants .............................................................. 107
Basic Arithmetic Operations ....................................................... 108
Compatible and Convertible Data Objects ............................ 110
Conversion Rules .................................................................. 111
Special Features of Division Operations ................................ 113
Sample Code for Fields and Calculations ..................................... 114
Notes on the Source Code .................................................... 115
Improved List Format ........................................................... 118

5 Modifying Character Strings .................................... 121


Declaring Character Strings ......................................................... 122
String Operations ........................................................................ 124
Shifting Character Strings ...................................................... 124
Replacing Character Strings .................................................. 126
Condensing Character Strings ............................................... 127
Concatenating String Fields .................................................. 128

8
152.book Seite 9 Donnerstag, 11. Oktober 2007 7:18 19

Contents

Splitting Character Strings ..................................................... 130


String Operations with Direct Positioning .............................. 130
Sample Code for String Operations .............................................. 132
Notes on the Source Code .................................................... 134
Outputting the Source Code ................................................. 137

6 Debugging Programs ................................................ 139


Overview ..................................................................................... 140
Calling the ABAP Debugger ......................................................... 140
Working with the ABAP Debugger .............................................. 144
Fields Mode .......................................................................... 144
Table Mode .......................................................................... 148
Watchpoints Mode ............................................................... 150
Breakpoints Mode ................................................................. 154
Static Breakpoints ................................................................. 157

7 Modifying Transparent Database Tables ................. 159


Do you remember the transparent database table from
Chapter 2? ................................................................................... 159
Copying a Database Table ........................................................... 161
Enhancing Non-Key Fields ........................................................... 165
Maintaining Fixed Values in Domains .................................... 166
Special Points for Currency and Quantity Fields ..................... 169
Maintaining Foreign Keys ...................................................... 171
Maintaining Append Structures ............................................. 179
Maintaining an Include Structure .......................................... 183
Manipulating Key Fields of Tables ............................................... 188
Deleting Table Fields ................................................................... 192
Deleting Tables ........................................................................... 194

8 Calculating Dates, Times, Quantities, and


Currencies ................................................................. 199
Field Definitions .......................................................................... 199
Using Date Fields in Arithmetic Operations ................................. 202
Using Time Fields in Arithmetic Operations ................................. 209
Using Quantity and Currency Fields in Arithmetic Operations ...... 214
Sample Code for Date, Time, and Currency Fields ........................ 217

9
152.book Seite 10 Donnerstag, 11. Oktober 2007 7:18 19

Contents

Notes on the Source Code .................................................... 221


Outputting the Source Code ................................................. 228

9 Modifying Data in a Database Table ....................... 231


Authorization Concept ................................................................ 232
Lock Concept .............................................................................. 234
Open SQL Statements ................................................................. 237
Creating a New Data Record ................................................ 238
Modifying an Existing Data Record ....................................... 241
Modifying a Data Record ...................................................... 242
Deleting a Data Record ........................................................ 243
Sample Code for INSERT ............................................................. 245
Notes on the Source Code .................................................... 247
Outputting the Source Code ................................................. 248
Sample Code for UPDATE ........................................................... 249
Notes on the Source Code .................................................... 251
Outputting the Source Code ................................................. 252
Sample Code for MODIFY .......................................................... 252
Notes on the Source Code .................................................... 254
Outputting the Source Code ................................................. 255
Sample Code for DELETE ............................................................ 256
Notes on the Source Code .................................................... 258
Outputting the Source Code ................................................. 259

10 Program Flow Control and Logical Expressions ...... 261


Control Structures ....................................................................... 262
Using Patterns ............................................................................ 263
Branches ..................................................................................... 266
IF Structure .......................................................................... 267
CASE Structure ..................................................................... 270
Loops ......................................................................................... 272
SELECT Loop ........................................................................ 273
DO Loop .............................................................................. 273
WHILE Loop ......................................................................... 275
Termination Statements for Loops ........................................ 277
Logical Expressions ..................................................................... 281
Simple Logical Expressions ................................................... 281

10
152.book Seite 11 Donnerstag, 11. Oktober 2007 7:18 19

Contents

Linked Logical Expressions .................................................... 284


Sample Code for IF ...................................................................... 288
Notes on the Source Code .................................................... 290
Outputting the Source Code ................................................. 292
Sample Code for CASE ................................................................. 293
Notes on the Source Code .................................................... 295
Outputting the Source Code ................................................. 296
Sample Code for DO and Termination Conditions ........................ 298
Notes on the Source Code .................................................... 300
Outputting the Source Code ................................................. 302
Sample Code for WHILE and Logical Expressions ......................... 303
Notes on the Source Code .................................................... 306
Outputting the Source Code ................................................. 308

11 Selection Screens ..................................................... 311


Events ......................................................................................... 313
Order of Events ..................................................................... 313
Examples of Events ............................................................... 314
Simple Selections ........................................................................ 316
PARAMETERS Statement ...................................................... 317
Additions to the PARAMETERS Statement ............................ 318
Complex Selections ..................................................................... 323
SELECT-OPTIONS Statement ................................................. 324
Multiple Selections ............................................................... 326
Additions to the SELECT-OPTIONS Statement ....................... 328
Using Selection Texts ................................................................... 329
Overview of Text Elements .................................................... 329
Creating Selection Texts ........................................................ 330
Saving the Selection Screen ......................................................... 333
Creating Selection Variants .................................................... 334
Starting a Report with a Variant ............................................ 340
Completing Text Objects ............................................................. 341
Creating Text Symbols ........................................................... 342
Creating Messages ................................................................ 343
Free Layout of the Selection Screen ............................................. 347
Formatting Single Lines ......................................................... 348
Formatting a Line Block ........................................................ 350
Sample Code for Selection Screen (Simple Form) ......................... 351

11
152.book Seite 12 Donnerstag, 11. Oktober 2007 7:18 19

Contents

Notes on the Source Code .................................................... 354


Outputting the Source Code ................................................. 356
Sample Code for Selection Screen (Extended Form) .................... 356
Notes on the Source Code .................................................... 361
Outputting the Source Code ................................................. 365

12 Internal Tables ......................................................... 369


Purpose of Internal Tables .......................................................... 370
Structure and Types of Internal Tables ........................................ 372
Creating an Internal Standard Table ............................................ 375
Traditional Syntax with Header Line ..................................... 375
Object-Oriented Syntax Without Header Line ...................... 377
Filling an Internal Standard Table ................................................ 380
Filling an Internal Table with a Header Line .......................... 380
Filling an Internal Table with a Work Area ............................ 386
Processing an Internal Table Line-by-Line ................................... 390
Processing an Internal Table with a Header Line ................... 390
Processing an Internal Table with a Work Area ..................... 398
Deleting the Contents of Internal Tables ..................................... 400
Deleting an Internal Table with a Header Line ...................... 401
Deleting Work Areas and Internal Tables
with a Work Area ................................................................. 402
Sample Code for ITAB with Header Line ..................................... 403
Notes on the Source Code .................................................... 408
Tracing the Output of the Source Code in the
ABAP Debugger ................................................................... 411
Sample Code for ITAB with Work Area ....................................... 417
Notes on the Source Code .................................................... 422
Tracing the Output of the Source Code in the
ABAP Debugger ................................................................... 425

13 Modularizing Programs ........................................... 429


Overview .................................................................................... 430
Source Code Modules ................................................................. 431
Procedures ................................................................................. 434
Subprograms ........................................................................ 434
Function Modules ................................................................ 449

12
152.book Seite 13 Donnerstag, 11. Oktober 2007 7:18 19

Contents

Memory Areas for Data Transfer .................................................. 465


Global SAP Memory .............................................................. 466
Local SAP Memory ................................................................ 466
ABAP Memory ...................................................................... 467
Sample Code for Modularization ................................................. 468
Notes on the Source Code .................................................... 476
Outputting the Source Code ................................................. 478
Sample Code for Calling an External Report ................................. 478
Notes on the Source Code .................................................... 485
Outputting the Source Code ................................................. 489

Index ........................................................................................... 491

13
152.book Seite 15 Donnerstag, 11. Oktober 2007 7:18 19

Preface

This book is intended as a practical introduction for those of you


who are planning to enter the world of ABAP programming. This
is the primary goal of the book; everything else is secondary.
Therefore, this book intentionally simplifies and oversimplifies
things by reducing technical and business-related issues to a min-
imum. In doing so, it accepts gaps, because it cannot and will not
cover the topic of ABAP to its full extent. Instead, it limits itself to
describing a core topic and moving along a common thread
throughout all the chapters in order to reach the intended target
group programmers with little or no ABAP knowledge, project
team members and developers for SAP introduction projects, etc.
In this way, the book is able to impart a feeling of success to new-
comers to ABAP.

For this reason, this book can neither replace a course in basic SAP
principles nor any advanced literature on specific ABAP-related
subjects. It is not exhaustive in any respect. Furthermore, the book
is not intended to be a "dry run;" instead, it is intended to motivate
you to get to know and use the SAP system. All steps integral to
reaching this goal are comprehensively described on the basis of
examples, background information, and source code listings.

Who This Book Is For


This book is primarily intended for developers who work in
companies that are currently implementing an SAP system. It is
also intended for consultants and project managers who want to
read and understand ABAP source code and to implement changes
by themselves. Lastly, the book has also been written for students
and trainees who are learning ABAP as part of their professional
training.

15
152.book Seite 16 Donnerstag, 11. Oktober 2007 7:18 19

Preface

What Youll Discover


You will be guided from a simple ABAP report through important
table maintenance tasks in the ABAP Dictionary to the modularized
flow control and complex data transfer structure between different
reports. For this purpose, we'll use a business example a ficti-
tious member management system continuously throughout
this book in order to apply the theoretical aspects directly to real-
life scenarios. Thus, the focus of this book lies on describing and
applying ABAP knowledge, not on the business-related context.

Navigational Tools for This Book


Throughout the book, you will find several elements that will help
you access useful information. We have used the following icons to
help you navigate:

Tip: Here youll find useful information as well as special tips


and tricks that can make your work easier.

Note: Notes call out information about related ideas, other


resources to explore, or things you should keep in mind.

Warning: Please watch out! This icon alerts you to common


errors and pitfalls.

Example: Here youll encounter real-life scenarios and exercises.

This is a Additionally, marginal text provides a useful way to scan the book
marginal note to locate topics of interest for you. Each appears to the side of a
paragraph or section with related information.

System Requirements

For optimal use of what is described in this book, we strongly


recommend that you meet some basic requirements. Ideally, you
should have already familiarized yourself with some SAP basics

16
152.book Seite 17 Donnerstag, 11. Oktober 2007 7:18 19

Whats In This Book?

such as navigating through the main menu. Also, experience with


general programming logic from other programming languages,
macros, or scripts would be beneficial to the success of your learn-
ing efforts. In addition, having access to an SAP system, for exam-
ple, an R/3 or ERP system, including the relevant authorizations,
would be advantageous. Here, the mini-SAP system would be suffi-
cient.

Mini-SAP System

The mini-SAP system is included in various SAP PRESS books (http://


www.sap-press.com). Alternatively, you can purchase it at a dis-
counted price from the SAP website (http://www.sap.com). The mini-
SAP system provides the ABAP development environment, which is
all you need when using this book.

Whats In This Book?

Chapter 1 describes the organizational and technical architecture


of SAP systems as well as development prerequisites you need to
be aware of to get started with ABAP. Furthermore, it demonstrates
the division of labor between the runtime environment and appli-
cation programs as well as the structure of ABAP reports.

Chapter 2 provides an overview of the purpose of the ABAP Dictio-


nary. Based on the example of a transparent table, you will learn
how to create a table, how to enter and display table entries, and
what youll need to do regarding data elements, domains, and tech-
nical settings.

In Chapter 3, youll create your first ABAP report, maintain its


properties, create the source code, and execute the report. More-
over, you'll learn about the first ABAP statements and the relevant
syntax.

You'll carry out your "basic arithmetic operations using variables"


in Chapter 4. This chapter will also introduce you to the properties
of data objects and to the difference between compatibility and

17
152.book Seite 18 Donnerstag, 11. Oktober 2007 7:18 19

Preface

convertibility. In addition, it describes some useful tricks you can


use to improve list formats.

In Chapter 5, youll work with character strings and carry out dif-
ferent variants of string operations. Youll learn how to search for
substrings and modify character strings.

Chapter 6 focuses on pursuing the program flow as well as on find-


ing program errors. For this purpose, youll use the ABAP Debug-
ger with its most important modes.

In Chapter 7, youll enhance and modify a transparent table and


you'll learn about foreign keys. In addition, youll implement table
content checks. For this purpose, you will use fixed values in the
domain, value tables, and check tables. Furthermore, youll learn
about the specifics of currency and quantity fields.

In Chapter 8, you will declare date and time fields, process these
fields, and examine their specific features. For a better understand-
ing, this chapter uses many examples, which are described and
traced in the ABAP Debugger.

Chapter 9 describes how you can modify the contents of a database


table, insert new rows into the table via ABAP statements, and
change and delete existing rows. Moreover, the chapter discusses
the risks involved in deleting and manipulating data.

Our sample application is beginning to get more complex: In Chap-


ter 10, youll make some case distinctions, implement control
structures and branches, and learn about logical expressions.

Chapter 11 describes how you can provide a report with input val-
ues for the program flow in a selection screen. You will develop
simple and complex selections and selection texts, and design the
selection screen in accordance with your own requirements. Fur-
thermore, this chapter describes the meaning of text symbols, mes-
sages, and variants in relation to the selection screen.

Chapter 12 describes internal tables including their meaning and


different forms. Youll learn what a header line is and be able to
distinguish the difference between an internal table and a work

18
152.book Seite 19 Donnerstag, 11. Oktober 2007 7:18 19

Acknowledgments

area as well as important statements for processing the table rows.


For a better understanding, this chapter also focuses on tracing the
program flow in the ABAP Debugger.

Chapter 13 describes the modularization of programs. Youll learn


about source code modules, internal and external subprograms as
well as function modules. Another important aspect discussed in
this chapter is the transfer of data and data structures to called
modules.

Code Samples for Download

In order to avoid the time-consuming typing of source code, you


can download the source code of all sample listings from the web-
site that accompanies this book at http://www.sap-press.com.

Acknowledgments

I would like to take this opportunity to thank my wife and children.


They had to manage without me for a long time, and by relieving
me from household work, they made it possible for me to write this
book.

Lastly, I hope that you will enjoy reading this book and I wish all
of you much success in learning ABAP.

Karl-Heinz Khnhauser
Nuremberg

19
152.book Seite 69 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the
ABAP Editor

Everything looks complicated when you first get started, but when
youre done, its usually not half as difficult as you imagined. Small
successes balance out the effort. After working through this chap-
ter, youll be proud of your first list.

This chapter shows you how to use the ABAP editor to create, acti-
vate, and execute your first program. It familiarizes you with ABAP
statements and shows you how to take the first steps in working
with the ABAP editor.

Creating an ABAP Report

You can start the ABAP editor from the SAP menu (Tools ABAP SE38
Workbench Development ABAP Editor) or using Transaction
Code SE38.

You must enter a program name in the initial screen. The name can One name,
be up to 30 characters long and should contain only letters and one program

numbers. Dont use special characters (letters with diacritical

69
152.book Seite 70 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

marks) except for an underscore. Please remember that you must


adhere to the naming convention for customer objects. The pro-
gram name must begin with a "Z," so name your first report
"Z_MEMBERLIST01" and click Create (see Figure 3.1).

Figure 3.1 Creating an ABAP Report

Maintaining pro- In the next screen, you define the attributes the properties of the
gram properties report (see Figure 3.2) and give it a descriptive Title, such as
"First Member List." You must also specify the original language of
the report the language in which it is created "EN" for English
in this case.

Why is this information important?

The information in the original language of the report is important,


because all texts in SAP, whether in menus or screens, are maintained
in a country-specific manner. SAP provides a proprietary translation
tool that you can use to translate the texts from the original language
to the target language, without having to change the source code of
the program. If developers have done their job well, a translator with-
out programming knowledge can translate all the texts.

70
152.book Seite 71 Donnerstag, 11. Oktober 2007 7:18 19

Creating an ABAP Report


3

Figure 3.2 Maintaining Program Properties

The status of our program is still "New (Revised)." That makes


sense, because were still creating it. The status will change to
"Active" later on, and it will then be executable.

For the Type of program, select Executable program. An execut- Program type
able program can be started without a transaction code directly, or
in the background with a batch job. The invisible runtime envi-
ronment controls the report. It calls defined processing blocks in a
fixed sequence and handles the processes of program execution,
such as outputting a list at the end of the report.

As the Status of the program, select Test program from the list and Program status
select Basis for the Application. Both criteria help program
management. They describe the status of program development: if
youre dealing with a finished customer program in production or
a program in the experimental and testing phase. They also
describe the business application area that the program belongs to.

71
152.book Seite 72 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

See Chapter 11 Leave the next three optional fields blank. You can use the Autho-
for more information rization Group to assign the program to a program group and then
on the Selection
screen. set authorization checks for the group, so that only authorized
users can start the report. A Logical database is a higher-level read-
program that makes it easier for you to find and assign data in var-
ious tables. It can ensure that data is processed in the right
sequence and perform other tasks that we cannot discuss in more
detail here.

Additional Select the following settings for the four remaining checkboxes:
attributes
Editor lock
Do not set the Editor lock. You need it only when you want to
prevent another user from changing, renaming, or deleting the
program. In the real world, this precaution can be helpful. Only
the author of the last program change can remove the lock.
Unicode checks active
Check Unicode checks active. As of Release 6.10, ABAP sup-
ports multibyte coding. Earlier releases used only character sets
based on single-byte coding ASCII or EBCDIC codes. In some
circumstances, programs without Unicode checks can trigger
syntax or runtime errors.
Fixed point arithmetic
Activate Fixed point arithmetic. Otherwise, packed numbers
are treated as whole numbers without consideration of decimal
places, and intermediate results are rounded in calculations. In
other words, if youre interested in exact calculations (which is
the case in Chapter 4), you must activate fixed point arithmetic.
Start using variant
Dont select Start using variant. Variants populate the selection
screen with initial values. To ensure that a report is actually
populated with the same initial values every time the report
runs, you can store the selection screen in a variant. If you start
the report with the variant, the selection screen is already popu-
lated, which significantly reduces the risk of errors.

72
152.book Seite 73 Donnerstag, 11. Oktober 2007 7:18 19

ABAP Editor: Overview


3

Tip

The Start using variant option is beneficial in your daily work. In the
real world, these kinds of selection screens can be quite compre-
hensive. But right now, starting the report with only a variant will not
be helpful. In Chapter 11, we will assign initial values to the report
with a selection screen for the first time.

After you save the program, youre instructed to create an object Maintaining an
catalog entry. As we noted in Chapter 2, you should save the object object catalog entry

locally.

ABAP Editor: Overview

That automatically (and finally) takes you to the ABAP editor (see Frontend and
Figure 3.3), which has two basic modes: frontend mode and backend backend mode

mode.

Figure 3.3 ABAP Editors in Change Mode

73
152.book Seite 74 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

Modes of the ABAP Editor


The frontend mode loads the ABAP source code onto the client,
where it is processed locally. In backend mode, the source code is
not loaded locally. It remains on the server. Saving a change in the
source code transmits the change to the server.

Both modes offer the same layout of the source code and are appro-
priate for editing ABAP source code. The difference between the
two modes lies in their operation and functional scope:

Operation and Frontend mode


functional scope In frontend mode, local editing quickly executes all editing func-
tions without communication with the server. The context
menus are user-friendly, and functions like cut, copy and paste,
and drag-and-drop will probably remind you more of a word
processing program than a program editor. But communication
between the frontend and the backend when large quantities of
data are involved can have quite a negative affect on perfor-
mance. Frontend mode also assumes specific operating systems
on the client.
Backend mode
The traditional backend mode works to accomplish a goal. It pro-
cesses several rows as a block of rows during cut and paste and
requires highlighting the block with several clicks (see Table 3.2
in this chapter). We recommend using various intermediate
buffers so that you can use several clipboards at one time.

Why backend mode?

Although novices probably find that it takes longer to get used to and
is not immediately comfortable, the backend mode has two advan-
tages. It offers better performance with large quantities of data and it
can process all the development objects that the ABAP editor needs.
Limitations still exist in frontend mode. Backend mode also doesnt
limit the choice of local operating systems on the presentation server.
Thats why we will always use backend mode in the following. Of
course, you can use frontend mode if it better meets your personal
style of working.

74
152.book Seite 75 Donnerstag, 11. Oktober 2007 7:18 19

ABAP Editor: Overview


3

The ABAP editor always starts in the last mode in which it was Switching between
operated. If you want to switch from one mode to another, use the editor modes

Utilities Settings menu to navigate to the dialog for user-specific


settings in the ABAP Workbench. Select the new editor mode in the
ABAP Editor tab and confirm your selection with Enter. The set-
ting remains in effect until you change it again.

Controlling the ABAP Editor


Above the input and output area of the screen that is used to edit Toolbars as
source code, youll find the control area of the ABAP editor: two controlling units

toolbars. The upper one (see Figure 3.4) helps to control the ABAP
editor. Table 3.1 explains the individual icons.

Figure 3.4 Toolbar to Control the ABAP Editor

Icon Function Description

Switch between When you change the source code, the


changing and background of the input and output area
displaying the is white. The background changes to gray
source code after you switch to "Display." Of course,
you cannot change the source code in this
mode.

Switching program Several versions of an object can exist in


status from active the real world, but only one of them can
to inactive be active at any given time. If you want to
inactivate an active version for a time so
that you can activate a different version of
the object, you can use this function.

Switching to During a project, developers


another object simultaneously work on several modules
that they become familiar with little by
little. You can use this function to display
a window from which you can quickly
control all other objects that belong to
your development project.

Table 3.1 Functions of the Toolbar to Control the ABAP Editor

75
152.book Seite 76 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

Icon Function Description

Switching to The only type of object you have become


another object familiar with so far are dictionary objects
(cont.) like tables. Advanced developers use this
function to navigate to function groups,
class libraries, and web objects.

Syntax check of the If the system finds a syntax error during a


source code check, a window is displayed that
indicates the problem areas. If it does not
find any errors, the status line notifies you
that no syntax errors were found.

Activate program If the program is inactive, the system


creates an active version with this
function. The correctness of the syntax is
checked and an active program version
and runtime version are generated. The
active object is generated even if the
program is already active.

Execute program in The program is started in test mode in the


test mode Workbench.

Where-used list of If an object is used in or by other objects,


the object the list shows in which other objects the
current object is used. You can navigate to
the location of the call from the list to
check the context in which the object is
used there. For example, tables are used in
many programs, so that changes to a table
structure could have unpleasant side
effects. When making changes, its always
a good idea to gather information about
the environment in which an object
works.

Display object list This function takes you to the view


provided by a different tool, the repository
browser. You see all the objects that
belong to your development project. You
work with the repository browser when
you require access to several objects for a
project.

Table 3.1 Functions of the Toolbar to Control the ABAP Editor (cont.)

76
152.book Seite 77 Donnerstag, 11. Oktober 2007 7:18 19

ABAP Editor: Overview


3

Icon Function Description

Display navigation This function is quite practical in complex


window development projects. An additional
window displays the last objects that were
edited, so you can quickly navigate among
them.

Help on This function opens a context-dependent


... window. This window appears in the
ABAP editor when you request help on
ABAP terms like key words, function
modules, and tables.

Set or delete Sooner than you think, the program will


breakpoint do what it was programmed to do rather
than what you want it to do. The end of
the program no longer meets expectations
and its time to observe the processing of
the program.

Set or delete You use this function to set a stopping


breakpoint point (breakpoint) on a line of source
(continued) code. The control icon is displayed to the
left of the line. When the program runs, it
stops at this line and switches to
debugging mode (see Chapter 6). Double-
click on the icon at the start of the line to
delete the breakpoint.

Insert pattern You must often insert several lines of


commands or comment blocks in the
source code. To save you the effort of all
that typing, this function is quite practical.
For more information, see Chapter 10.

Pretty Printer Source code can quickly become


unmanageable unless visual aids are built
in for comments, paragraphs, and
insertions. To avoid having you keep track
of how many spaces you need at the start
of a line (for nested loops, for example),
this practical function handles everything
for you.

Table 3.1 Functions of the Toolbar to Control the ABAP Editor (cont.)

The lower toolbar (see Figure 3.5) is used to edit the source code.
As you can easily see from the icons, the functions here are similar

77
152.book Seite 78 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

to those of other interfaces: cut, copy, paste, and so on. Table 3.2
explains the meaning of the icons.

SAP buffers In particular, working with buffers differs from working with the
clipboards familiar to you from your client. In addition to the
buffer of the presentation server (client) as the standard buffer, the
SAP system has three additional buffers: X, Y, and Z.

Copying within If youre copying in the standard SAP buffer, you can insert the
a system and contents of the buffer into another location in the source code in
beyond a system
the same mode. If youre copying in one of the three supplemental
buffers, you can also insert the contents into the source code in a
different mode. In both cases, however, the SAP system must be
the same. The buffers are related to the system and are emptied
when you quit the editor or log off the system. If you want to copy
between systems, you must start from the SAP system and copy to
the buffer of the client, either with the SAP menu or with Ctrl+C
and Ctrl+V.

The cursor must be placed on the line that is being edited. A section
of a line must be highlighted beforehand. A block that consists of
several lines must be highlighted at the beginning and at the end
of the block.

Figure 3.5 Toolbar to Edit Source Code

Icon Function Description

Cut line If you place the cursor on a line in change


mode and press this button, you cut the line
out of the source code. It disappears from
the source code and is stored in the SAP
buffer. From there, you can insert the line
into another location in the source code.
The SAP buffer has only one set of content:
new content overwrites old content.

Table 3.2 Functions of the Toolbar for Editing Source Code

78
152.book Seite 79 Donnerstag, 11. Oktober 2007 7:18 19

ABAP Editor: Overview


3

Icon Function Description

Copy line This function copies the line in which the


cursor is placed into the SAP buffer. The
source code still contains the original line.

Insert line In change mode, this function copies the


content of the SAP buffer to the line in
which the cursor is placed.

Selection mode You use selection mode to edit several lines


as a block. To copy a block of lines to
another location in the source code,
proceed as follows in change mode:
1. Place the cursor in the first line of the
block of lines.
2. Click on the selection button: the line
turns red.
3. Place the cursor on the last line of the
block of lines.
4. Click on the selection button again. This
line and all the lines in between turn red.
5. Copy the selected block to the X buffer
(or to one of the other buffers) via
Utilities Block/Buffer Copy to X
Buffer. The status line notifies you that
the block was copied to the buffer.
6. Position the cursor in the target line.
Careful programmers create a blank line
for the sake of safety and position the
cursor there. In the following step, the
contents of the buffer are inserted into
the line in which the cursor has been
placed.
7. Insert the contents of the X buffer into
the source test via Utilities Block/
Buffer Insert X Buffer.

Cancel command Cancel the last editor command in change


mode.

Insert new line In change mode, insert a blank line in front


of the line in which the cursor has been
placed.

Table 3.2 Functions of the Toolbar for Editing Source Code (cont.)

79
152.book Seite 80 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

Icon Function Description

Delete line In change mode, delete the line in which


the cursor has been placed.

Concatenate line In change mode, this function merges the


current line with the following line. This
option is helpful when editing leaves only
one word of a command in the following
line.1

Duplicate line/block You can use this function to copy lines or


blocks in the source code and reinsert them
into the original position with a click.
Depending on the actual case, it works like
a combination of the Copy Line and Insert
Line buttons or the steps to highlight a
block, copying a block to the buffer, and
reinserting the block in front of a line.

Move line/block This function moves text. The text in the


line is moved five columns to the right. If
you dont want to rely on Pretty Printer, you
can use this function to ensure better
legibility on your own.

Find You can use this function to search for and


replace text in the source code. Whether
youre searching for a character string that is
a word, a character string that is part of a
larger character string, or for uppercase or
lowercase characters, this function will find
it if it exists. The cursor in placed on the first
line of the hit. You can set the search area at
the cursor position or specify a set of lines.
If several inactive versions of your source
code exist, you can also search inactive
versions.

Find next You usually need this function along with


the Find function. If you suspect the
presence of additional hits in your source
code, you can continue to search with this
option.

Table 3.2 Functions of the Toolbar for Editing Source Code (cont.)

1 Please use this option carefully. You can use it to write two short commands in
one line. ABAP has no problem if you end every command with a period, but
doing so would make the source code difficult to read and runs counter to the
convention of placing each new command in a new line.

80
152.book Seite 81 Donnerstag, 11. Oktober 2007 7:18 19

Understanding and Editing ABAP Programs


3

Understanding and Editing ABAP Programs

When you now look at the source code (see Figure 3.3), you might Comments in the
see red, especially in lines 1 7. The asterisk (*) in the first position source code

turns the entire editing line into a comment line. You also have a
second option for comments: you can write something after an
opening quotation mark ("). Everything after the quotation mark is
interpreted as a comment rather than as a command. Section
Notes on the Source Code in this chapter provides an example of
this feature.

Please try from the very start to create good legible inline documen-
tation; the business world calls this adequate documentation, but
this term is not operational. Comment lines that make up some
30 % (or more) of the source code can, in some situations, be com-
pletely appropriate. Always remember that you might soon be a
third-party looking at the source code. You will note how quickly
your own code becomes unfamiliar even after a couple of months.

In the ABAP editor, youll see black along with red in line 9. This REPORT
is the first ABAP statement (also called a command) that youll
become familiar with, namely, the REPORT statement. It is always
the first statement in an executable program.

Youll also see the first operand (or addition) of the command: the
program name (Z_MEMBERLIST01).

You can also see a period (.) in the line, because every ABAP state- One more point
ment must end with a period. Even if a statement stretches over
several lines or screens, a period must be placed at the end of the
statement. However, you should note that a period doesnt have a
fixed place like the end of a line. It is just important that the period
is the last character of the command (i.e., it closes the command).
The place in the line is not important. It also could be placed
directly after the last operator. See the following complete state-
ment:

REPORT Z_MEMBERLIST01.

81
152.book Seite 82 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

Tips for self-help

If the REPORT command didnt offer any explanation here, you can eas-
ily determine what the statement does and what operands it has.
Click on the statement and then press F1. A help window opens with
ABAP key word documentation; you have information on the effects of
the command along with examples and tips (see Figure 3.6). The win-
dow also displays possible additions, and you can display hints and
examples as well.

WRITE Of course, you want to see the success of your first ABAP program
quickly, so you now write your first comment in line 10 (after the
REPORT statement):

WRITE 'This is my first list'.

Literal Its not difficult to discern that the WRITE statement outputs a list,
in this case, a literal 'This is my first list'. A literal is a set char-
acter string in the source code. It begins with a single quotation
mark and unfortunately cannot be maintained as language-depen-
dent. In Chapter 11, well start working with text elements that can
be translated, but for now lets just enjoy our immediate success.

Figure 3.6 ABAP Keyword Documentation

82
152.book Seite 83 Donnerstag, 11. Oktober 2007 7:18 19

Executing an ABAP Report


3

Executing an ABAP Report

Four steps are involved in the execution of our first ABAP program: Short countdown

Save
Check
Activate
Execute
Save the program via Program Save or with the Save (Ctrl+S) but-
ton. The status line issues a confirmation. Then check the program
via Program Check Syntax or the Check (Ctrl+F2) button. If you
receive a message in the status line that no syntax errors were
found in the program, you can activate the program via Program
Activate or with the Activate (Ctrl+F3) button.

Activation checks the correctness of the syntax, generates an active


version of the program, generates a runtime environment, and
deletes the object from the list of inactive objects. Activation there-
fore combines several work steps. You should already be familiar
with the next activation screen from Chapter 2. The status line dis-
plays the message, "Object was activated." The report is then
executable and you can start (execute) it.

You have two ways to perform a required test here. The first way Starting from the
is to navigate via Program Test Directly or with the Directly ABAP Workbench

(F8) button. You start the report from the ABAP Workbench. If the
program terminates, you then have to reopen the ABAP Work-
bench and redisplay the source code on the screen to look for
errors and correct them.

The second way is akin to the way that a user would start a report. Starting from ABAP
Usually, users dont have the necessary access rights to work in the program execution

ABAP Workbench. Depending on the rights that a given user has


been assigned, user menus can look different, but they all have
entries for System and Help. Thats why a normal user can start
the report from the SAP menu with System. Lets test this
approach.

83
152.book Seite 84 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

Open a second session (a second window) via System Generate


Session or with the Generate New Session button. In this session,
navigate via System Services Reporting to ABAP program execu-
tion . In this case, the system has already entered the name of the
program to be executed in the field. You simply have to press the
Execute (F8) button to start the program. The advantage of using
this approach is that you can see the dump in the second session if
the program terminates. If the program terminates, the system
generates a log as a screen list that contains hints about probable
causes and an excerpt of the source code that caused the error. If
the source code is still in the first session, its much easier to ana-
lyze errors and make corrections.

Did everything work?

Were assuming that our first attempt didnt trigger a program termi-
nation. If everything worked, you can see the result the first mem-
ber list (see Figure 3.7). You can use the Back (F3) button to return
to ABAP program execution. Then you have to switch to the session
with the ABAP editor.

Figure 3.7 First Output of a List

That wasnt difficult, but were not done yet. In the next step, lets
try to output the data records of the table that we created and popu-
lated in Chapter 2.

84
152.book Seite 85 Donnerstag, 11. Oktober 2007 7:18 19

Reading and Outputting Database Tables


3

Reading and Outputting Database Tables

When you want to work with database tables in a report, you must
inform the report about the tables. You can inform the report about
our table, ZMEMBER01, with the following statement:

TABLES zmember01.

The TABLES statement implicitly creates a structure of the same TABLES


name in the program, the table area or table work area. All the fields
of the structure have the same names and data types as the fields in
the database table. When reading the data records from the data-
base table, you can place each of them in the structure and then
work with them.

The hyphen

You address the fields of the structure with their names; you address
the MNAME fields of the ZMEMBER01 table with ZMEMBER01-MNAME.
The first part of the name is the table name; the second part of the
name is the field name. Note the hyphen between both parts. It sepa-
rates the parts of the name without any blank spaces. For your addi-
tional work, also note that you use the hyphen only for this purpose:
never use it with variable names.
Of course, no one remembers the type declarations for all the fields
of the database tables in use. If you need to refer to them, use forward
navigation (double-click on the name of the table) to branch to the
display of the dictionary, where you can see the required information
on the fields in the Fields tab. Then use the Back button to return to
the ABAP editor.

The following program is the simplest way to output the rows of a SELECT
database table line-by-line in a list:

SELECT * FROM zmember01.


WRITE / zmember01.
ENDSELECT.

The SELECT statement means that the records from the ZMEM-
BER01 table are transferred, record for record, into the program

85
152.book Seite 86 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

structure. The asterisk (*) indicates that all the fields of a record are
transferred. If you want to transfer only some of the fields, you
must specify those fields as a field list instead of using the asterisk.

In this form, the SELECT command corresponds to loop processing.


All records of the database table are transferred to the program
structure record by record. The structure of the loop begins with
the SELECT statement and ends with the ENDSELECT statement.

Formatting Lists

The structure contains the statements for processing the records


that have been read. In this case, the entire ZMEMBER01 structure
will be written to a list for each record. You trigger a new line with
a slash (/) in the WRITE command. Please note that you must insert
a space before and after the slash.

WRITE / With three data records in the database table, you have three lines
in the list: each line of the list is as long as the structure. The struc-
ture is output as a character string in the list. There is no empty col-
umn between the fields and the legibility of the list leaves
something to be desired. It would be better to see the fields in the
desired order with some space between them on the list. You must
address the fields of the structure. Consider the following example:

WRITE / zmember01-mdob.

The slash triggers output of the field on a new line. The following
statement, however, places the output of the field at the end of the
current line of print: the field is simply appended to the line.

WRITE zmember01-mname.

This approach can truly produce infinitely long lines. On its own,
the system breaks a line on the screen only when the screen set-
tings demand it. It breaks a line on paper only when the output set-
tings on the printer or the width of the paper demand it.
Accordingly, each and every developer is responsible for the cor-
rect design of a line.

86
152.book Seite 87 Donnerstag, 11. Oktober 2007 7:18 19

Formatting Lists
3

Chain Statement
A WRITE statement is needed for every field of the structure that
should be output in the list. You would have to expend a great deal
of effort to write a statement each time. Luckily, you dont have to.
Simply tell the system that several WRITE statements are to be exe-
cuted after each other.

Place a colon (:) after the first statement and separate the statement WRITE:
with a comma instead of a period. Place a period only after the last
statement. In our example, the chain statement appears as follows:

WRITE: / zmember01-mdob,
zmember01-mname.

Of course, these kinds of chain statements are not limited to WRITE


commands.

Looking good

Please consider the transparency and readability of the source code.


Even when you work with chain statements, you must adhere to the
principle of writing each statement to a new line. As far as possible,
you must avoid writing two or more statements in one line.

Lines
For simple list formatting, the ULINE command (without additional Underline
operands) creates a horizontal line in a new line of the list.

ULINE.

You can use this command to set off sections of a list and improve
its legibility.

Blank Lines
The SKIP statement creates blank lines in a list.

SKIP.

87
152.book Seite 88 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

If you want to create several blank lines, simply specify the number
of blank lines. The following statement produces three blank lines:

SKIP 3.

Writing and Editing Source Code

Type it yourself You can simply type your first source code manually (see Listing
3.1),1 so that you can become familiar with the ABAP editor. You
create empty lines with Enter. You can also use the familiar copy
and insert functions (Ctrl+C, Ctrl+V, and so on) and practice with
the additional functions of the ABAP editor for entire lines or
blocks of lines, as described in Section Controlling the ABAP Edi-
tor in this chapter.

1 *&---------------------------------------------*
2 *& Report Z_MEMBERLIST01 *
3 *& *
4 *&---------------------------------------------*
5 *& *
6 *& *
7 *&---------------------------------------------*
8
9 REPORT z_memberlist01 .
10 TABLES zmember01. " Declare table
11 WRITE 'This is my first list'.
12 ULINE. " horizontal line
13
14 * loop
15 * each record of the table with all fields
16 * will be printed on a new line of the list
17 SELECT * FROM zmember01.
18 WRITE / zmember01.
19 ENDSELECT.
20 SKIP. " 1 blank line
21
22 * select statement like before

1 You can also download the source code in Listing 3.1 from the website for this
book at http://www.sap-press.com.

88
152.book Seite 89 Donnerstag, 11. Oktober 2007 7:18 19

Writing and Editing Source Code


3

23 * single fields of the record will be printed


24 SELECT * FROM zmember01.
25 WRITE / zmember01-mdob.
26 WRITE zmember01-mname.
27 ENDSELECT.
28 SKIP. " 1 blank line
29
30 * select statement like before
31 * single fields will be printed like before
32 * but the write statement is concatenated into a chain
statement
33 SELECT * FROM zmember01.
34 WRITE: / zmember01-mdob,
35 zmember01-mname.
36 ENDSELECT.
Listing 3.1 Z_MEMBERLIST01 Report

Notes on the Source Code


You start editing in line 10, right after the REPORT statement that is Short
inserted automatically. The system automatically generates the documentation

first eight lines. They serve as short documentation on the author,


creation date, and change history.

Line 10
TABLES zmember01. " Declare table

The report is therefore aware of the ZMEMBER01 table (along with


its structure and fields) and creates a table area in the program that
you can use to read and process the table fields. The statement con-
cludes with a period.

After the blank space, a comment line begins with the quotation Comment lines
mark in the same line: "Declare table." The system interprets all
characters to the right of the quotation mark as a comment. Even
if you write a statement over several lines, you can still insert com-
ments into individual lines. The comments would appear in the
middle of the statement.

89
152.book Seite 90 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

Line 11
WRITE 'This is my first list'.

The text between single quotation marks is output to the current


position in the list. Because this is the first WRITE statement, the
current position is line 1, column 1.

Line 12
ULINE. " horizontal line

ULINE produces a horizontal line across the entire width of the list.
That separates the title from the rest of the list.

Line 13
The blank link should improve the legibility of the list.

Lines 14, 15, and 16


* loop
* each record of the table with all fields
* will be printed on a new line of the list

These three lines are comment lines that explain the following
statements.

Line 17
SELECT * FROM zmember01.

One record The SELECT statement opens a structure. A loop reads all the data
after the other records of the table and transfers them one by one into the table
area of the program. The table area contains a complete record of
the table. The record is processed from the table area. Once
processing of the record ends, the next record is read. The asterisk
means that all the fields of a record are being selected.

Line 18
WRITE / zmember01.

The slash after the WRITE statement outputs the list to a new line in
column 1, rather than to the current print position. Note that a
blank space must be placed before and after the slash.

90
152.book Seite 91 Donnerstag, 11. Oktober 2007 7:18 19

Writing and Editing Source Code


3

Writing the ZMEMBER01 option outputs the table area as a whole Output as
as a character string. The length of the character string is the character string

sum of the lengths of the fields. In the character string, the fields
are given according to their type they are not formatted for print-
ing.

Line 19
ENDSELECT.

The ENDSELECT statement closes the open SELECT structure. Just


like other loops have a closing command for every opening com-
mand, each SELECT statement (if its a loop) has an ENDSELECT
statement.

Just like math

The situation here is similar to that working with brackets in math. An


opening bracket always has a closing bracket: they always appear in
pairs. When nesting brackets, you must make sure that you have
assigned them correctly. The same applies to loops in programming.
When nesting loop structures, you must also take special care to make
sure that the loop is opened in the right position, the loop processing
runs correctly, and that the loop is closed. We have not yet nested any
loops, but the principle applies already.

Line 20
SKIP. " 1 blank line

The SKIP statement creates a blank line in the list. This statement Improved legibility
is helpful for improving the legibility of the list.

Lines 21, 22, and 23


The source text has a blank line and two comment lines here, just
as it does in lines 1316.

Line 24
SELECT * FROM zmember01.

91
152.book Seite 92 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

All records of the table are reread in a loop as in line 17. There
difference here is in the following record processing.

Line 25
WRITE / zmember01-mdob.

Writing convention

This WRITE statement outputs a field from the work area of the table
structure: the MDOB field of the ZMEMBER01 table structure. Note
the writing convention here: structurename-fieldname. If the field
name or the structure name contains a hyphen as part of the name,
the system cannot uniquely identify and interpret the statement.
Thats why when assigning names, you should always work with an
underline ( _ ) TABLE_A-FIELD_B, for example.
The slash after the write statement always places the output on a new
line in column 1.

Line 26
WRITE zmember01-mname.

This WRITE statement also outputs a field of the table structure: the
MNAME field. The output is placed in the current position in the
list, after the MDOB field in this case. If fields are written after each
other in the same line, the system automatically inserts a line
break.

LINE-SIZE With this kind of output, you must make sure that the line has
enough room for the fields that you want to have in the first line.
You could also add LINE-SIZE after the REPORT statement to manip-
ulate the width of the list.

Line 27
ENDSELECT.

The ENDSELECT statement closes the SELECT loop from line 24


the last one that was opened.

92
152.book Seite 93 Donnerstag, 11. Oktober 2007 7:18 19

Writing and Editing Source Code


3

Line 28
SKIP. " 1 blank line

As in line 20 of the source code, insertion of a blank line here


improves legibility.

Lines 29 32
Blank lines and comments are inserted into the source code here.

Line 33
SELECT * FROM zmember01.

The table is read for the third time.

Line 34 und 35
WRITE: / zmember01-mdob,
zmember01-mname.

In the list, the result looks exactly like the second read loop. The C as in
difference is in the writing. When several statements that follow chain statement;
C as in comma
each other are the same and differ only in the operands, you can
use a chain statement. Line 34 has a colon right after the WRITE
statement without a space. That tells the system that several
WRITE statements now follow each other. The individual statements
are not ended with a period, but are separated by commas. Only
the last statement, as usual, is closed with a period.

The first statement in our example outputs the MDOB field of the
ZMEMBER01 table structure to a new line in column 1. It is closed
with a comma. The second statement writes the MNAME field of
the same table structure to a list with a blank space after the MDOB
field. Because this statement is the last statement of the chain state-
ment, it is closed with a period. Please note that a chain statement
can involve several statements right after each other. The principle
that a new command belongs in a new line also applies to a chain
statement.

Line 36
ENDSELECT.

93
152.book Seite 94 Donnerstag, 11. Oktober 2007 7:18 19

Programming in the ABAP Editor


3

Dont forget to end the loop: this ENDSELECT statement belongs to


the SELECT statement in Line 33.

List Screen from Our Sample Source Code


Self-programmed If you look at the list screen (see Figure 3.8), you can see that the
outputs system has generated some outputs on its own: the date and the
descriptive text from the program properties.

Figure 3.8 List Screen for the Z_MEMBERLIST01 Report

But right now, the outputs that we created ourselves are more
important:

Outputs created The first line is the text, "This is my first list."
The second line is the horizontal line beneath the text.
The next three lines present the unformatted output of the table
structure. One line in the list corresponds to the complete con-
tents of the structure. Because the table contains three data
records, the processing loop is run through three times and three
lines are written to the list.

94
152.book Seite 95 Donnerstag, 11. Oktober 2007 7:18 19

Writing and Editing Source Code


3

After the blank line, you can see three lines, each with a birth
date and name. Note that the date is output in a different format
than it was in the first block. When we declared the field in the
table, we defined the "Date" field type. That includes a country-
specific presentation of the data format. The internal formatting
of the field is seen in the output of the table structure: YYYYM-
MDD. Because only two fields of the table structure should be
output, the remaining fields do not appear in the list.
The contents of the third block do not differ from those of the
second block. The difference exists only in the source code,
where the WRITE command was given as a chain statement.

Did everything work as planned? If so, use the Back (F3) button to
return to the ABAP editor. In the next step, well work with fields
and calculations.

95
152.book Seite 491 Donnerstag, 11. Oktober 2007 7:18 19

Index

$TMP 48, 163 Advanced Business Application Pro-


&, placeholder 347 gramming ABAP
* 81 Alphanumeric characters 122
. 81 AND 285
/ 86 AND RETURN 449
APPEND 382, 388, 423, 426
A Append structure 159, 180
activating 182
ABAP 21 assigning 180
ABAP commands 81 component 181, 182
ABAP Debugger 139, 144, 155, 411, creating 180
425 maintaining 179
call 140 name 181
close 155 APPL0 63
system fields 147 Application layer 23
tablespace 149 Application server 24
ABAP Dictionary 39, 44, 46, 161, 187, Arithmetic operations
201, 214, 232, 237 using date fields 202
ABAP Editor 40, 69, 73, 88 Arithmetic operator 110
controlling 75 - 110
dynamic breakpoints 155 * 110
icons 75 + 109
toolbar 75 / 110, 113
ABAP keyword documentation 82 Array fetch 385, 408
ABAP memory 467 Article numbers 123
ABAP Objects 31, 380, 445 AS CHECKBOX 321
ABAP programs AS TEXT 397
modular structure 32 Assigning names to variables 103
structure 31 Asterisk 463
ABAP report AT 130
creating 69 AT SELECTION-SCREEN 314, 315,
executing 83 346
ABAP runtime environment 31 AT SELECTION-SCREEN ON 318
ABAP statements 81 AUTHORITY-CHECK 233
ABAP Workbench 37, 83, 432 Authorization
Access effort 393 check in source code 233
Access key 37, 373 concept 232
Access time 373, 374 group 72
Accounting 36 object 233
Activation sequence 166 program execution 234
ADD 110 transactions 234
Addition 82, 108 Automatic client management 65
ADJACENT DUPLICATES 400 Automatic type conversion 282, 383

491
152.book Seite 492 Donnerstag, 11. Oktober 2007 7:18 19

Index

B Calculation 97 (cont.)
determining last day of previous
Back-end mode 73, 74 month 205
advantages 74 determining last day of the current
Background processing 337 month 206
Basic arithmetic operations 102, 108 determining past days 206
Basics of ABAP programming 33 determining periods of time 202
BEGIN OF 376 determining remaining days 207
BEGIN OF LINE 348 determining the age of a person 207
BETWEEN 283 determining the beginning of a month
Blank character 109 204
removing 128 determining the keydate 204
Blank lines, generating 87 determining the payment date 203
Block dimension of time periods 208
duplicate 80 remaining days 207
moving 80 sales tax 215
Block name 350 time period containing date change
Block of lines 212
deleting 101 time period in days 209
selecting 100 time period in hours 210
Block/buffer 100 time period in minutes 210
Block-by-block transfer 385 time period in seconds 210
Body line 441, 467 time period in years 209
change 391 time until midnight 211
delete 400, 401, 402 using time fields 209
Branch 266 with currency fields 214
BREAK-POINT 142, 157 with quantity fields 214
Breakpoints 77, 140, 150 Calculation accuracy 112
active 154 CALL FUNCTION 459, 465
delete 154, 155 Cardinality 177
dynamic 142, 155, 157 CASE 270, 272, 296, 465
manage 155 Case distinction 261, 270
save 155 Case sensitivity 300
set 142, 154 Central control component 489
Breakpoints mode 154 Chain statement 87, 93, 117, 375, 376,
Buffering 63, 78, 232 378
BY 396 CHAR, data type 166, 169
Character string 91, 121, 122
C complementing 124
concatenating 128
c, data type 122, 125, 131, 202, 214, condensing 127
240, 241, 282 modifying 121
Calculation 97 replacing 124, 126
determining an invoice amount 216 searching 124
determining an invoice date 203 shifting 124
determining keydates 202 splitting 130

492
152.book Seite 493 Donnerstag, 11. Oktober 2007 7:18 19

Index

Characters Consolidation system 24, 26


alphanumeric 122 CONSTANTS 107
cutting 124 Constants 103
numeric 123 Context-sensitive 346
CHECK 278, 438 CONTINUE 277
Check program logic 140 Control structure 262, 267
Check table 175, 193 Conversion in dialog 192
Checkbox 448 Conversion rules 110, 111
Checksum process 374 Convertible data objects 110
CLEAR 240, 241, 242, 401, 402, 411, Copy 189
415, 424, 427, 444 Core areas 36
Client 35 Create line 87
handling, automatic 237 Creating selection variants 334
management, automatic 65 Cross-application components 36
number 237 Cross-client tables 237
Client-server architecture 23, 231 Cryptology 374
Clipboard 74 CUKY, data type 169, 170, 214
Cluster 467 CURK, data type 201
Cluster name 467 CURR, data type 169, 201, 202, 214
Cluster tables 45 Currency
Code table 282 amount 169
Collective shaft 269 fields 169, 201
Column distribution 118 key 201
Command 81 unit 169, 174
canceling 79 Customer name space 181, 184
COMMENT 348 Customizing 25
Comment 81 Cut 189
asterisk 81
lines 100, 264 D
on the screen 348
quotation mark 81 d, data type 199, 240
Company code 35 DATA 104, 107, 122, 199, 221, 240,
Compatible data objects 110 375, 411, 422, 437
Complex condition 266 BEGIN OF 376
Components, append structure 181, DECIMALS 104
182 END OF 376
Composite profiles 233 LIKE 105, 123, 200
Computational accuracy 113, 214 OCCURS 376
COMPUTE 112 TYPE 104
CONCATENATE 128, 138 VALUE 106, 123, 200
SEPARATED BY 129 Data
CONDENSE 127, 138 block 384
NO-GAPS 128 browser 47, 165, 187
Conditions 275 class 63
complex 284 consistency 449
resolving 284 declarations 433

493
152.book Seite 494 Donnerstag, 11. Oktober 2007 7:18 19

Index

Data (cont.) Database tables (cont.)


loss 190, 193 transparent 159
temporary 324 Database utility 190, 194
transfer 467 Database, adjust 160, 192
Data element 50 Date fields 199
activate 61 defining 199
check 60 filling 203
creating 50 in arithmetic operations 202
Data objects 103, 377, 386, 437 processing 202
compatible 110 Date format 95
convertible 110 Debugging 139
Data records 371 Debugging mode 140, 142
checking 164 DEC, data type 169, 214
creating 64 Decimal numbers 104
delete 243 Decimal places 104, 107
displaying 67 Decimal separator 107
entering 65 DECIMALS 104
Data type 53, 55, 103, 112, 377, 437 Declaration 105
c 122, 125, 131, 202, 214, 241, 282 Declaration part 31
CHAR 166, 169 DEFAULT 318, 328
character 199 DELETE 238, 243, 244, 259, 261, 395,
complex 377 400, 414, 424
CUKY 169, 170, 214 ADJACENT DUPLICATES 400
CURK 201 DESCENDING 397
CURR 169, 201, 202, 214 DESCRIBE 392
d 199, 240 LINES 392
DEC 169, 214 Development system 24, 25
differences 125 Dialog modules 31
elementary 104, 377 Dictionary elements 378
f 317 Digital signature 374
generic 122, 123 Display list 146
i 104, 111, 209 DIV 113, 208, 209
n 123, 125, 131 DIVIDE 110
NUMC 55, 169 Division 108, 113, 208
p 104, 108, 111, 202, 209, 214, 215 different cases 113
QUAN 169, 215 integer 308
string 488 integral 113
t 200 Division of work 232
UNIT 169, 215 DO 273
Database layer 23 DO loops 274
Database lock 234 Documentation 54
Database server 24 Domains 50, 106
Database tables 465 activate 58
modification 159 creating 51, 55
outputting 85 Dump 84
reading 85 Dynamic name assignment 241, 244

494
152.book Seite 495 Donnerstag, 11. Oktober 2007 7:18 19

Index

Dynamic program Dynpro EXPORT TO MEMORY 467


Dynpro 28, 312 External report
calling 446
E
F
Editor lock 72
Editor mode 75 f, data type 317
Elementary data types 104 F1 66, 82, 319, 349
Elements F3 84, 343
copying 99 F4 55, 66, 168, 178, 319, 334
creating your own 51 F5 144
ELSE 267, 269 F6 145
ELSEIF 268, 269 F7 145
END OF 376 F8 84, 145, 364
END OF BLOCK 350 Field 49, 97, 103, 139, 182
END OF LINE 348 asterisk 86
ENDCASE 270 declaring 102
ENDDO 273 definitions 199
ENDFORM 436, 440, 441 identical names 377, 382, 384, 388,
ENDIF 262, 267 389
Endless loops 273 inserting 159
ENDLOOP 390 label 53, 332
ENDSELECT 86 length 103, 122
ENDWHILE 276 list 86, 169, 379, 438, 467
Entry check 169, 171, 174, 175, 177 mode 144
Error processing 102
analysis 84 type 378
case 271, 296 Field content
exit 465, 488 changing 147
handling 248, 316, 346 check 146
log 190 modify 147
message 177 monitor 153
Event 363 shifting 126
Event keyword 313, 363 Filling date fields 200
Event orientation 363 Find 80
Events 313 Find next 80
examples 314 Fixed point arithmetic 72
terminating 280 Fixed values 109, 166
Exception handling 465, 488 individual values 167
Exchange rate conversion 214 intervals 167
Exclusive lock 236 maintaining 166
Executable program 71 testing 167
EXIT 279, 280, 302 Flow control 489
Exponential numbers 112 FOR FIELD 349
EXPORT 467 Foreign key 171, 176, 235
Export parameter 459, 465 maintaining 175

495
152.book Seite 496 Donnerstag, 11. Oktober 2007 7:18 19

Index

Foreign key 171, 176, 235 (cont.) Hat 411, 427, 441
relationship 193 Header line 371, 372, 379, 380, 382,
table 175 390, 441
testing 177 Help 77
FORM 436, 437, 441, 444, 446 Hierarchy levels 123
Formatting lists 86 HIGH 324
Forward navigation 51, 85, 183, 185, Human resources 36
187, 432, 435, 466 Hyphen 85
Frames 347
FREE 402, 403, 411 I
Free text 347
FROM 400 i, data type 104, 111, 209
Front-end mode 73, 74 Identical names 388
Function builder 40, 450, 452 IF 262, 267, 269, 278, 284
test environment 456 IF structure 270, 323, 326, 465
Function code field 39 nesting 269
Function groups 450, 451 IMPORT 467
Function library 450 IMPORT FROM MEMORY 467
Function module 40, 77, 235, 431, Import parameter 459
449 IN PROGRAM 445
call 459, 462 INCLUDE 385, 389, 432
documentation 460 Include
exceptions 455 compress 187
export 454 expand 187
flow type 452 report 432
import 454 INCLUDE STRUCTURE 384
name 459 Include structure 183
properties 452 activating 186
search 451 create 185
searching 450 insert 185
testing 450, 457 maintaining 184
value transfer 454 position 184
preconditions 183
G Inconsistencies check 177
INDEX 392, 399
Generic data type 122, 123 Index 373, 391, 393, 395
Generic key 176 Index tables 374, 392, 395, 399
GET PARAMETER 466 Industry minutes 225
GET PARAMETER ID 466 Information systems 36
Global SAP memory 466 INITIAL SIZE 378
Global variables 437 Initial value 106, 240
INITIALIZATION 313, 315, 363
H Initialize header line 401
Inline documentation 81
Hash algorithm 374, 395 Input blocks 347
Hashed table 374, 395

496
152.book Seite 497 Donnerstag, 11. Oktober 2007 7:18 19

Index

Input fields Line


positioning 347 block 350
Input help 166, 171, 177, 179 break 86, 92
Input help list 178 change 391
Input verification 315, 317, 364 concatenating 80
INSERT 237, 238, 242, 392, 399, 423 copying 79
Insert 189 cutting 78
Integers 104 delete 395
Integral division 113 deleting 80
Integral division with remainder 114 duplicate 80
Interfaces 378 duplications 374
Internal tables 370, 441, 467 free layout 348
benefits 370 insert 392
define 371, 375, 379 inserting 79
filling one record at a time 381 inserting new line 79
process 390 moving 80
structure 370 redundant 400
INTO 399, 400 structure 378
INTO CORRESPONDING FIELDS 385 Line type 372, 376, 377, 386
IS INITIAL 283, 322 define 380
Item numbers 123 LINES 392
LINE-SIZE 92
K List
formatting 86
Key 49, 379, 391, 394, 399 headings 330
generic 176 of suggested values 168
non-unique 373, 378 processor 312, 314
unique 373 screen 94, 312
user-defined 373 Literal 82, 107, 123, 244, 259, 391,
Key fields 184, 188, 394, 399 414, 459, 467
change 188 Literals 222, 300, 342
deleting 190, 193 LOAD-OF-PROGRAM 32, 313
manipulation 160 Local names 444
Key words 77 Local object 27, 48, 99
Keyword documentation 82 Local SAP Memory 466
Local variable 437, 440
L Locale object 163
Locale variable
Language key 343 explicit definition 437
Leap year 287 implicit definition 438
Legibility 32 Lock
Length 131 logical 235
LIKE 105, 123, 200, 319, 382 point-in-time problem 236
Limiting loop runs 274 problem 236
Limits 372 remove 236
table 235

497
152.book Seite 498 Donnerstag, 11. Oktober 2007 7:18 19

Index

Lock concept 232, 234, 235 Message 341 (cont.)


physical database 234 on the status bar 316
SAP 234 pool 344
Lock object saving 345
remove 235 type 346, 364
set lock 235 type E 346
Logical AND 285 Message class 343, 347
Logical database 72 creating 344
Logical expressions 261, 281 MESSAGE-ID 344
linked 269 MOD 114, 208, 209
linking 284 MODIFY 237, 242, 391, 392, 398
Logical operators 281 FROM 398
Logical OR 284 Modularization 22, 377
Logistics 36 Module 437
Logon 34 Module pool 312
Logon client 65 MOVE-CORRESPONDING 383
Logon screen 34 Multiple selections 326
Long text 460 Multiplication 108
LOOP 390, 391, 392, 395, 398 MULTIPLY 110
Loop 86, 90, 91, 227, 272, 371
endless loops 273 N
inner 275
outer 274 n, data type 123, 125, 131
processing 91 Name assignment
termination statements 277 dynamic 244
with conditions 272 static 242, 243
without conditions 272 Naming convention 181
LOW 324 Native SQL 30, 45
LOWER CASE 320, 328 Navigation window 77
Lower-case and upper-case letters 244 Negation 286
LT 278 Nesting 91, 272, 274, 277, 378, 434
Nesting levels 269
M Network drives 457
Network paths 457
Maintainability 32 NEW-PAGE PRINT ON 312
Maintenance dialog 165 NO-EXTENSION 329
Maintenance screen 185 NO-GAPS 128
Mandatory parameter 460 Non-key fields 188
Memory area 376 enhancing 165
Memory ID 467 NOT 286
Memory space, initial 378 Notation
Menu painter 40 modern 445
MESSAGE 344, 346, 347, 364 traditional 445
Message 341 Numbers
editing 344 integers 104
number 347 packed 112

498
152.book Seite 499 Donnerstag, 11. Oktober 2007 7:18 19

Index

NUMC, data type 169 Physical area 63


Numeric characters 123 Placeholder 347
Numeric text fields 123 Placement operands 347
Point-in-time problem 236
O Pool tables 45
POSITION 349
Object Position 118
activating 166 operand 129, 438, 441, 445
classes 233 specifying 118
key 179 Positioning 131
list 76 Preassignment 106
local 27, 48, 99, 163 Preselection 291
navigator 41 Presentation layer 23
Object orientation 375, 377 Presentation server 23
OBLIGATORY 319, 328 Pretty Printer 77
OCCURS 376 Primary key 242, 243
Office 36 Printing 312
Open SQL 39, 232 Procedures 32, 430, 434, 449
statements 237 Processing
Operations, arithmetic 209 reading 371
OPTION 324 writing 371
OR 284 Processing blocks 31
Output position 118 Processing type
background 192
P direct 192
Production system 25, 26
Packed numbers 112 Profiles 233
Parameter Program
mandatory 460, 463 activate 76
optional 463 activating 83
Parameter ID 466 checking 83
create 466 execution 84
initializing 477 flow control 261
reading 477 name, dynamic 446
writing 486 saving 83
Parameter list, checking 445 starting 83
PARAMETERS 317 status 71, 75
Parentheses 287 termination 84
Parenthetical levels 285 Properties
Patterns 77, 263 semantic 177
inserting 263, 266
PERFORM 435, 436, 441, 444, 445, Q
446, 477
IN PROGRAM 445 QUAN, data type 169, 215
USING 438 Quantity fields 169
Period of time for date values 208 Quantity units 169

499
152.book Seite 500 Donnerstag, 11. Oktober 2007 7:18 19

Index

R SAP Memory 477


read 466
Radio buttons 322 write 466
RADIOBUTTON GROUP 323 SAPscript Editor 54
Range 325, 327 Screen check 177
READ 393, 394, 399, 410, 413 Screen painter 40
INDEX 399 SE11 44, 161
INTO 399 SE38 69
Readability 103 SE91 344
Record Search term 126
create 242 Search, generic 451
modify 242 SELECT 85, 227, 237, 272, 273, 381,
Redundancies 190 385
Reference field 170, 193, 201 Selection buttons Radio buttons
REFRESH 401, 402, 411, 424 Selection mode 79, 100
Release reserved memory area 402 Selection screen 311, 319, 334, 338,
Reorganization work 160 447, 448
Repetition 262 avoiding 448
REPLACE 126, 138 processing 346
REPORT 81, 99, 141, 344 saving 333
Report 28 Selection table 324
copying 98 Selection texts 329, 330
data transfer 465 activating 332
start with variant 340, 447 creating 330
REPORT, LINE-SIZE 92 editing 331
Repository info system 450 using 329
Response time 374 Selections 316, 323
Return code 147, 238, 239, 242, 243, SELECTION-SCREEN 348
271, 296, 414, 465, 488 BEGIN OF LINE 348
Reusability 185, 377 COMMENT 348
Role 233 END OF BLOCK 350
Row END OF LINE 348
create 242 FOR FIELD 349
delete 189, 243 POSITION 349
highlighting 74 TITLE 351
insert 189 WITH FRAME 351
update 242 SELECT-OPTIONS 324, 325, 329
Runtime environment 313 Semantic properties 177
Runtime object 163 Separator string 130
Runtimes 192 SEPERATED BY 129
Session 84
S SET PARAMETER 466
SET PARAMETER ID 466
Sandbox 26 Settings, technical 62
SAP GUI 33 Shared lock 236
SAP Logon 34 SHIFT 125

500
152.book Seite 501 Donnerstag, 11. Oktober 2007 7:18 19

Index

Shifting field contents 126 String operation 124, 132, 209, 222,
Short description 52 223
Short documentation 89 String, data type 488
SIGN 324 Structure 85, 182, 371
Single quotation marks 90 components 182
Single values 325 end 262, 313
Size category 63 include 385
SKIP 87, 292 maintenance screen 186
Slash 86 start 262
SORT 396, 415 SUBMIT 447, 449, 466
BY 396 AND RETURN 449
Sort sequence 397 VIA SELECTION-SCREEN 447
SORTED TABLE 379 WITH 447
Sorted table 374, 393, 395 Subprogram 430, 434, 438
Sorting call 435, 444
binary 397 external 444
criteria 397 fields 438
language-specific 397 internal 444
Source code Subroutine 435
editing 78, 88 Substring 131
modularization 430 Substructures 183
switching 75 SUBTRACT 110
writing 88 Subtraction 108
Source field 111, 129 Suffix 457
SPACE 136 SY-DATUM 200
SPLIT 130, 138 SY-INDEX 276, 280
AT 130 Syntax 374
Standard key 373 check 76, 434
Standard selection screen 312 error 76
Standard table 181, 188, 373, 378, System
393 client 50
enhancing 180 date 200
STANDARD TABLE OF 378 table 147, 344
Start position 131 SY-SUBRC 147, 238, 239, 271, 456
START-OF-SELECTION 32, 314, 365, SY-TABIX 395
435
Statement block 267, 270, 348 T
terminating 277
Statement blocks 262 t, data type 200
Statements 81 T100 343, 364
Static name assignment 242, 243 Tab, fields 182
Step into 144, 412, 425 TABLE 400
Stop sign 411 Table 77, 377
Stopwatch 276 activating 63
String 199 area 85, 89
body 371, 372, 380, 390, 391

501
152.book Seite 502 Donnerstag, 11. Oktober 2007 7:18 19

Index

Table (cont.) Technical settings 62


checking 62 Temporary data 324
completion 61 Temporary tables 370
content, displaying 66 Termination condition 274, 281, 302
content, modify 237 Termination statements 278
conversion 193 effects 279
copying 161 Test data records
declaring 89 enter 165
definition 374 Test mode 76
deleting 194, 196 Test system 24, 25
entries 164 Text element 222, 329
entry 371 editing dialog 342
error message 170 Text fields, numeric 123
field, deleting 192 Text objects, completing 341
header 372 Text pool 329
index 395 activating 343
internal 370 Text symbol number 342
maintaining 46, 165 Text symbols 330, 341, 348
maintenance dialog 64 editing 342
mode 148 Time fields 200
modify 159 defining 200
physical conversion 190 filling 201
row 164 TIMES 274
saving 47 TITLE 351
status 163 Toolbars 75
T100 364 Totals
TCURC 172 calculating 291
temporary 370 outputting 291
transparent 45 Totals fields, initializing 292
type 377, 378, 379, 386 Transaction code 38, 234
without header line 380 Transaction SE91 344
Table processing 374 Transaction, runtime 466
multidimensional 371 TRANSLATE 321
n dimensional 372 Translation 342
Table structure 92 Transparency 32
physical 188 Transparent tables 45
Table work area 85 Trick 35 205, 206
buffer 239 Troubleshooting 140
delete 240 TYPE 104
TABLES 85, 239, 441, 444 Type conversion 137, 199
Tablespace 63 automatic 282
check 149 Type declaration 85
Target field 111, 129 Type definition 378, 379, 389
Target table 162 TYPES 378
TCURC 172, 175
table 172

502
152.book Seite 503 Donnerstag, 11. Oktober 2007 7:18 19

Index

U W
ULINE 87 WAERS, domain 172, 174
UNDER 119 Watchpoints 140, 150
Underline 92 create 151
Unicode check 72 mode 150
Unit of currency 255 save 155
UNIT, data type 169, 215 WHEN OTHERS 271
UPDATE 237, 241, 242 WHERE 245, 273, 396, 410, 424
Upgrade 180 Where-used list 76, 194, 195
Upper and lower case 317, 446 WHILE 275
Uppercase and lowercase letters 123 WHILE loop 275
Uppercase and lowercase spelling 391 Wildcard 451
User master record 233 WITH 347, 447
USING 438, 444 WITH FRAME 351
WITH HEADER LINE 379, 423
V WITH KEY 394, 399
WITH UNIQUE KEY 379
Validation 168, 179 Work area 240, 242, 371, 372, 376,
VALUE 106, 123, 200, 411 377, 382, 391, 398, 400, 423
VALUE CHECK 320 define 379
Value range 56 defining 240
Value table 172, 174, 175 initialize 248, 402
Values Work process 235
negative 106 Working memory areas 449, 465
transfer 447, 448 WRITE 82, 86, 87, 118
valid 171 UNDER 119
Variable 103, 467
Variant 72 X
creating 334
editing 337 X buffer 78
properties 337
protecting 337, 339 Y
start using 72
Variants 334 Y buffer 78
VIA SELECTION-SCREEN 447, 448
Z
Z buffer 78
ZIP codes 106

503

You might also like