Vous êtes sur la page 1sur 7

ABAP Workbench: Creating a program

Prepared by Jennifer Kreie


New Mexico State University

ABAP Workbench: Creating a program


This lesson gives an introduction to the ABAP Workbench by creating a simple program and changing some
ABAP Editor features.
Assumptions and ground rules
Before we begin working through the ABAP lessons, we need to cover some assumptions and ground rules.

Already familiar with SAP navigation. This ABAP lesson starts with the assumption that you are familiar
with navigation in SAP. You should complete the SAP Navigation exercise now, if you havent done so. The
ABAP lessons will give the menu path to a feature and/or the transaction code. You should be familiar with
using these already.

Naming conventions. Before you begin creating anything you need to know something about naming
conventions in SAP, i.e. the namespace. Developers must put a Z or Y at the beginning of any name when
they create a table, a program, a function, etc.. This naming convention identifies your programs and all
their components as ones built beyond the core SAP applications. All developers, not just students, follow
this convention. By the way, if you ever want to use something else as the prefix, you can register the prefix
with SAP. Registering the prefix prevents other developers from using it. This way whatever you develop
could be transported into any SAP installation without having to worry about name conflicts.

Naming convention for this course. With only a few exceptions, the names of things you create will follow
the format shown here. The dollar signs ($) will be replaced by a 4-letter code assigned by the instructor.
This will often be your first initial and the last three letters of your last name but verify with the instructor.
Z_$$$$_
So, if you were assigned JKRA as your 4-letter code, you would name your program Z_jkra_my_program.
Following this naming convention not only makes it easier to locate your objects, it also avoids naming
conflicts with existing SAP programs and with other developers working on their own projects. Remember,
Workbench is a multi-user development environment. The programs you create reside in the same
repository as those made by other students in this course and, possibly, by other students at other
universities.

User-specific input. Whenever you see text between to angle brackets <>, you should type in the text that
applies to you. For example, <lastname> means you should type your last name, not the text lastname.
If you saw this template for naming a program:
Z_$$$$_<lastname>
and your name is Jack Kramer, you would name the program: z_jkra_kramer.

Dont just look at screen shots. Please note that screen shots examples may not reflect the current
naming conventions in these lessons. You should follow the naming conventions explained in the lessons or
given to you by your instructor. Dont mimic screen shots. In most cases they are meant as general
examples. Screen shots have been made at different points in time and are not often retaken when minor
changes in these lessons are made.

Lesson 1: In this lesson youll create a simple program using ABAP Workbench while you learn some of
the Workbench features.
Page 1 of 7

ABAP Workbench is a development environment that provides a framework for large-scale development with
many developers working on a project. Whatever programs you create in the Workbench must adhere to certain
conventions in order for them to run in the production environment and ABAP Workbench does a great deal to
ensure this adherence to rules and conventions.
The sequence of development has at least three steps before programs are put into use.
1. Write the programs in the development environment.
2. Transport this set of programs into a testing environment.
3. Transport the tested set of programs into the production environment where the programs you
developed will be used in the workplace.
Before you get started with your first program you will have to lay some groundwork for organizing the programs
you create. Lets say we were going to start a development project. As a project manager, I could create a
transport request and give you and other developers access to it. You create a package (formerly called a
development class in ABAP Workbench) that will contain the many components that make up your work on this
project. When your project is complete and ready for testing the transport request is released by the project
manager which allows the package you created and perhaps others from other developers to be transported to
another SAP environment, in this case the testing environment.
For the purposes of this lesson, you will create a transport request, even though this would likely be done by
someone else in your development team at work.
Create a request.
Open ABAP Workbench. This can be found in the SAP menu
structure under Tools\ABAP Workbench\Overview\Object
Navigator (SE80). In the list of categories in the upper left of the
screen, Repository Browser is automatically highlighted. Change
this.
Select Transport Organizer. Select the text that says Modifiable
Requests with a right-click and use this context menu to select
Create.
In the dialog box that appears, leave the Request
type as is and type in a short description: <$$$$>
ABAP Practice. Click the checkmark and you have a
request.
The request is identified by an SAP-generated number. You can copy this or write it down but SAP will usually
keep track of this request and show this request ID for things you
create later on. Also, if you need to find your request, you can
easily use SAPs search to locate your request.
Create a package (formerly a development class)
In the Object Navigator, highlight Repository Browser then type
the name of your new package: Z_$$$$_ABAP_practice and hit
enter.

