0 ratings0% found this document useful (0 votes) 63 views87 pagesHow To Develop in ABAP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
HOW TO DEVELOP IN ABAP
How to Develop in ABAP
Applies to:
SAP NetWeaver 7.0. For more information, visit the ABAP homepage.
Summary
This is the PDF version of the development blog series on SDN published in 2007 that gave an introduction
to ABAP newbies who want to leam how to develop simple programs in ABAP.
‘This PDF file does not contain the few blogs of the original series that explained how to install and
administrate the ABAP demo version and how to import and export programs. This PDF document solely
focuses on the many blogs that focused on development in ABAP. This is why the PDF file starts with blog 3
and has some gaps in the numbering.
‘The main author of this blogs is Thomas Weiss but some blogs were written by other authors (Manfred Lutz,
Hans Tillinger, Dirk Feeken). For more information read the original blogs.
If you are interested in the comments and answers to the comments on the blogs you should read the
original blogs on SDN. Otherwise this PDF file gives you an easy opportunity to work your way through the
whole series.
Author Bio
‘Thomas Weiss has a Ph.D. in analytic philosophy. He worked as a professional writer before joining, in 2001,
the SAP NetWeaver product management training team where his responsibilities included the e-Learning
strategy for ABAP. After becoming more involved in writing ABAP material himself, he is now a member of
the SAP NetWeaver Application Server Solution Management. One of his main interests lies in roling out
ABAP topics both for experts and for beginners by writing blogs in SDN.Table of Contents
WHY AND HOW THE SERVER MATTERS TO YOU AS A DEVELOPER: SERVER ARCHITECTURE AND
WORK PROCESSES... 4
ABAP Application Server for Newbies — Why and How the Server Matters to You as a Developer.......4
Developing on the Server .s.nmteninnnnnninnnnnniuntiennnsinaininunnnnnnsnnnnnnnnaninn 4
The Three-Layer Architecture 5
Work Processes in Some Detail 5
The Three Layer Architecture Continued... nnmmnmnnnnnnnnnnannnnnnnnne 7
‘Summary. 8
MANY DEVELOPERS ON ONE CENTRAL SERVER - HOW DOES IT WORK? wssesnmnnieennnnnee B
Many Developers on One Server — How Does It Wotk? ssn
Developing on a Central Server - The Way to Keep Your Sources
‘Summary.
NAVIGATION IN THE APPLICATION SERVER.
A FIRST ‘HELLO-WORLD' PROGRAM
‘Sync.
The Repository Browser ~ The Central Place in the ABAP IDE vi.
Packages. 44
‘A Package for Local Objects. 414
‘Hello World’ as a Local Program. 44
‘Summary. 48
CREATING A PROGRAM AND A PACKAGE - AN INTRODUCTION TO THE SAP CHANGE AND
TRANSPORT SYSTEM.
‘Some Words of Motivation: Why Your Programs Deserve Better than Package Stmj 49
Creating a Package - the Chance to Get in Touch With the CTS 49
Creating a Package - the Details wnnmmnnnnnnnmninnnnnnnnnnnansnnnnmnnnnnnnnmnnnnnnnel®
The Concept of a Transport Layer...
‘Some More Basic Concepts of the SAP Change and Transport System....
Package Building Continued ...emnr
Creating a Program Within a Package
Outlook.
AFIRST LITTLE BUSINESS PROGRAM.
The Aim: Our First Little Business Program.
How to Use the ABAP Documentation...
How to Get an Internal Table with the Line Type of a Database Table wsnnnnnnnnnnnmnneennnnind9
Open SQL in ABAP ..
Test Output of an Internal Table
How to Get to Know the Properties of a Database Table...
What the List Output with the Write Statement Looks liKE ww.
Test Output of an Internal Table 2: A Dynamic Way to Output Any Internal Table.
Test Output of an Internal Table 3: The Object Oriented Way wununmmunmunnnnennnnnnnnnnnin SS
‘The Whole Code of the Three Alternatives - An Overview...
‘Summary.
GETTING MORE FAMILIAR WITH THE ABAP DICTIONARY
PARAMETERS and the Selection Screen ..
From the ABAP Dictionary to the Data Browse!
Data Element, Domain, and the Way They Inter
At Last: The Source of Our Search Help...
‘Summary.
DEBUGGING IN ABAP ....ssssssesennsee
Defining a Custom Structure in a Program.
A Useful Addition to the SELECT Statement.
What Is Wrong With Our Program ~ We Start to DebUg. inn
cunnennnnnnnnnnennnnnnnnnnsns dO
AA
A
42
sunnannnnnnnnnnnnnnannnnnnsnnndS‘The New ABAP Debugger - A Short Overview.
Debugging Our Program
‘Some Words on Efficient SQL Programming
How to Use the ABAP Language Documentation Efficiently
GET YOUR PROGRAM UP TO SPEED - OVERVIEW & INTRODUCTION
The Programs to be Analysed... suse
ABAP Runtime Analysis: Tool & Procedure.
THE FOUNDATION OF AN APPLICATION - CREATING THE DATABASE TABLES ..snnnnsnnnnnsnu53
The Contents of this Blog in Some Detai
The Concept of a Client: A Key-Player in the SAP World of Business Programming 55
Defining the Data Elements ....:nnnnsninnnnnnnsnnnnnnnenninnnnnennnnnnnnnnnannnnseS
Creating Database Table YACCOUNT...
Providing Some More Check Table:
‘Summary
HOW TO DYNAMICALLY CREATE TEST DATA FOR OUR DATABASE TABLE.
The Basic Principle of How to Create the Entries Randomly.
How to Fill Database Tables in the Data Browser ..
Looking at the Program Itself...
BREE
sunnennnnnnnnnnnnnnnnnnnenssnne AB
&
sunnnnneuneennnmnnancnnnnnnennennnnnninnnennnnnn dS
&
Running the Program 68
The Complete Program Code 69
YOUR FIRST ABAP OBJECTS... .sssnnse
‘STARTING WITH WEB DYNPRO FOR ABAP 75
Create your first Web Dynpro Component 75
Model View Controller and the Context.. 76
Data in the VieW .unmmnnnnniennnnnnniennnnnnnin nmnnnnnnnnnnnnnnannennnnnnneT®
Defining the View Layout
A First Test.
Bringing Life into the Component
Conelusion.
86WHY AND HOW THE SERVER MATTERS TO YOU AS A DEVELOPER: SERVER ARCHITECTURE AND
WORK PROCESSES
In general, you develop on a central server in ABAP. That is why the server matters to ABAP developers
from the very outset. In this weblog | explain the three layer architecture of the SAP NW Application Server
ABAP and the basics of how users are distributed on work processes. The result of this architecture is a
highly scalable and robust server.
ABAP Application Server for Newbies - Why and How the Server Matters to You as a Developer
Usually as a developer in a language like C or C+ you need not care so much about the server. It might
only matter to you if your program should run on a server in the end. When you are developing in ABAP
things are different in this regard. In this weblog I will explain why the server concerns you from the very
‘outset and why, consequently, you need to have some knowledge about the SAP NetWeaver Application
Server ABAP. And this is what | want to provide you with in this blog: some basic information on the SAP NW
Application Server ABAP.
Developing on the Server
For those experienced with other programming languages like C, Java, or Visual Basic working with ABAP
offers some features they might not be accustomed to, The structure of the development environment for
ABAP is different from probably everything that you might have encountered so far: In ABAP, you program
‘on the server from the outset. You do not develop the programs locally on your PC, nor do you store the
‘sources in a versioning system or deploy the programs on the server at a later stage.
In order to program with ABAP, you therefore require access to and developer authorization for the SAP NW
Application Server ABAP. You write your programs using the ABAP Editor of the ABAP Workbench and the
tools integrated there, which are also part of the server.
However, the SAP NW Application Server ABAP not only contains the programming environment with its
tools and utilities for supporting the software lifecycle. Developing with ABAP is closely connected to the
server in another respect: Once you activate your source code, platfarm-independent byte code is
generated, which the runtime environment interprets for the program execution. And this byte code
‘generated from your ABAP program runs on the SAP NW AS ABAP. Usually many developers are working
on the same server.
This way, a problem known to all developers in large projects does not even arise: No quality manager
needs to care about providing a system on which to deploy the programs from different developers and
where to test the interaction of the programs from different developers in a project. Everything to accomplish
this, is already done, and you as a developer already have your programs in the right piace: As soon as your
source code is activated the respective development object is visible on the central system. So the principle
in ABAP is: Development on a central server.
You need also not care about checking in and out your sources in a content management system. The whole
persistence and administration of different versions of your sources also happens transparently to the users.
Pushing the Save-button in the ABAP Workbench stores your program in the database. You retrieve it by the
program name: There is no fumbling with program files in ABAP. Again the server does it all for you.
By the way, this is a typical experience when working with the SAP NW AS ABAP: Many things you need for
business programming are provided by the system. The ABAP server does a lot of services for you in the
background that developers or quality manager usually have to care about.
‘The explanation for these conveniences is the fact that the organization and structure of and the technology
behind the development process in ABAP is different. Some these features need getting used to, but after a
while you will ike them because thanks to them you can concentrate on what your job really is about:
developing business logic.
Itis for this reason that you must take into account the architecture of the environment in which ABAP
programs run when designing and developing these programs. For this purpose, you first require some
information about this architecture.‘The Three-Layer Architecture
‘The SAP NW Application Server ABAP consists of three layers: presentation, application, and database. The
database layer of a system is made up of a central database with a database management system and the
database tables. It not only contains the user data, but also the entire program code of the SAP NW AS and
application programs, all administrative data, and Customizing settings. The programs you develop are
stored in the database of the system.
The application layer lies between the database layer and the presentation layer. It consists of one or more
application servers (more than 100 servers possible) and a single message server, which is responsible for
‘communication and load distribution within this layer. The programs that process the business logic of an
application and all the development tools, such as the ABAP Workbench, run in this layer.
Work Processes in Some Detail
Technically, the actual processing takes place in work processes, which represent processes of the
operating system. A fixed database connection is assigned to each work process. For you as a developer
this means: You always have a database connection at hand. No need to get a database manager, to open,
handle and close the database connection. The whole database handling is done for you in the background
by the server.
‘There is no fixed assignment of users to work processes. A lengthy user session can utilize different work
processes sequentially, and one work process is used by different users consecutively. Stil the state of your
program is Kept. The context of your work process is rolled in as soon as your program is processed and
‘once the work process returns a result, your context is rolled out. Its this s0-called roll area that contains all
the data and programs that are currently processed by a user.
This architecture makes for robustness and scalabilly. Itis robust because every user has a work process of
his own, for the time his program is processed. All that can happen in the worst case only concerns the work
process your program currently occupies. There is no such thing like crashing the whole engine in ABAP by
a severe syntax etror in your program,
‘The way user requests are distributed to work processes combines the advantages of stateful and stateless
‘communication. On the one hand, a user does not occupy a process for a long period while he might not be
doing anything. On the other hand, the Dispatcher (within the server) knows and remembers the identity of a
user over time: This way each time a user session gets processed its context is known.
To give you a better understanding of this mechanism | will present you an example of how a user of a
particular application is assigned to different work processes at different points in time when performing
different steps in an application. To avoid one possible misunderstanding from the outset: In general, one
request is processed Within a single work process though itis possible to write programs in ABAP that
distribute cifferent costly tasks on several work processes (such as, for example, several large selects on the
database if they do not depend on each other)
Let us suppose a loan officer, let us call him Jones works with an application in the office: First retrieves the
table of debtors in a particular region. His request is processed by work process 4 (picture 1). But, of course,
he might get any other work process that is currently free.Dispatcher Eins
Fs
s
If the request is processed the result is sent back to the user. The roll area that keeps the state and data of
User 1 is rolled out and the work process is freed for requests of other users (picture 2). As long as user
Jones does not interact with the application he dos not occupy any work procass. By the way, the other
users in our pictures are assigned to other free work processes in the same way as user Jones is. But this is
‘not shown in the picture, as I want to keep the focus on the way user Jones is assigned to work processes.
Next our loan officers want to get the details of a particular customer. He gets assigned to work process 3
and his roll area in the state he has left its rolled into this work process (if there is not much traffic on a
server, you will in general stay into the same work process, because the server tries to minimize the cost for
rolling-in and —out, but this are optimization details, and | am interested here in the general mechanism),
Again the work process is freed after the request is processed (picture 2),
Next the loan officer sets a new credit limit for Smith and saves it. Again he gets another work process. His,
roll area is rolled in, the request is processed and the data is saved on the database.This way a user does only occupy a work process when the application he uses actually sends a request
Due to this mechanism itis possible to have far more users than work processes on an AS ABAP. So a
typical SAP ERP System running on an AS ABAP server might have 50 work processes and 500 users
currently logged on (This is, of course, only an example to show the ratio, the actual number of work
processes on a server depends on many technical details such as the CPU power of the servers, the RAM
that is available, what kind of applications the users typically are running, how many users are logged on
simultaneously etc.. The number of work processes for a system is determined in the profile by the system
administrator).
‘The Three Layer Architecture Continued
‘The kernel and the Basis services make up the part of the application layer that is specific to both the
operating system and the database. They ate responsible for user and process management, database
access, communication with other systems, as well as system monitoring and administration. The software
processes or virtual machines, that interpret the platform-independent byte code as operating system-
‘Specific machine language commands, run in the kernel.
‘The presentation layer represents the interface with the user and is responsible for the screen display. This
layer receives user entries — that is, mouse-clicks and keyboard input — and passes them on to the
application layer. Furthermore, it receives data from the application layer and displays it to the user.
When writing a business application you should use Web Dynpro ABAP as a siale-of-the-ait user interface,
‘A Web Dynpro ABAP component may run on the same server as the underlying business logic. An ABAP
Web Dynpro application is displayed in the Browser or the Business Client.
‘The ABAP workbench and all the other tools you need for developing use the Dynpro technology (Dynpros
are the classical user interfaces of most ABAP-based SAP programs and run in the SAP GUI). In our demo
programs in this series, we will sometimes use classical Dynpros to input and outout data as a handy device
just 2s you use the output to the console in Java Tutorial. It saves you time if you want to test a backend
program and the real user interface written in Web Dynpro ABAP is not yet available or you want to test the
business logic apart from the presentation logic. The real user interface of your programs should always be
developed with Web Dynpro ABAP.
Presentation Layer oe eo oe
ne a a a
+ Client-Side
Presentation Browser | SAP. NW Business Client |
Application Layer | | |
+ Presentation
Logic Dispatcher
+ Business Logic Buffer
‘Work Work Work
Process Process: Process
Database Layer | | |
DB DB DB
Process Process Process‘The purpose of this division in three layers is high performance and scalability. The layer division is purely
logical. It does not imply over how many machines the system is distributed. in fact, all thrae layers can
actually run on a single computer. For demonstration purposes, such as you have just done it in the case of
this demo system, itis possible to install all three layers on a single PC. However, in the case of large,
production applications of customers, this is more of a theoretical possibilty, since it would counteract the
scalability of the three-level architecture,
Summary
Now you should have understood that you always work on the server when developing in ABAP. It is for this,
reason that I have explained to you the basics of the three-level architecture of the server and the way users
are assigned to work processes. In the next blog I will explain the impact of development on a central server
‘on the developing process. Again | will focus on an example that is intended to illustrate a basic mechanism.
This time you will lean some details about what happens when you activate your program,
MANY DEVELOPERS ON ONE CENTRAL SERVER - HOW DOES IT WORK?
In this blog | show you one big advantage of central development in an example: You will always use the
latest sources as soon as they are activated instead of developing against proprietary source versions that
you have on your PC and not updated for weeks. This is ensured by the technology underlying the
development process in ABAP. A simple example illustrate how this works.
‘Many Developers on One Server — How Does It Work?
In the last blog | have explained some basics about the ABAP server: Let us now combine what | have
explained about the three-layer architecture ofthe server and the fact that developers always develop on the
central ABAP server in real-world projects. As in the last blog | wil provide a ittle example to illustrate what
happens when you activate your program:
Deviled Dev Clant Dev Chant
Central
System =
As I have told you, there are many developers developing on the same server. Each developer has his own
“instance” of the development environment on the server within his roll area. You can compare this to many
clients working with different instances of a class.
Technically the development environment comprises a set of programs such as the ABAP Editor, the ABAP
Workbench or the Class Builder plus a lot of other tools to support the development process. An ABAP
developer works on the client and has the classical SAP GUI that presents the user interface of the
respective development tools, The programs under development are stored on the central database,
‘The program a developer writes within development client 1 is only visible to this developer as long as the
program is not activated.[An inactive version
‘of a program is
nly visible to its
eveloper
‘As soon as the developer activates a program itis visible on the whole server. This means, of course, that
‘other programs can access it.
Developing on a Central Server - The Way to Keep Your Sources in Sync
‘One great advantage of this organization lies in the fact that incompatibiities will become visible very early.
Let us refine our small sketch a bit to show you how this works in detail: Let us assume that program 4 uses
class 3 (developed by development client 3). Remember: Its the active version of class 3 that is used.
Inactive versions are not visible to other users (in fact they are not visible to any other development objects)
Meanwhile there is @ new inactive version of class 3 under development,
\
Program { Program 1 cals
sctivevarion peel cwe)
=w eveloped by Dev
CoseSid Client 3
active version
‘As developer 3 is not very experienced he changes the interface of the method that is called by program 1.
Let us assume he renames the parameters of the method. Unaware of the consequences of this
incompatible change developer 3 activates his class. What happens? The old inactive version becomes the
new active one and ... there is a syntax error as soon as program 1 (the client of class 3) is recompiled:ov Catt Dov Giet DovCient3
\
Progen Dev iient 3 has
actveversion activated a new version
<3] ‘of lass 3, which is
incompatisie withthe
ee ‘ell in program 1
activeversion
So you see: As | have already explained, thers is no need to maintain a dedicated test system if the
developers belonging to a project develop on the same server. So one typical problem of local development
does not occur when you develop in ABAP. Instead of developing against proprietary source versions that
you have on your PC and not updated for weeks, you will always use the latest sources as soon as they are
activated. This way, inoompatibilties will be realized in a very early state.
‘Summary
| hope, by now you have understood what is so good about many developers working on one central system.
‘Once you activate your program itis visible to everybody else on the system, and possible conflicts are
detected in a vory early state.
NAVIGATION IN THE APPLICATION SERVER
In Part 2 of this blog series, you logged onto the Application Server as 'BCUSER’. From this starting point,
this blog explains how to find the functionality you need,
[ Menu Est fortes Extgs Sytem Heb
9 B ee she HnnHn
Development relevant
Item No.1 is a Command field for the ‘Transaction Code’. This is a shortcut to the transaction (functionality)
you want to execute, Position the cursor in the field and press 'F1' to display the documentation.
This is a general feature of the Application Server for online help on input fields,In Part 2 of this blog series you were asked to enter 'SE80’ in this Command field, which takes you directly to
the ABAP workbench, This works only in the logon screen, in all other screens you have to add '/ as the first
character and a letter as described in the documentation. For example, if you add an ‘o' (as in ‘other’) before
the Transaction Code, a new window will be opened for that transaction.
To the right of the Command field, there is an icon to display a history of commands used. Just click the icon
and a pull down menu appears with all the transaction codes you entered so far.
lem No.2 are two buttons in the toolbar. The left button opens a new window, which is the same as Yo’ in the
‘Command field. The right button is for creating a shortcut on your desktop that will start the transaction you
are currently in. You also can create a shortcut to any other transaction.
Item No. 3 is a folder for your favorite transactions. Since it is not easy to remember all the transaction codes
you can collect the ones you'd lke to use more often in that folder. To make it more convenient for you, the
folder displays the title of the transaction instead of the transaction code. Click the folder icon to open the
context menu. ‘Insert transaction’ adds a new item to your favorites. You can do the same thing by clicking
‘Favorites’ in the menu bar.
It you are in a screen and you don't know the transaction code, just click the ‘System’ button in the menu bar
and select ‘Status’. A new dialog box will appear.
fae) msttin timber [RETR
Progam (Git) SAFURTEE] ue Boreron 31.49.59)
ost [ama roc | uncote sytem es)
This dialog box shows all the system information for your session. The transaction code used in the
Favorites folder can be found under Transaction’.
‘One useful hint: In the Favorites folder and in the SAP Menu you can display the transaction code in the
beginning of each line (see screenshot below). For that, cick on ‘Extras’ in the menu bar and select ‘Settings’
and check for ‘Display technical names’.
Item No. 4 is a navigation tree to the different transactions. Just open up the SAP menu, click ‘Tools’, open
the 'ABAP Workbench’ folder, open ‘Overview folder, and then you'l find the ‘Object Navigator’ item.TH tems est favors Gms Seta Hee
oe ee she onan an:
(ec
RE Bibbs vs
Double-click that item, and the "SE80" transaction is started.
ce the ABAP Trial Version is only the Application Server, there are no business-oriented transactions in
the navigation tree.
© otek ek Go vit eat ee
ol Te
nn oF
[Acces
© © | £0 eee ome
(Pwe pepostoy
[er ones
‘There are three buttons in the middle of the toolbar, all for navigation purposes. They are highlighted when
active.
The green button is the "Back’ button, which goes back to the previous screen.
The yellow button is the 'Exit’ button that interrupts the transaction and takes you straight back to the entry
screen.
‘The red button is the ‘Cancer’ button that stops the transaction, but will not always return you to the entry
screen,
To close the session, just enter ‘inex’ in the Command field and press ‘Enter’ or the green ‘OK’ icon to the left
of the toolbar. All open sessions will then be terminated without any dialog.A FIRST ‘HELLO-WORLD' PROGRAM
After you have learned how to get the ABAP Object Navigator (transaction SE80) in the last blog it is now
time to do it. And we will do it here and now in this blog. We will write a "Hello World” program
Again, you will recognize a principle that | have explained in my blogs on the server. The ABAP development
environment offers you a lot of benefits for fee that take quite some extra work when developing in other
languages. When developing in ABAP, your program becomes part of a large mechanism that helps to
manage and organize development objects in a system landscape from the very outset. Let my elucidate this
by an analogy. Creating a development object with C or Java is in a way like writing a text with a word
processor: You write it, save it where you want and that's it. In contrast, developing a program in ABAP is
like writing a text with @ content management system where you are forced to create a document as part of a
larger context with a number of default attributes, which help to pigeonhole your document within this
system.
The main structure is pretty simple: Every development object in ABAP belongs to a package. In general,
every package has a property that determines to which other systems the package plus its content is
transported if the package plus its elements are assigned to a transport request. The only exception to this
tule is the package Stmp which is made for local developments. The content of this package is not
transported to any other systems. In this blog we will create a program in this package for local
developments, while in a later blog we will create a package that we will use as a container forall elements
we will create in other blogs.
The Repository Browser — The Central Place in the ABAP IDE
First we navigate to the transaction SE80 and have a short look at what we see there:
Gla Be Oak
ena
‘The Object Navigator is the development environment for the central editing of all development objects. We
call these objects repository objects. This includes all ABAP programs of AS ABAP and all their components.
However, there are many other repository objects, such as global data definitions in the ABAP Dictionary,
global classes, or XSLT programs. Together, these development objects in the ABAP Workbench form a so-
called repository. This repository is a special part of central database, which, instead of customer data,
comprises the programs of AS ABAP itself.
The buttons in the upper part of the navigation area allow the selection of a browser. You can configure in
Uiiies - Settings which browsers are presented for selection with buttons. The browser we will generally be
using is the Repository Browser (1). Itis the default setting of the Object Navigator and also the most
generic browser, which provides an overview of all important repository objects sorted by different criteria.You access the repository objects through the Repository Browser by using so-called object lists. You must
select such an object list in the dropdown list box, which is displayed in the navigation area under the
buttons. In our screenshot you see the Jocal objects (2) of user Dcuser. As we have not created any local
objects by now, the area that shows these local objects is still empty (3). By choosing another entry in the
dropdown list you can see other objects such as package, programs, function groups etc.
Packages
As already mentioned above, every development object must belong to a package. Packages organize
development objects and handle their connection to the AS ABAP software logistics. That is a package is like
a folder in a way. As for the software logistics, in ABAP your objects have to be assigned to @ specific
“software transport track” and a particular transport request. As soon as you release the relevant transport
request, your object will be transported to the next system on that track. | will explain in another blog more
technical terms what these tracks and transport requests look like in detail
You can view a package plus allits elements also in the SE80. Just choose the entry Package in the object
list of the Repository Browser, enter the name of the relevant package in the input field below and press
"Enter". Then all the objects of that package are displayed
‘A Package for Local Objects
We will make do with the default package for local development for our first program. In this case we do not
need to create 2 package and need no transport request. As already told, every AS ABAP contains a
predefined package named STMP, in which you can create local practice and test programs, that need not
be transported to other systems. Each user has a local package of his own in a system. If the SE80 does not
already show the space for your local objects, select "Local Objects’ in the Repository Browser, enter
"BCUSER’ in the input field under the dropdown list box, and press “Enter”. As result the Repository Browser
displays all the development objects in this special package, which were created under your user name,
‘Hello World’ as a Local Program
To create a local program we select "Program" in the Repository Browser and enter the name
z_he11o_word_local in the input field below and press "Enter” or select the glasses icon.
Hore you see a very helpful feature of the ABAP development environment. If you want to edit an object that
does inot exist, in general the system asks you if you want to create the respective object. We confirm and
get to the next dialogue window.
By the way, you should note and always remember as from now that repository objects created for
‘customers in customer systems have different naming conventions than those that apply to Sap’s own
programs: A customer must use "Y” or "2" for the first letter, or the abbreviations reserved by SAP for
the customer's company. Our Trial Version is set up as a customer system in which the user BCUSER is
registered as a customer. Therefore the names of the objects we create must start with a *y" or"2"
In the next dialog window we deselect the item "Create with TOP Include", confirm, and get to the next dialog
window.las canes ee |
In here you can define the properties of the new program. This is important, since the program properties
determine the execution of the program in the ABAP runtime environment. One of the most important
program properties of an ABAP program is its type. From the list provided, we want to select the type
“Executable program for our simple Hello-World- program, and change or add no other properties. In
particular, ensure that the properties "Unicode checks active" and “Fixed point arithmetic” should always be
checked.
In the next dialog window we select "Local Object” and, thus, do not need to input a package name. And
there we are. Now we have done everything we need to input the code of our first program.
Note that in our blogs we will be using the new frontend editor available as of SAP NetWeaver 2004s, which
like all modem editors supports syntax highlighting and so on. To configure this editor, select Utilities -
‘Settings - Frontend Editor (new). To configure the editor for your own preferences, you can select the icon in
the lower right-hand comer. Up to and including Release 6.40 (SAP NetWeaver 04), you will stil need to use
the old frontend, which provides a lot less support for programming.
To go on, we double-click the program name in the object list of the SEBO
[Fomem 1)
[ZHELLo-WoRLD.LOcL
On the right the editor opens. In it you see the framework predefined by the ABAP Workbench. This syntax
consists of a few lines of comments, and also contains an initial statement named Report.
+e Report 2
+6
REPORT 2_CREATE_EXAMPLE_DATA.
-REATE_EXAMPLE_DATA‘The first seven lines are comment lines, and the eighth ling is a statement
Comment lines are introduced by an asterisk * in the first position. The rest of the line is arbitrary and is
shown in a different color by the editar. To mark only the final portion of a line as a comment, you can use
the character"
‘As we want to input some code, we have to change the program. In order to do this we have to go to the
change mode by pressing the respective button:
os} «H eee ane
Below the report-statement we enter:
REPORT Z HELLO WORLD LOCAL.
data output_text type string.
output_text = "Hello World’.
write output_text. “obsolete statement
‘Admittedly, this listing needs some beautifying. The tool to do this is the Pretty printer. We configure the
Pretty Printer at Uiilies-Settings-ABAP Ecitor-Pretty Printer and select Convert Uppercase/Lowercase and
below Keyword Uppercase. Next we press the Button Pretty Printer and our program now looks a bit nicer as
all the keywords are now in capitals.
To run the program we press the icon:
° sa eee Bae
ABAP Editor:
e5\oRee a
A250 SR me
Now let us spend some words on the syntax ofthis litle program. Though this program is as simple as it
could be, | still want to add some comments on the general way ABAP programs are structured.
Every standalone ABAP program, that is, all types of programs except for so-called include programs, start
with an introductory statement. In our first program, the introductory statement is REPORT. This designation
is historical and expresses the fact that an executable program was once exclusively used for reporting.
Here, however, it suffices to know that our first statement introduces the program z_helio_worl
1
After the introductory statement, every ABAP program follows a fixed program structure that divides it into
two parts:
‘+ a global declaration part
‘+a procedural part
In the global declaration part, which directly follows the introductory statement, deciarative statements can be
used for definitions and declarations, which will be visible and applicable throughout the entire ABAP
program. Examples of objects that can be declared or defined here are data types, classes, and data
objects. For larger programs, these declarations are generally made in a special include program, the "top
include,” which is supported by the ABAP Workbench and inserted at this position. After the global
declaration part comes the implementation part, in which the actual processing logic of the ABAP program is,
implemented‘The keywords and statements used in this program do not need many explanations. We declare a field of
type string, assign a value to, and output it.
Note some important information on the write-statement. The write statement outputs a list and itis driven by
the classic SAP Dynpro technology which should not be used to write applications with a state-of-the-art user
interface. You should use Dynpro-based Uls only in test-programs if you want to outout (or input) some
values in a quick and dirty way.
You can compare the write-statement to the output to the console in Java. Just the same way you should not
use the write-statement to output something in an application proper. The right way to do this is to use a Web
Dynpro ABAP application as a user interface and to encapsulate all the logic of your programs in function
modules or classes. Stil, we will use the write-statement sometimes in our blog series in order to output
some results of to input some values @ program needs. And this is the way, you should use this classic, but
by now obsolete UI technology yourself: Use it (only) to test your business logic separately from the
presentation logic.
In order to show you, how the syntax check works in ABAP, let us change the Keyword DATA to DTA and
press the Check Icon
eo19Rm - AOU OG rom
At the bottom of the editor we get the information:
“The statement ‘DTA" i ot expected. A correct sia statement 6"DATA™
Fe “OUTPUT_TEXT& unkown
aid “OUTPUT_TEXT a unkpown,
This check gives you precise information as to in which line the error is. In case of a slip of pen lke this, the
system can make a reasonable guess as to what you wanted to type in, and proposes a semi-automatic
correction.
Next we save our program by pres
ing the Save button
o ——_> fijece ane
_ AGAP Etttor: Change Report Z_fHELLOWORLD_LOCAL
© ORES 6786 A201 G8 mn
The real storage of the program in the database is done by the system. You need not worry about it. All you
need to retrieve the program is the name. So there is no fumbling with files on the Web AS ABAP.
I-you remember the blog about the activation of programs, you probably know that this program is stil not
visible to other users. Why? There is no active version of this program. A version of a program that is not
activated is only visible to the developer of this program.
In order to make our program visible in the whole system, we activate it by pressing the Activate button:° “<8 @eeisne
A250 68 ram
Now our program is visible to every user in the system.
‘Summary
Now you have learned all you need to develop a simple program in ABAP.
+ You know that you need a package for every development object. If your object does not need to be
transported to another system the package $tmp for local development will do,
* You have seen how to find your way in the Repository browser of the SE8O and how easy you can
create a new program. Just input the name of a new object and the system asks you if you want to
create it
+ You are able to save, activate, run, or check a program for syntactical correctness
In other words, now you know the basics, and we can go on with something more complex in the next blog.
Special thanks to Horst Keller and the Galileo Press. By courtesy of the author and the publishing house
| could reuse some explanations of ABAP concepts from the lately published book: ABAP Objects. ABAP-
Programming in SAP NetWeaver in this blog. And | will also do this in the following blogs of this series, as it
is faster sometimes to reuse an explanation of some ABAB basics to some extent if it fits in the structure of
the blog
In case, you want to know anything about ABAP in more detail than we can present here in our blog series,
just consult the book, On 950 pages it covers, | feel temped to say, almost every conceivable detail of the
ABAP language.
CREATING A PROGRAM AND A PACKAGE - AN INTRODUCTION TO THE SAP CHANGE AND
TRANSPORT SYSTEM
This biog is about how to create a transportable package, how to create a program within this package, and
how to get the connection to the integrated software logistics of the server, the SAP Change and Transport
‘System (CTS) right from the beginning. Doing this you will get a grasp of what a mult layer system
landscape for development is for and what the concepts of a transport layer and a transport requests mean
in this context. This will provide you with a basic understanding of the complex world of software logistics in
the ABAP world
Unfortunately, I must confess it, you need a lot of dialog windows to define the relevant properties of a
package and a program. And clicking through these windows is a bit of a bore. No kidding. And the worst is:
It will take so much time to show you what attributes the package and the program need and to explain why
they need these attributes with which value that | have decided to postpone any program code to the next
blog
But still | believe that you need the information | present in this blog. And | will ry to make the long walk
through many dialog windows more interesting by adding some more basic information to the CTS, But do
not expect too much from it. The world of SAP CTS is complex, and | can only scratch its surface. But let me
first spend some thoughts on why we are not content with our demo programs in the package $tmp for local
developments‘Some Words of Motivation: Why Your Programs Deserve Better than Package Stmp
Development is not only about devising cool patterns, algorithms and coming up with a hip design. This is
the bright side of developing. What | show in this blog is, in a way, the monotonous housekeeping of the
developer. It is not cool, but it has to be done, if you will not end up in a mess with your cool programs. And
Yyou will get rewarded for it. By assigning your development objects to a package and a transport request with
the right properties, you will keep your developments tidy, from the very outset
This proper structuring of development objects becomes particularly important if you work in a team on a
development project. When just developing on your own at home, this assignment of your objects to the
software logistics is not strictly necessary and means some overhead expense for you. Nevertheless, you
might also profit from it when just working on your own. To retum to our analogy of housekeeping: Avoiding
producing a mess is more important if you share an apartment, but itis not wrong if you live on your own
either. The same appiies in analogy to developing on your own with our demo version at home. There is only
‘one default package Stmp for local development for each user. And you need more packages to manage a
lot of different developments. Just imagine you had all files on you PC in one folder. In the same way, it does
No good to have all your development objects in your package Stmp.
But there is an even more compelling reason to use a transportable package as a container for your
programs right from the beginning: You cannot even export local objects to ail. (In fact this unconditionally
{rue only for objects in package Simp. They can never be transported. Objects in a local package can be
transported in a special type of transport request: a request for the transport of copies. But this type of
request can only be created in the Transport Organizer, SEO9 and not from the dialog windows provided by
the ABAP Editor in the SE80. As | do not want to introduce the SED in this blog we have to make do with a
normal transportable package).
‘As ABAP development objects are stored in the database of the system you cannot just copy a program file
if-you need it elsewhere. You need to export it to transport files first, and then you can import these files into
any other application server ABAP if you have access to the file system of the underlying physical server.
This is the motivation and an explanation as to why even solitary developers at home should not be content
with developing in package Stmp. Your programs deserve better. They should live in a transportable
package.
Creating a Package - the Chance to Get in Touch With the CTS
This walk through a lot of dialog windows, cumbersome as it is, might stil be interesting to those who have
some experience in handling these things. In a way, this cascade of dialog windows resembles a wizard
riven activity. You may get along in these windows, and still not really know what you are doing. This is the
way I got through some wizards. | was happy to be out of it, and hoped that | had fed the wizard the info it
needs and that the wizard would not take revenge on me: Maybe due to my limitad knowledge | had
provided some syntactically correct data that nevertheless did not lead to a semantically meaningful
‘outcome.
Since the input in these dialog windows connects your development objects to the SAP Change and
Transport System and this powerful system is really complex, the odds are good that you do not really know
what you are doing there, though you get along quite successfully in these windows. In any case, if you are
‘one of those you will probably profit from this blog.
Creatir
19 a Package - the Details
By creating a package we are laying a cornerstone for all subsequent developments in later blogs, as we will
use it throughout all parts of our litle demo application. Moreover you learn the litle steps you have to take
before you can start typing in the code, whenever you need a new development object. After this blog we will
simply presuppose that you know how to perform these steps, and if we create other development objects
such as a global class, a function group and a function module, a database table or a data element in the
ABAP Dictionary, we will only explain what is different from the procedure explained in this blog.As packages themselves are also repository objects, which can be edited using the ABAP Workbench, we
Use this tool to create our package. To do this, we select the package object list in the Repository Browser,
and enter the name y_abap_demo into the input field below.
ee yeODU ETS Ae ew
Pade ¥_ABAPDOHO doesnot est. Do ou want
@ srcenersecosce
fie 1) Se) @) Ge)
‘Objet nae
* Be STHP HVA
‘Again you see this very helpful feature of the ABAP development environment: If you want to edit an object
that does not exist, in general the system asks you if you want to create the respective object. We confirm
and get a dialogue window:
Sertbepo cone wag
In addition to a short description you must specify the Application Component, the Software Component, and
the Transport Layer. In order to input the software component, we select suitable entries from the selection
list, which is displayed after pressing the input help key (F4). As already mentioned, this value help is an
important and extremely helpful feature, and you find it throughout the SAP AS ABAP and all ABAP-based
applications if their developer has provided it. So let me show you in the next figure how this value help
works. You select the field with the label Software Component, enter (F4) and you get the value help if itis
provided:In our case the values you see are created by the system administration when the system was set up: Itis a
list of the software components that are available in the system. The software component HOME is meant by
SAP for customer development and equipped with all the tools available for this. We select it and confirm by
selecting the check mark (1). In case a list in a value help is very long, select the telescope icon (2) and start
a search.
The Concept of a Transport Layer
‘The transport layer is an important concept. It refers to the transport path a package should take in a system
landscape. The usual landscape has a least three layers:
One Transport Layer
The basic idea behind this layered system structure is simple: You develop an object in the development
system and test it in the consolidation system. When all tests are successful you transport your tested
development objects to the productive system. The SAP CTS enables you to define this path as an attribute
of a package. Due to this feature there is no fiddling about with the destinations of development objects. You
just define them in the properties of the respective package in the beginning,
How useful the concept of a transport layer is, becomes in particular evident if you have, for example, one
development system for different productive systems.Two Transport Layers
In the landscape shown in this figure it makes sense to define two transport layers, one for a path from the
development system over consolidation system 1 to productive system 1 and the other layer that leads from.
the same development system to consolidation system 2 and productive system 2.
Due to this organizational structure development objects destined for productive Systemt are from the very
outset in a different pigeonhole than those for productive System 2
‘The arrows in these figures only show the direction and the destination of the relevant transports. The
transport layer by itself does not transport anything. You need a transport request to get something
transported. Maybe an analogy can help to expose the way the concepts of a package. a transport layer, its
respective destination system, and the export from and import into a system are interrelated:
The transport layer is like a subway line and the transport request is like the tram. Assigning some object to a
transport line is like buying a ticket for this line, while assigning an object to a transport request is like
actually puting it on the train. Exporting the transport request is like the train leaving the station, and the
import is the reverse.
‘Some More Basic Concepts of the SAP Change and Transport System
Let me show you an example to help you understand how a program BB in a package 2_ny package
assigned to transport layer DeCoPro and transport request 1 is transported through a system landscape with
three layers (the names of the transport request and the transport layer are simply chosen for didactic
‘reasons and irrespective of existing conventions and technical constraints). The figures just concentrate on
the entities mentioned: The program, its package. the transport request and the transport layer.
eaten4. Our Program is assigned properly to the package, this in tum is assigned to a transport layer, both are
assigned to the same transport request, that is a transport request that has the same destination as the first
destination defined in the transport layer. So far nothing has been transported. The transport is not released
and you can stil change it, that is, you can, for example, assign other objects to it or change programs in the
request.
2. The transport request has been released from the development system and been imported into the
consolidation system. As you see, there are copies of program BB and its package in the relevant
destination system after the transport. And this makes sense: If the transport moved the program, many
transports would empty a system, and above all, you could no longer change a program after it has been.
transported out of a system. The released transport request is in the consolidation system too, and it also still
exists in the development system. In fact, this is only the logical perspective. Physically the objects in a
released transport request are written to a file, and this fle exists only ance. When it is imported into another
system, this system gets a reference to this file.
3. Next after the tests in the test system are completed successfully we import the transport request into the
productive system,
Again, physically the productive system just gets a reference to the exported transport request in the file. So
the arrow between the systems only expresses a temporal and logical sequence. | stil decided to use these
arrow as this is the typical way to sketch the structure of the transports through a SAP system landscape.
The physical structure (see figure below) is lke this: When importing the Transport Request 1 into the
consolidation and the productive system these systems just get a reference to the export files of the relevant
transport request:At this stage of the explanation, you might ask yourself what happens if you have to change program 25 for
some reason, Well, lel us suppose in the productive system a branch of your program is executed that has
not been tested s0 far, and the program does not behave as expected. So we have to change it, and we do
this in the development system. This is what the division in the three layers is for. As the name suggests, in
general, you only develop in the development system. Of course, there are some situations when you better
correct errors in the consolidation system (for example if this system gets programs from different
development systems and the error does not appear in the development systems, but only when the sources
from the relevant development systems are activated and run on one system), but then you should change
the relevant development objects in the consolidation and the development system. Otherwise you will easily
{get inconsistencies between these two systems. But in our example We can stick to the general rule to
develop in the development system,
In order to change the program, we need to assign it to a new unreleased transport request:
There we are, We have assigned the program to a new unreleased transport request, which can still be
changed. A package is usually only transported once, except for the case that the package properties have
changed. For this reason we only assign the program to a new transport request and not the package. But
what happened to the previous assignment of the program to transport request 1? Nothing. The point is
simple: A development abject can be assigned to one unreleased changeable transport request only, but,
in addition to many released transport requests.focus)
my package
But why is it that the assignments to the old, released requests do still exist, if they are not changeable?
What are they good for? Probably you guess the answers: This is for matters of versioning. Whenever a
transport request is released an actual version of the program state at this time is stored. You can both
return to this old version in case you need to or simply use it to track when which version of a program was
released. Before leaving this short introduction to the transport system, let me mention that, of course in our
example we need to transport our bug fix to the productive system, before our problem is corrected there
But this should suffice by now to give you a basic understanding of the SAP Change and Transport System.
As | told you before, the CTS offers a complex set of features, and in this intro blog | can do no more than
give you a clue as to what you are doing when you fill out the relevant fields during the creation of package
and a program.
Package Building Continued
So let us go on with our example. For our demo system you should use the transport layer znsp throughout
{as already told, you also need a transport layer if you want to export a development object to a file, In a later
blog we show how you export and import development objects to or from a fle),
If you have input all values as shown on the last figure you press the Create button
In the next dialog window you have to assign your package to a transport request. As we do not have a
transport request of our own so far we create one by pressing the Create button in this dialog window and
the next dialog window appears. We input some short description as shown:Just note in this context: In a real-world development project you will always use a transport request that is
Created in the transaction SEO9 and paste this into the window with the header Prompt for transportable
Workbench Request, that is the window we have just shown, and not create the transport request by using
the Create button in this window. By using the SE09, you have more control on the transport request you get
If you just need a transport request without any particular properties, you can do it the way we do it here.
Pressing the Save button opens another dialog window:
shor Oesrpten | Request for Dano Prgect 1
(¥) BEC (own eves)
There it comes: Our first transport request. We finish the creation of our package by pressing the Create
button. And now we have done it. We have created a package of our own,
‘The package we have just created is shown in the list below the input field of the Repository Browser where
the Stmp package of our BCUSER was shown before,
In case you feel a bit dizzy by now because of the bunch of dialog windows, do not hesitate. Let us do
something similar again and pass a similar cascade of dialog windows in order to create a program in our
package.
Creating a Program Within a Package
‘So we create @ program within this package, or to put it another way, create a program and assign it to this
package. If you have completed this task you will see that these dialog windows always appear in a defined
order, and once you have understood this order, you will feel no more confused by clicking your way through
the dialog windows than by walking through a long floor with several doors,
So lot us start. We right-click on the package Y_ABAP_Demo and choose Create - Program.
aT)
Postge
aa Pacage erie
soir F
Dosis Futon coup
‘spi OecOwedoyeny | SEBO .
te rnopet ety LDetornyonet ‘
‘et Futons iss tay "
Estero anceriensenee +
Berta c
Enmarcamar .
uses Enaoeng °
Eomooeet ‘
ostotet
‘Again we are lead to a dialogue window, where we input the name of the program we want to create
y_select_f flight. We deselect "Top Include” because we still do not need a top include, and we
‘confirm. As in the case of our last program z_he1lo_word_local we get the dialog window that defines
the program properties. We confirm again and in the dialog window we see that the system already proposes
y_abap_demo as the package for our program. We press the Save buttonEm
raed poet
The next dialog window also offers little work for us. The transport request our package belongs to is already
in the relevant field,
Again we confirm and we have done it: We have created a new program within a package.
‘The procedures | have just described might look like a lot of work, but let me repeat it: After a short while it
will cause no more trouble than getting the car key, opening the car, sitting down, fastening the seat belt, and
turning the ignition key. In real life, you hardly pay any attention to these actions. In the same way you Will
create programs in ABAP. The steps are always the same:
‘+ Give the program a name,
‘+ Define the properties of the programs (in general, you just accept the values proposed by the
system),
‘+ Assign your program to a package,
‘+ Assign your program to a transport request
Outlook
Instead of a summary I want to finish this blog by giving an outlook on what we will do in the next blog. By
now the ABAP Editor has opened in the change mode and below the usual comments at the beginning of a
report you have the first ine: report y select_f_sflight. You know this already from the last blog,
From here we will start in one of the next blogs and write a program that performs the task of a typical
business program: It selects some lines from a database table that fulfil a given condition, stores them in @
container in the program, an internal table, and shows this internal table in a quick and dirty way on the
screen. We will use a Dynpro-based list and an object-oriented alternative to do this. As already mentioned,
you should use this technology for test purposes only: It facilitates a fast and easy output to the screen, but
oes not support the model-view-controller paradigm.
In some later blog we will show you how to output a table like this in a real world program: You encapsulate
your business logic that contains the SELECT statement in a global class or a function module and offer the
relevant data in a getter method. The presentation in the Ul is done in a Web Dynpro ABAP application that
accesses the relevant modularization unit that offers the data.AFIRST LITTLE BUSINESS PROGRAM
Now it is time to write a program that does something more than just output “Hello World”. In blog 7 of our
series we have done the necessary preparatory work, that is, we have created a transportable package for
all our programs and a program within this package. With some more experience you will handle this prep-
work very fast with hardly paying any attention to it, though it might look time consuming at first sight, The
‘other reason why I spent some more time on this is that it will pay if you know what your are doing when
clicking your way through these dialog windows: The SAP CTS (Change and Transport System) does not
exist for its own sake, but it has proven to be highly useful in large development projects and that is why SAP
created the CTS.
In any case, the result of the last blog will be the starting point at which be begin to write our program. You
will only be able to reproduce what we are doing in this blog, if you have the results of this blog or are able to
create an empty report, that is a program of the type report. If you have trouble doing this, just look in blog 7.
The Aim: Our First Little Business Program
‘So much for the preliminaries. So let us resume the work we have begun in the last blog. Our aim is to write
a typical business program: It selects some lines from a database table that fulfil a given condition, stores
them in a container in the program, and shows this data in a quick and dirty way on the screen. As to the
presentation of the rasult in the user interface | will show three alternatives that are easy to realize, straight
forward to understand and require a minimum of coding effort. You will probably be surprised at how simple it
is to output a result table on the screen in ABAP.
All three alternatives are based on classic Dynpro technology. That means you should use them for test
purposes only, if you need to output some result fast. Each altemative has an advantage of its own and
‘contains new ABAP commands for you: The first one is straight forward in that you see all the different
components that you output. You can use the second alternative to output any result table of a SELECT on
the screen no matter what its components are. Understanding this you get to know two important means for
dynamic programming: the field-symbol, which is a sort of a pointer and the dynamic assign. The third
alternative is based on a service ciass that needs hardly more than the name of the table you want to output.
‘The code of this gives you an impression of how object orientation is realized in ABAP.
Nevertheless, useful and fast-to-realize as these alternatives are, they are all more or less comfortable ways
to output results for test purposes. In a real-world program you use Web Dynpro ABAP. encapsulate your
business logic in a global class or a function module and hand over the data needed in the user interface as
parameters. But | think itis perfectly legitimate to use this classic technology at this stage of our blog series.
Just compare it to the output to console so widely used in Java tutorials though nobody would bother a real
end user with such a user interface.
How to Use the ABAP Documentation
‘Our example is based on the SAP fight model: This model gives a simple description of seat bookings in
passenger airplanes by flight customers and is realized in a set of database tables such as SCARR for ai
carriers, SPFLI for flight connections, SFLIGHT for fights and SBOOK for bookings. You find more
information on this model in the SAP Help Portal under this link. The SAP Help Portal contains the SAP_
documentation in different tree structures, The key node of the ABAP documentation in this portal is here.
The topies we touch in our weblogs are mainly covered under these three subnodes,‘The documents under the node ABAP Programming and Runtime Environment describe language-related
topics. Under the header ABAP Workbench you find documentation on the tools to edit objects like reports,
function modules, and global classes, on the Transport Organizer, on test tools like the ABAP Debugger and
the Performance Trace and all the other tools of the ABAP Workbench. The Web Dynpro ABAP
documentation provides a description of the complete architecture of Web Dynpro ABAP and its main
concepts. You should consult the Help Portal for ABAP topics when you have questions that are related to
tools, the architecture or the relation of concepts. For information on the keywords and syntax of the
language itself there is the system documentation. One way to access the system documentation is by
marking the relevant command in the editor and pressing the F1 button.
How to Get an Internal Table with the Line Type of a Database Table
This was a short digression to the ABAP documentation and how to access it. Let us go on and select some
flights from the database table == 1ight, in particular the flights that fuffil two conditions: The airfine is
Alitalia ang the seat capacity of the airplane is smaller than 250 seats. We want to output the result set of this
select condition on the screen. We begin our program by declaring the data we need:
DAT
ab_flight TYPE STANDARD TABLE OF sflight,
wa_flight TYPE sflight.
In the first statement we define an internal table with the line type of the database table s£1icht. The way
this works in general is simple:
DAT
ble TYPE STANDARD TABLE OF [any database table]
This declaration defines the intemal table with the line type of the database table given in the square
brackets at the end. An intemal table is the ABAP data type that is tailor made for business programming. tt
is a dynamic data field that can contain a practically infinite number of lines. You can use centrally defined
line types or define a line type within your program.tab_cot — )
ines James Miller
Now York Klaus Jones
London George ‘Smith
kairo Peter Znang
Bejing Marz ‘Schmidt
‘The figure shows a linetype for contacts (1). It consists of first name, last name and city. The internal table
itab_contacts (2) can contain a practically infinite number of lines, the technical size limit for an internal table
is 2GB.
‘Open SQL in ABAP
Next we select from the database table s£1ights all fights of the carrier Lufthansa with airplanes that have
less than 250 seats:
SEL:
* FROM sflight INTO TABLE itab_flight
WHERE carrid = 'LH' AND seatamaz < 250.
‘As you can see a subset of SQL is part of ABAP. This so-called Open SQL has a big advantage for you: itis,
a database independent subset an SQL, so that your SQL statements are valid for the database of every
vendor that is supported by the SAP NetWeaver Application Server ABAP. As the application server always
has a database connection at hand, you need not care about opening, administrating and closing such a
connection. By using the keywords INTO TABLE you perform an array fetch, the whole result set is
transported into the intemal table. The only precondition is that the database table and the internal table
have the same line type.
Next we want to see the content of the internal table. One way to see the content of this internal table at
runtime is to switch to the debugger and to have a look at the content of it. We will showin a later blog how
easy this is in ABAP. You can just set a breakpoint at a particular statement and the debugger opens as
soon as this statement is processed,
Test Output of an Internal Table 4: A Loop and a Write-Statement
Here we will output the content of the internal table on the screen by using a classical list. ABAP has a
particular control statement to loop over all ines of an internal table. Let us use i:
LOOP AT itab flight INTO wa_flight.
WRITE: wa_flight-mandt,
wa_flight-carrid,
wa_flight-connid,
wa_flight-fldate,
wa_flight-wa_flight-curre:
wa_flight-planetype,
wa_flight-seatemax,
wa_flight~seatsoo
wa_flignt-payment sum,
wa_flight-seatemax_b,
wa_flight-seatsoce_b,
wa_flight-seatemax_f,
wa_flight-seatecce f.
SKIE.
ENDLOOP.
Every line of the intemal table is put into the work area consecutively. Inside the loop the different
‘components of the work area wa_flight are written to the list output. In ABAP the hyphen is the component
selector for a structure.
How to Get to Know the Properties of a Database Table
‘You may ask, how could I know the components of this structure? Answering this question is a good
opportunity to show another useful feature of ABAP. Obviously, the work area is a structure of the line type of
the database table =£1igixt. So we double click the name of this database table in the declaration at the top
of our report. We are asked to save the program, and we confirm. There we are:
key Di. ‘Data Type Length
So sxwr cor 3 OCent
@o@samm cor 3 Carine code
% Wscmw me 4 cFaghe connecton umber
oo smn pars © oFighe date
O @ sma com as 2ANfae
CO @ Scmcoe cme SCLoca carency of ane
O @ Smaere con 10 cAreafe Type
O Mssmsae m0 418 Maxum capactyin economy css
Ow Sseatsoce wre 20 C Occupied seatsin economy cass
Ow som com 172 Totalofeurent booknos
Oo wssaxa are 20 CMserum capacty in Busse eae
O wsscce ara 200 Occupied seats in buses cass
Ov ssaxe are 120 OMkxerum capacey n fest cs
Ow sscce mmm 10 OOccupld seats in fest cs
‘The system has led us to the location where the table is defined. This is the ABAP Dictionary (Transaction
‘SE11). By using the Back button we return to our program. So this is the way you get to know the
‘components of the line type of a database table.
What the List Output with the Write Statement Looks like
‘The way the output to a list works is simple: As soon as the whole list is filled it is output to the screen. So let
us save and run our program, and the upper part ofthe result on the screen looks like this:Obviously this way to write the lines of the internal table while looping over it presupposes the knowledge of
what the components of this table are.
Test Output of an Internal Table 2: A Dynamic Way to Output Any Internal Table
Next | will show you a way to write the lines of a table without knowing the different components of its line
type. First of all you can reuse these lines of code to output any result of a SELECT that is stored in an.
internal table. And secondly, you encounter two important means to realize dynamic programming in ABAP:
the field-symbol and the dynamic assign.
First we have to declare such a field-symbol, ths is a particular field type in ABAP. Without going into the
details of it, you should know that a field symbol works like a pointer without pointer arithmetics, but has @
value semantics. You can assign it to different data fields and when accessing their content there is no need
for dereferentiation.
FIELD-SYMBOLS: TYPE ANY.
‘The typing ANY is necessary because the field symbol should be able to refer to data of any type. And this is.
what our loop looks like now using a dynamic assignment to the different components of the work area:
noor at itab_flight mro wa_flight.
Do.
ASSIGN COMPONENT Sy~inde:
IP sy-subre <> 0.
SKIP.
OF STRUCTURE wa_flight To .
ENDIF.
WRITE .
ENDDO.
ENDLOOF.
The most complex activity is contained in the third line. The rest is simple and straight forward: The system
variable sy-inciex contains the loop counter that is counted up with every processing of the loop. The n-th
component of the structure is assigned to the field symbol. If this is successful (if =y-subrc =0) the content
of the field symbol is output to the list using the write-statement. f there is no more component to be
assigned to the field symbol, the assign is not sucoassful (sy-suibre <>0) and then we leave the DO-loop
{the inner loop) and go on with the auter loop.To chock if our new lines yield the same result we comment out the original loop. You mark the relevant lines
and press CRT and "<" simultaneously. We run the program and the result is almost the same. There is one
difference: This table has some more columns because this time we output all columns, while in the first
alternative we have not shown the columns SEATSMAX_B, SEATSOCC_B, SEATSMAX_F, SEATSOCC._F.
If you doubt this just double click on s£1ight in the program and look in the declaration of the table in the
ABAP Dictionary.
Test Output of an Internal Table 3: The Object Oriented Way
‘Amore comfortable way to output the internal table is by using a service class that outputs the whole table
plus the header information provided in the ABAP Dictionary. First, we need to declare a field that can keep a
reference to the service class.
DATA alv TYPE REF TO cl_salv_table.
‘The whole output is contained in two statements,
el,
alv
itab_flight ).
1y_table=>factory( IMPORTING r_salv_table
CHANGING t table
alv-odisplay( ).
The class method factory of the class c1_salv_table needs the internal table it should show, creates
an instance of this very class, and exports a reference to this instance. In the second statement the method
lisplay of this instance outputs the table to the screen. Before we run the program, we should, of course,
‘comment out, the dynamic assign plus the loop:
aro. eons ree cam panes | ay occ Seung ets acy) oraead) Cae Oka
ano ee 8 a ‘esas a
‘eno eR AIF ae sera a
‘eno et 18 2 memes
eno ek 8 2 moss
‘eno et 18 B weses 2m
‘weno te > fame om
‘eno et 19 2 Saad
eno ek 19 2 sage 2
‘aaso ik 18 mT sone
‘ero aR 1 mt too
2200 em 727200 1 smo
ase eR 720 m hie
zap em 27308 = soga
zen em 727200 re some
apo em 727200 = somnk
Rem em 70200 1 sso
dezes em 77200 a Sous
2ep0 om 727200 as Ban
Rem em 727200 & namo
besos em 77300 D ‘oe‘The Whole Code of the Three Alternatives — An Overview
Now let us have a look at the whole code of our program in one listing. | have commented out alternative two
and three to autput the internal table on the screen. So if you use this cade as itis, you run alternative one.
To change this just comment out other parts of the code (press Shift + CRT + ">" to uncomment and CRT +
>" to comment out some lines):
REEOR
DY
read_table_flights.
itab_flight Tyez sranparp TaBLe oF sflight,
wa flight vee sflight,
alv TyeZ REP To cl_salv_table.
FIELD-SYMBOLS: TYEE
SELECT *
FRoM sflight Into TaBLE itab flight
WHERE carrid = ‘LH’ AND connid = "402!
* Alternative one: Loop at table and write the different components of work area
Loop aT itab flight Ito wa flight.
write: wa_flight-carrid,
wa_flight-connid,
wa_flight-fldate,
wa_flight-price,
wa_flight- ,
wa_flight-planetype,
wa_flight-seatsmax,
wa_flight-seatsocc,
wa_flight-paymentsum.
skip.
endloop.
‘alternative two: Loop at table with dynamic assign of component
"LOOP AT itab flight INTO wa_flignt
* Do.
* ASSIGN COMPONENT sy-index OF STRUCTURE wa_flight 70 .
* TF sy-subre > 0.
* ENDIF.
* WRITE .
* ENDDO.
*ENDLOOP.
+* object oriented way
*cl_salv table=>factory( IMPORTING r salv table = alv
* CHANGING t table iteb flight ).
talv->display().‘Summary
Now you have leamed:
‘+ What an intemal table is good for and how easily you can declare an internal table of the same line
type as a given database table
+ How you write a SELECT statement in ABAP and put its result into an intemal table.
‘+ Asimple way to output an internal table on the screen by looping over it and outputting each line
‘component-wise.
‘+ Adynamic way to output any internal table using a field symbol and a dynamic assign.
‘+ An object oriented way to output the whole table without any looping,
GETTING MORE FAMILIAR WITH THE ABAP DICTIONARY
In this blog of our series we will improve the program from the last blog and show you some other useful
features of ABAP and the development environment provided by the NetWeaver Application Server ABAP.
You find an overview of all the biogs in the series hi
Quite obviously our program is not very flexible. In fact, what the program does appears more hard-wired
than really program driven insofar as you always get the same result. In this blog we will adapt the program
so that you can choose the carrier on a so-called selection screen. Using this selection screen you can very
easily create a Ul to input the relevant parameter, but you should use this also (just as the list output) for test
purposes only, as itis based on old technology. Stil, with this limitation, the selection is the perfect means to
Create @ user interface for input of test data in a quick hack. So we will create one to input the cartier.
Astonishingly enough, we will find that there is a value help for the input of the carrier, when we call this
selection screen from the program. Apparently this is quite useful, as the user cannot be expected to know
the carriers available, let alone the abbreviations of the carriers that are needed by the program. At this
stage, we will take the existence of this value help for granted, but keep the question in mind: Where does
the value help come from, if we have prepared nothing of this kind in the program code?
Moreover there lurks the problem that we do not know in advance for which searches we will get a non-
‘empty result set. We cannot be sure if there are any flights in the result set for a particular carrier. To make
matters worse, we also will not know, why the program does not show any flights, if this happens. You might
suppose that there might be something wrong with the program presenting the values in the user interface if
it does not show any fights.
We will tackle all the question addressed in the course of this blog:
‘+ First we show you how to navigate from the definition of a database table in the ABAP Dictionary
(transaction SE11) to the Data Browser (transaction SE16) that enables you to look at the records in
the respective table. This way, you can check beforehand whether the data you input will produce a
non-empty rasult set.
‘+ Having a closer ook at the ABAP Dictionary and the way data types are defined there we will get 2
better understanding of how and why technical and semantic properties of a data type can be
defined separately from each other: Semantic properties are defined in the Data Elements, while
syntactic properties can be defined in the Domain.‘+ Itis the data element that contains a reference to a Search Help. The so-called Search Help is also
defined in the ABAP Dictionary and provides the value help we use when inputting our carrier as a
parameter.
‘+ In-some of the next blogs | will present you the standard solution to problems like this: Quite
obviously, the standard approach to a problem like this, is to use the debugger. This is true for ABAP
a for any other programming language. But with the SAP AS ABAP itis particularly easy to start the
debugger. You can diverge into the debugger from the normal state of the system. There is no need
to start the system in a particular debugging mode in ABAP. Moreover you will find, that the ABAP_
debugger offers all the functionality you expect from a state-of-the-art debugger. But this is
something that should only raise your interest in the blogs to come. Explaining the ABAP debugger
will not be part of this blog.
PARAMETERS and the Selection Screen
We start by copying the program from blog 10 to another program. To do this, we navigate to the program in
the object tree of the SEBO, right click it and choose Copy. A dialog window opens:
We enter the name of the target program as shown and press the Copy button. Next we switch to the
Change mode (by selecting the respective button).
80 what do we want to achieve? We are not content with the SELECT statement as itis:
SELECT FROM sflight INTO TABLE itab flight
WHERE carrid = 'LH' AND seatamax < 250.
Instead of always choosing the carrier Lufthansa, we want to enable the user to input other carriers and look
what flights they offer.
In ABAP this is quite easy to achieve. We declare a variable of the relevant type as an input parameter of the
program:
parameters: p_carrid t:
s_carr_id.
This simple line of code serves two purposes:
‘+ First, itis the declaration of the variable as we need it. (Later in the blog you will understand why we
use the data type =_carr_id).
‘+ Secondly the parameters-command in ABAP creates a so-called selection screen at run time, which
is a screen to input the respective variable(s) declared in this command.
In order to make our parameter do some work we adapt the select statement:
SELECT FROM sflight INTO TABLE itab flight
WHERE carrid - p_carrid AND seatemax <
We save, activate and run the program. As I have told you, we get to a so-called selection-screen.Since we are not familiar with the carriers in the database we need a value help and press the F4 Button,
‘Surely, you remember: This is the button to trigger the value help in ABAP. if there is a value help supplied.
Obviously, there is a value help though we have not done anything to provide one:
We choose BA for British Airways, confirm and press the Copy button (with the checkmark icon). Nothing
happens.
‘And this is the situation | have mentioned at the beginning of this blog. Obviously, we do not really know, if
there is something wrong with our program or if there are no flights of British Airways with the specified
capacity,
From the ABAP Di
nary to the Data Browser
As a first approach to solve this problem we try to find some other way to cheok if there are any flights in the
table that match our SELECT criteria: We double click the name of the database table sfiight in the data
declaration of the program. The ABAP Dictionary opens. The Fields tab shows the name of each column
plus its data type, as we have already shown in blog 10. At the moment we use the ABAP Dictionary only to
pass through to another transaction that provides us a view on the content of the database table, To get
there, we choose the menu Utilities - Table Contents — Display. We reach the selection screen of the Data
Browser (SE16):@ ERT Nember of eres
cane Ta » 1
coun » []
FLDATE [ wo
CURRENCY we
PUETE cy sy
sexTsoce co ero
Pare Se
SEATSHAL ne |
‘SEATSOCC wo | ]
SEATSHNCE a eo
sexrsoce cm sf
Wt of ott at (a)
cru, of =]
First we enter BA in the fleld CARRID. A message in the status line tells us: "No table entry found for
specified key".
In order to got an overview of all the entries in the table, we delete the input BA, select the Execute button,
and get a list with the entries:
A view at the relevant section of the table shows that there are no entries for BA at all. So we have one part
of the answer to the question of why our program showed no result list. Stil you might wonder why the
program does not even show an empty list. Let me add a particular feature of the report-logic to answer the
question completely: If there is no list output the program returns to the selection screen. (But be careful: In
case you ever want to use this feature in test programs, you should know that the selection screen is opened
in anew internal mode. That means the global variables of the program are reset to their initial values.)
Now itis time to have a look at the question where the value help came from. You surely remember that in
blog 10 I told you that the flight model is part of all delivered SAP systems. This means the respective tables
and the relevant data elements are available in the system. That was why we could use the table sfiight with
allits components though we have not stirred a finger to create it. The same is true for the value help as | will
show in the next section.Data Element, Domain, and the Way They Interact
We navigate back to the ABAP Dictionary, where we see the definition of the database table sflight. We want
to have a closer look at the type of the component CARRID since we have a value help for a parameter of
this type. So we double click the data type S_CARR_ID.
We get to the data element $_CARR_1D:
fee 9 9 es 3 ne cae
@Elementary Type
@doran D
Data Type (CHAR Character String
Still wo find that the syntactic properties of the type are not defined in here, but defined in a Domain. So we
drill down to the domain by double cl
To make a long story short, the ABAP Dictionary provides two levels to define a data type: The data element
determines the semantic properties of a type, while you can assign a domain to the data element, and itis
this domain that defines the syntactic of technical properties. What is this two-level-structure good for?
Apparently itis a good idea to reuse the technical properties of a data type. For instance, a character field of
length three, can be used for all kinds of IDs, not only for carriers. They all share the syntactic properties, but
need, for example, different labels.
Probably you remember the last blog: When we output the internal table with the display method of the class
¢l_salv_table all the columns had header information on the screen. You might have asked yourself: Where
did this information about the header text come from? It is now that we are in the right position to answer this
question: The text used for headers is defined in the Data Element under the tab Field Label:
Short
Medium
HeadngOn the level of the Data Elements (1) you define the semantic properties, and, the syntactic properties are
defined in the Domain (2).
a
1
Xx
Of course, this two-level-structure is optional: If you want you can define also the syntactic properties in the
Data Element.
At Last: The Source of Our Search Help
The Data Elomentis also the place where search help for a data element is defined. Under the tab Further
Characteristics you see the name of a search help: S_CARRIER_ID:
Defast Component tame (REET ——SCSC~*~*~S~S:
By double clicking the name of the search help we could go into the details of the search help. I do not want
to do this here, but it should suffice to state: A search help is 2 particular kind of object that is created and
edited with the ABAP Dictionary. It provides a value help with the list of possible input data by drawing the
data from a table that serves as the data source.
‘The fact that the search help is a property of the data type has a big advantage: A search help defined in the
ABAP Dictionary, is also available in Web Dynpro ABAP applications if the fields on the screen are typed
with the right Dictionary types that supply such a help, We navigate back to our program by using the Back
button and take some breath and sum up what we have learned so far about the ABAP Dictionary and the
Parameters command,‘Summary
‘+ The ABAP Dictionary (SE11) defines the technical properties of a database table such as the name
‘and the data type of each column. It is possible to define the syntactic and the semantic properties of
a data type separately from each other, the semantic properties in the Data Element, and the
syntactic properties in the Domain.
‘* Typical semantic properties are the field labels and the reference to a Search Help. So we know by
now where the value help that seemed to appear by magic is defined: In the Data Element of
'S_CARR_ID. A Search Help defined there can also be used in a Web Dynpro ABAP application.
‘+ The Data Browser (SE16) is the place where we can get an overview of all the entries of a database
table. We can navigate there via the ABAP Dictionary as we have seen, but we might, of course,
also open another session, input SE16 as an ok code and enter the name of the relevant database
table there:
‘+The Parameters command is very simple to use and stil a powerful means to create a Ul for user
input. But nowadays you should use it for test purposes only because itis based on classic
technology.
With the knowledge we have acquired, we can now check if the WHERE-condition of our SELECT should
lead to a list output. In order to make sure that nothing else goes wrong, you should be able to use the
debugger. As I have already mentioned in the introduction of this blog, | will soon introduce this powerful tool
‘You will find it particularly useful, since you can just jump into the debugger without making any time
‘consuming preparations.
DEBUGGING IN ABAP
In this blog (blog 12 of our blog series) you get to know one of the most important tools for an ABAP.
developer, the debugger, and an important source of information that every developer needs: the ABAP
keyword documentation. | will give you a short overview on the ABAP debugger and uss it to find a particular
bug. You will probably be pleased to learn that in the SAP AS ABAP itis very easy to start the debugger.
You can diverge into the debugger from the normal state of the system. There is no need to start the system
ina particular debugging mode in ABAP.
Moreover | will show you how to benefit from some really useful features of the ABAP keyword
documentation. All these explanations are embedded in a practical example: We will change the program
from blog ‘1 in order to present fewer columns in the Ul, to order the entries and to minimize the result set.
In the course of doing this, you will learn:
‘+ How to define a structure
‘+ How to narrow the result set of a SELECT by reading less fields from the database
‘+ Aparticular addition to the SELECT statement that enables you to restrict the number of fields
transported into the target field of the SELECT.
Defining a Custom Structure in a Program
As a preliminary we copy the program from blog 11 to the program y_select_£_flight_ad_2. Ifyou
have any trouble doing this refer to blog 11 where | describe how to copy @ program
{_flight_ad_1. Letus start by defining a narrower structure than the one we had in our
program. You remember that by defining wa_flight TYP= sflight we got a structure thal was as broad
as the table sflight with all ofits fields. We assume, we need only some of its fields, namely: carrid,
connid, fldate, price, currency, and planetype. So we add a new data definition:itab_flight TYPE
wa_flight TYPE 5
alv TYPE REF TO cl :
BEGIN OF str_flight_s,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
fldate TYPE sflight-fldate,
ce TYPE sflight-price,
rrency TYPE sflight-currency,
mnetype TYPE sflight-planetype,
END OF str_flight_s.
ANDARD TABLE OF sflight,
It you have read the blog in which | introduced the Data Element, you know what additional benefit we get by
using those Dictionary data types: They all have defined field texts. Since | intend to use the object-oriented
way to output an internal table (look at biog 10) we will profit from these texts by getting headers for all the
table columns we output.
‘You may think that by now we do not even have an internal table that has the same line type of our new
structure. And you are right. So let us create one:
TANDARD TABLE OF str_flight_s. does the job for us. We use the
keyword LIKE’ because we do not give a type for the table line, but a structure, Next we adapt the select
statement:
‘Light INTO TABLE itab_f:
WHERE car:
ight_s
id AND Seatamax < 250.
Again we have an array fetch, because we select the whole result at once, and we have ... yes, we have a
syntax error. Press CRT + F2, this is the keyboard short cut for the syntax check to see this.
A Useful Addition to the SELECT Statement
‘At second thought it is easy to understand what is wrong with our SELECT. By using the asterisk we read all
columns of table =f1ight, and this does not completely match with structure str_flights_s. Of course,
there is a partial match, because the structure str_flights_s contains only fields that are typed with the
respective types of the columns of sflight, but it does not contain all the fields of this database table, only a
subset. Wouldn't it be nice if we could tell the program: “Move only the fields from the result set to the target
structure that have a counterpart in this structure’? And indeed, there are some keywords in ABAP that do
this job. We adapt the SELECT statement again:
SEL:
FROM sflight INTO C}
WHERE carrid = p ¢
RRESPONDIN
id AND seal
FIELDS OF TABLE itab_flight_s
max < 250.
But be careful with the keywords INTO CORRESPONDING FIELDS. They can do no magic, but use the
identity of the names for the assignment: That is the value of the selected entries from database table
column A are moved to the fields in column A of the intemal table, And this is all. In our case, the fields with
an identical name also are of the same type, but if this would not be case this is not checked by the system.
Next we use the object-oriented way to output our intemal table. In order to get some additional information
in case the intemal table itab_f1ight_s is empty we add a condition. So our code looks like this:IF itab_flight_s 15 INITIAL.
‘nothing in table.".
factory( IMFORTING x_salv_table = alv
Caavemns t_tapie itab_flight ).
aly-odisplay( ).
ENDIF.
We comment out the two alternative ways to output the table (mark the relevant code and press CRT +
SHIFT + "<"), save, activate the program, and run it
What Is Wrong
Our Program — We Start to Debug
We know from blog 11 that there is @ result set with some entries in it if we choose Lufthansa in the selection
screen as the value of the parameter p_carrid and s0 we provide the same value for this parameter.
Unfortunately the result is not satisfying:
Itmight seem hard to understand why we do neither get the output “nothing in table” nor an output showing
some table entries. So this is the time to resort to the debugger. To see what our SELECT statement does at
runtime we set a breakpoint at this ine. We do this by double clicking the leftmost column in the editor as
shown and a small icon appears that stands for a breakpoint:
[@) 2) petecr'
55" Foo selaghe Tit CORRESEONDING FrEtDS OF TABLE stam f2ighe_e
26 WHERE carsia = p_carria AND seatamax < 250.
Before starting to debug we check if we have really chosen the new debugger. In fact your system should
already be configured accordinaly. I not we open the menu: Utilities ~ Settings - ABAP Editor —
DEBUGGER and select "New Debugger”. And now let us go. We run the program, choose the input
parameter Lufthansa and select Execute or press F8:
‘Anew extemal mode opens and we see the new debugger. Let me use this opportunity to give you some
general information on the debugger before we go into the details of how to find our bug
‘The New ABAP Debugger — A Short Overview
You know, you live in good times, at least as far as the ABAP debugger is concerned. Since NetWeaver
2004 there is a completely new debugger that runs in another work process than the program that is
debugged, the debuagee. This is why the new debugger always starts in a new extemal mode.
To put it in a nutshell: This debugger is a state-of-the-art tool that offers the features you expect from any
debugger, even some features more (for example a tool to compare the contents of any two intemal tables).
The navigation within the debugger is straight forward, and you can easily configure the different tools in it as
you like. As for the general layout of the debugger, its divided in different tabs. Each tab stands for a
‘desktop ofits own, that can contain differant tools, which, for example, show the source code, the call stack,
or the value of variables etc. You can customize each desktop by inserting the tools you like in the position
you want. To give you a general impression of what such a desktop in the debugger looks like let me show
you a screenshot of the standard desktop with its three tools:Below the menus that are not shown in this screenshot (experienced bloggers on SDN know: the size of
pictures in SDN blogs is limited) there are some buttons to control how to step through the debugged code
(8). In the panes below you see the standard desktop (1) with the source code tool (2), the call stack (3) and
the variables and their values (4). So much for the overview of the debugger. But to really show you how to
work with it we go on searching our bug
Debugging Our Program
As the debugger has opened with desktop 1 we first choose the standard desktop tab to see the tools as
shown in the figure above. We double click the name of the internal table italp_£1ight_s in the code view.
That has the effect that the debugger shows the value of this variable in the pane on the right (4 in the figure
above):
Men
val |
[0x6 (62) ]Inicial Scandar_
If you were more experienced with the ABAP debugger, this display would already tell you that we have an
internal table with six columns and no line, So you can just guess it or must believe me. To make sure that
this is the right way to understand what we see we double click the name of the intemal table in this pane:
We get to the tab rider that shows the content of the internal table so that we can check, if there were any
lings to be displayed
tas aarp
oe
trues ‘standard (06(68)) ae
reercten [) mE)
ton MRD (CS) (COMM e)) OATE(OI)) PRICE (HE) DEC2) CURRENCY CS) PLANETPE [0 |‘There are none. We navigate back to the standard desktop by using the Back button. Next we want to
‘execute the SELECT statement and then look again at the content of the internal table. So we need a single
step, and quite obviously the icons to control the debugging steps look as in most other debuggers, and
anybody familiar with debugging will have no problems to choose the right debugging steps in the ABAP
debugger:
We select the single step mode as shown, look again at the content of the internal table in the right pane
below. Obviously our internal table is now populated with 33 entries,
[34x6(68) ]Standard Tabie
‘So we can feel relieved: There was no mystic loss of data in the system since the blog 11 when we had quite
‘a number of entries for the carrid of Lufthansa. We go on in the single step mode, and see that the first
branch of the #-statement is not taken. This is because the internal table is not empty. While we are stepping
forward we have an eye on the content of the internal table in the pane on the right, Itdoes not change until
we reach the display method. So how could it be that there are no lines output, i the value of the internal
table it not empty and this table is output?
Obviously we have so far explicitly verified only the first part of the condition. So do we really output the
internal table, which has 33 lines as the debugger tells us? We have a closer look at the relevant statement:
el,
1y_table=>factory ( alv
itab_flight ).
alv->display( ).
And there is the culprit. We have passed the wrong table to the factory method. We double click tab_fiight to
iew it in the variables tool. The table is empty, and this takes little wonder. Itis the table we used in blog 11.
Since we have not deleted its definition it does still exist in the program, but no line was added to it
Remember: We meant to replace its name by the name of the table itab_f1ight_s in all statements. But
il seems, we have forgotten one statement, namely the one in which an intemal table is passed to the factory
method. So the table ital_£1ight is stil empty, and itis this empty table that we pass to the factory
method. This is also the explanation of why our output showed many more headers for columns than our
new narrow table =_flicht_s. We showed the old table >_£1 ight with all columns of the database table
s£light and no content, because the result of the SELECT statement was moved to the new internal table.
2_flight_s.
‘So we correct the statement accordingly, activate, save the program, and by double-clicking our breakpoint
we remove it: For the time being we do not need the debugger, we are fully confident that we have corrected
the mistake, and we are right.
Let me use the last sections of this blog to tell you a bit about good SQL programming style and somethir
more about the ABAP language documentation as | have announced at the beginning of this blog.
‘Some Words on Efficient SQL Programming
First ofall, you probably know already that it is bad programming style to select more data from the database
than needed or used. Why is this so? In general, in a real-life system accessing the database is expensive.You have the network latency and you have to access the hard disk if the table is not cached. In general,
both activities are far more time consuming than the execution of simple statements on the application server
that do only affect the memory of the work area of the process the program runs in. Selecting all fields from a
dataset on the database if in fact you move only a few fields to the target structure is as efficient as carrying
ten buckets of water to the tenth floor and then pour five of them away. Of course, it does not really matter in
ur litle example, but if you have result sets with some hundred thousands of datasets, you are well-advised
to select only the fields you really use:
‘So we adapt our select statement to:
SELECT carrid fldate planetype currency price connid
FROM eflight INTO CORRESPONDING FIELDS OF TABLE itab_flight_s
WHERE carrid = p_carrid AND seatsmax < 250.
have chosen a sort of random order for the columns just to show you that this order does not matter
because the fields of the result set are moved according to their name. The order is irrelevant,
How to Use the ABAP Language Documentation Efficiently
Being economical we want to order the fights in the result by the price and the date. Most probably we need
an addition to the SELECT statement. f you are not sure what the relevant addition you need looks like in
detail, just position the cursor on the keyword SELECT and double click. A dialog window opens:
Ex
Uo nde Ser
ane ngage berets =
(Bocere est, ABAD stent
+ DORETE DATASET, B19 Scene
+ QOBETE tb, ABM Store
Bhoeere mah ph, AAP statorent
(Bhoesere TB at, a80? stator
1 (DOBETE TARE mesh sath AB82 Statement
(Bros sacr, orem cinson|
Ber oca uncince ae saceren
+B umcunce ve, nETIOn 8 OXTABASE PROCEDURE
+ icons Sas, HeTHOO BY DATABASE RNCTION
+ cacunce SaLScRPT, HETHOO BY DATABASE PROCEDURE
+ umeusce, ore TecPooe
+ Buaeusce, nsset TextPoo.
+ Duaneunes, wea rextPooe
+ Bune, suo
+ Bowen ror sarc, xr sa.
+ sac, nseet oH
(sac, were sbesey
+ ser Lancuace, ata Statement
B)ser woos wincincs, BN) stent
‘owes ABAD Langage Bens
7 are austen che a see or fom Obst ABA? Stee
+ QOGETE tb short frm Oosulete ABAPStaterent
+ Dsascr- sur tom obsokt Av? Sarena
© beara ABs Language Barats a
~ ES OBETE DOR, Pera ABD Serene a
fee Saal EE ITE