You are on page 1of 5

Getting Started Newsletters Store

Products Services & Support About SCN Downloads


Industries Training & Education Partnership Developer Center
Lines of Business University Alliances Events & Webinars Innovation
Log On Join Us Hi, Guest Search the Community
Activity Communications Actions
Browse
thomas.weiss
Previous
post
Next
post
0 Tweet 0
After you have learned how to get the ABAP Object Navigator (transaction SE80) in the last weblog it is now time to do
it. And we will do here and now in this weblog, we will write a "Hello World"-program.
Again, you will recognize a principle that I have explained in my weblogs on the server. The ABAP development
environment offers you a lot of benefits for free 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 a 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 rule is the package $tmp which is made for local
developments. The content of this package is not transported to any other systems. In this weblog we will create a
program in this package for local developments, while in a later weblog we will create a package that we will use as a
container for all elements we will create in other weblogs.
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:
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 Utilities -
Settings which browsers are presented for selection with buttons. The browser we will generally be using is the
Repository Browser (1). It is 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 local objects (2) of user bcuser. As we have not created any local objects by now, the area that shows these
local objects is still empty (4). By choosing another entry in the dropdown list you can see other objects such as
ABAP Trial Version for Newbies: Part 6 - A first Hello-
World-Program
Posted by Thomas Weiss in thomas.weiss on Apr 11, 2007 8:51:18 AM
Share 0 Like
package, programs, function groups etc. The whole list is shown in the screenshot (3).
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 a 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. I will explain in another weblog more technical terms what these tracks and transport requests look
like in detail.
You can view a package plus all its 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 a package and need no transport request. As already told, every AS ABAP contains a predefined package named
$TMP, 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_hello_word_local
in the input field below and press "Enter" or select the glasses icon.
Here you see a 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 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 "Z" for the first letter, or the abbreviations reserved by SAP for the customers 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 an "y" or "z".
In the next dialog window we deselect the item "With TOP INCL", confirm, and get to the next dialog window.
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 weblogs we will be using the new frontend editor available as of SAP NetWeaver 2004s, which like all
modern 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 corner. Up
to and including Release 6.40 (SAP NetWeaver 04), you will still 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 SE80.
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.
*&----------------------------------------------------* *& Report
Z_CREATE_EXAMPLE_DATA *
*& * *&--------------------
--------------------------------*
*& *
*& * *&--------------------
--------------------------------* REPORT Z_CREATE_EXAMPLE_DATA.
The first seven lines are comment lines, and the eighth line 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 editor. 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:
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
Utilities-Settings-ABAP Editor-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:
Now let us spend some words on the syntax of this little program. Though this program is as simple as could be, I 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_hello_world_local .
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, declarative 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 it is driven by the classic
SAP Dynpro technology which should not be used to write to used to write applications with an state-of-the-art user
interface. You should use Dynpro-based UIs only in test-programs if you want to output (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
Average User Rating
(1 rating)
My Rating:
0 Tweet 0
application as a user interface and to encapsulate all the logic of your programs in function modules or classes. Still, we
will use the write-statement sometimes in our weblog series in order to output some results or to input some values a
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.
At the bottom of the editor we get the information:
This check gives you precise information as to in which line the error is. In case of a slip of pen like this, the system can
make a reasonable guess as to what you wanted to type in, and proposes an semi-automatic correction. By pressing the
Correct Errors button (marked by the red-dotted frame) you can accept the proposal and your syntax error gets
corrected.
Next we save our program by pressing the Save button:
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.
If you remember the weblog about the activation of programs, you probably know that this program is still not visible to
other users. Why? There is no active version of this program. A version of 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 the it by pressing the Activate button:
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 objects 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 SE80 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 weblog.
Special thanks to Horst Keller and the Galileo Press. By courtesy of the author and the publishing house I could
reuse some explanations of ABAP concepts from the lately published book: ABAP Objects. ABAP-Programming in SAP
NetWeaver in this weblog. And I will also do this in the following weblogs 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 weblog.
In case, you want to know anything about ABAP in more detail than we can present here in our weblog series, just
consult the book. On 950 pages it covers, I feel temped to say, almost every conceivable detail of the ABAP language
2649 Views Topics: abap
Share 0 Like
3 Comments
John Spencer May 7, 2007 2:50 PM
I really appreciate the 'hand-holding'. This blog and the one prior did have me 'finally' understand
about the 'activation' of ABAP programs. I ordered Horst Keller's new ABAP Objects book on Friday.
Hoping to use it, this blog series, and the other resources here to 'dig into' ABAP. Again---Thanks!!
John Spencer
Follow SCN
Site Index Contact Us SAP Help Portal
Privacy Terms of Use Legal Disclosure Copyright
Like (0)
Like (0)
David Brenchley Aug 21, 2007 7:52 AM
Good Day Folks ..
SAP is foreign to me .. THANKS for such an excellent series of blogs .. their quite helpful .. I was about
to throw in the towel ... when I discovered these ..
my goal is to write an RFC callable from a 3rd party app eg. Excel
is this possible w/ this trial version ??
when I attempt to create a function group I'm queried for a KEY .. can you advise as to what the value
of this is and/or how I might obtain one ??
THANKS !!!
Like (0)
Rajesh G Jul 19, 2010 4:52 AM
Thanks a lot for this blog, it helps a lot for a beginner to SAP. Looking forward for other blogs from you
that aids beginners.

You might also like