ABAP Workbench: Creating a program


Prepared by Jennifer Kreie
New Mexico State University

When prompted whether to create this package, click Yes.

Enter text in the Short Description field. Leave the default values for the Software Component and Transport
Layer then click the sheet in the lower right corner to create the package.

You are asked for the transport request to


attach this package to. If your newly created
transport request ID doesnt appear
automatically, click inside the Request box
and hit F4 to get a list of your transport
requests (there should only be one at this
point). Double-click the request. With the
request ID showing now, click the checkmark.
Create a program
Now you have a package that will hold all the things you build and this package is assigned to a transport
request. As you create programs and other things throughout the lessons ABAP Workbench will prompt you for
the package and transport request assignments for the things you create. Without further instruction, you should
know to use the ones you created here.

Under the Object Name section the package name should be


listed. Right click this to get the context menu. Select Create
Program. Name this program: Z_$$$$_1st_program and
uncheck With TOP INCL If you forget to uncheck this, youll get
a line of ABAP code in your program that isnt relevant.

The next dialog box asks for an access key. The first time you create a program, you are required to enter an
Access Key. You wont have to enter this key again but enter it now. (Get this key from your instructor.)

Page 3 of 7

In the next dialog box, you enter


the title of your program. It doesnt
have to match the example shown.
Enter what you like but keep in
mind that this title will be the first
line shown when your program
generates output. Update status to
Test Program and click Save.
Assign the program to your
package and transport request in
the following dialog boxes.

In the ABAP Editor on the right side of the computer screen, you see the start of your program (see example
below). A comment header section has been created and the executable statement REPORT has been
added. Everything you code will go below the REPORT statement.

Your program screen may not look like the example shown. The
example screen has the ABAP Editor set to display new editor
features (line numbering, expandable/collapsible code
segments, etc.). To turn these features on, select the Utilities
menu and Settings. Select Front-End Editor (new) and click
the checkmark in the lower right corner.

ABAP Workbench: Creating a program


Prepared by Jennifer Kreie
New Mexico State University

Enter a few simple WRITE statements. The first line writes some text. The second WRITE statement adds a
return (newline) by using the forward slash followed by some text. The third line writes your user ID which is
held in a system variable
called sy-uname.
Notice that each statement
ends with a period. The
example here also shows inline comments.
Save, check, activate
There are three things you will do repeatedly while writing a program: save, check, and activate. Use the
diskette icon to save the program

. Click the check icon

to have Workbench check your program for

syntax errors. If there are any, correct them. Click this icon

to activate your program.

Since youre in a multi-user development environment the activation process is important. While you are
working on somethingrevising or building a new program, function, etc.it is inactive and no one else sees
see it. When you activate what you have built, other people using ABAP Workbench can see it.
The test icon
will execute your program. Try it. Your output should be
similar to what you see here.
Return to ABAP Editor by clicking the Back button.

Pretty Printer
In the ABAP Editor on the same row as the check and activate
icons, there is a Pretty Printer button. We will use this to
format the code, putting ABAP commands in capital letters and
indenting where it is appropriate. First, we have to check the
settings for Pretty Printer. Use the menu path: Utilities
Settings. Click the Pretty Printer tab and change the settings to
the ones shown here. Check Indent, convert
uppercase/lowercase, and Uppercase.
Click the checkmark to save settings.

Test Pretty Printer by clicking the button.


See the change in the code formatting?
ABAP commands are shown are capitalized
even if you had typed them in lowercase.

Page 5 of 7

Terms to Know
access key.............................................................................................................................................................. 3
activate................................................................................................................................................................... 4
development class.................................................................................................................................................. 2
development environment.................................................................................................................................. 1, 2
namespace............................................................................................................................................................. 1
package.................................................................................................................................................................. 2
Pretty Printer........................................................................................................................................................... 4
production environment...................................................................................................................................... 1, 2
testing environment................................................................................................................................................ 2
transport request.................................................................................................................................................... 2

Vous aimerez peut-être aussi