sappress abap basics

49
Bonn Boston Günther Färber, Julia Kirchner ABAP ® Basics

Upload: govindbalakrishna

Post on 22-Nov-2014

226 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: Sappress Abap Basics

Bonn � Boston

Günther Färber, Julia Kirchner

ABAP® Basics

Page 2: Sappress Abap Basics

Contents at a Glance

Foreword ................................................................. 11

Introduction ............................................................ 13

1 Technical Overview and Getting Started in the System .......................................................... 19

2 Working with the Development Environment:The Object Navigator ............................................. 51

3 Procedural Language Elements .............................. 107

4 Defining and Managing Database Tables ............... 191

5 Screen Input and Output ........................................ 225

6 Object-Oriented Language Elements ..................... 319

7 Practice Scenario — Automated Accounting for Corporate Subsidiaries ...................................... 393

A Programming Guidelines and Tools ........................ 451

B Glossary .................................................................. 463

C The Authors ............................................................ 467

Page 3: Sappress Abap Basics

7

Contents

Foreword .................................................................................. 11

Introduction .............................................................................. 13

1 Technical Overview and Getting Started in the System .......................................................... 19

1.1 Overview of SAP Software and Architecture ............ 191.2 Notes for Setting Up Access to SAP Software .......... 23

1.2.1 Regular System ............................................. 241.2.2 Test System on Linux .................................... 251.2.3 Test System on Windows .............................. 26

1.3 Programmer’s Checklist for Getting Started ............. 281.4 Logon, Getting Started, and System Setup .............. 31

2 Working with the Development Environment:The Object Navigator .............................................. 51

2.1 Getting Started with the Object Navigator .............. 542.2 Development Classes and Packages ........................ 632.3 Namespaces ........................................................... 662.4 First Program: “Hello World” — REPORT, INCLUDE,

and Application Menu ............................................ 722.5 Online Help, help.sap.com, service.sap.com, and

SAP Notes .............................................................. 97

3 Procedural Language Elements ............................... 107

3.1 Basic Commands and Fields — WRITE, PARA-METERS, MOVE, SY Fields ...................................... 110

3.2 Data and Data Types — DATA, PARAMETERS, CONSTANTS, FIELD SYMBOLS, TYPE, CREATE, Text Elements ......................................................... 116

3.3 Structures and Internal Tables — TABLE, MOVE-CORRESPONDING, INSERT, APPEND, READ, MODIFY, DELETE, LOOP ........................................ 139

3.4 Subprograms and Functions — FORM, FUNCTION, EXCEPTIONS .......................................................... 151

Page 4: Sappress Abap Basics

Contents

8

3.5 Branches and Logical Expressions — IF, CASE .......... 1693.6 Loops — WHILE, DO ............................................... 183

4 Defining and Managing Database Tables ............... 191

4.1 Field Properties — DATA ELEMENT, DOMAIN ....... 1924.2 Defining and Processing Database Tables —

SELECT, INSERT, UPDATE, DELETE ......................... 206

5 Screen Input and Output ........................................ 225

5.1 Simple Input and Output Interfaces , — SELECTION SCREEN, SELECT OPTIONA CALL SELECTION SCREEN, SAP List Viewer ......................................... 227

5.2 Complex Input and Output Interfaces — Dynpros ... 258

6 Object-Oriented Language Elements ..................... 319

6.1 Classes and Objects — CLASS, CREATE OBJECT, METHOD ................................................................ 321

6.2 Inheritance and Polymorphism — INHERITING FROM, REDEFINITION ............................................ 351

6.3 EVENTS ................................................................... 370

7 Practice Scenario — Automated Accounting for Corporate Subsidiaries ...................................... 393

7.1 Defining the Requirements and a List of Functions for the Application .................................................. 3947.1.1 List of Functions ........................................... 3957.1.2 Selection List ................................................ 397

7.2 Software Architecture .............................................. 3997.3 Software Design ...................................................... 401

7.3.1 Rough Design ............................................... 4027.3.2 Detailed Design ............................................ 406

7.4 Implementation ....................................................... 4167.4.1 DDIC Objects ............................................... 4167.4.2 Programs ...................................................... 4227.4.3 Function Groups ........................................... 424

Page 5: Sappress Abap Basics

Contents

9

Appendix......................................................................... 449

A Programming Guidelines and Tools ................................... 451A.1 Programming Guidelines ......................................... 451A.2 Program Check Tools .............................................. 461

B Glossary ............................................................................ 463C The Authors ...................................................................... 467

Index ........................................................................................ 469

Page 6: Sappress Abap Basics

11

Foreword

For the past several years, ABAP has transformed itself from a pro-gramming language, which was used internally only at SAP, into adevelopment platform for business applications on application serv-ers from SAP — a platform used by over a million programmers.Consequently, the need for more information on ABAP and itsobject-oriented extensions and tools has grown exponentially; forexample, the need to address the following questions: What’s thebest way to start to use ABAP Objects? What are the typical tasks thatan ABAP programmer must perform? What basic concepts are theunderpinnings for the programming of SAP applications with ABAPObjects, and how does ABAP differ from other programming lan-guages? What goes on behind the scenes in transactions of the ABAPdevelopment environment, and which transactions are important toyou? These are only some of the questions that we have tried toaddress in this book.

Here, we’ll introduce you to the most important components, con-cepts, and ideas regarding SAP programming, namely, the informa-tion you’ll need to answer the aforementioned questions. This bookis intended for those of you who are looking for an up-to-date andquick tutorial to programming with ABAP Objects — an introductionbased on solving real-world tasks. The title of this book, ABAP Basics,says it all. We offer a basic course on the ABAP Objects programminglanguage. This book is based on application scenarios that discusstypical, everyday problems and solutions on the basis of comprehen-sive SAP systems and applications. The focus is always on practicalmatters: actual procedures are shown screenshot by screenshot. Thecomments on the language elements are by no means complete.They simply convey popular options for usage, and thereby maxi-mize the success of your learning experience.

The groundwork for this book was laid incrementally; it involvedmany years of training and practical experience, with topics thattoday would come under the overarching terms SAP and ABAP pro-gramming. Ongoing and intense collaboration with the developmentdepartments at SAP in Walldorf, Germany has enabled us to learn agreat deal about the SAP way of solving problems and what must beconsidered in the process. A practice scenario that uses the knowl-

Page 7: Sappress Abap Basics

12

Foreword

edge gained in individual chapters demonstrates how to create acomprehensive and professional application. This shared expertisewill enable you to become more familiar with the source code fromSAP and ultimately work to your advantage.

We are especially grateful to Horst Keller (SAP), who reviewed theindividual chapters and was always ready to advise and help us, andto Florian Zimniak (Galileo Press), whose editorial work ensured thepublication of this book.

We hope that this book will provide all readers with a quick and easyto understand introduction to ABAP and SAP application program-ming.

Julia Kirchner and Günther FärberNEXONTIS IT GmbH

Page 8: Sappress Abap Basics

72

Working with the Development Environment: The Object Navigator2

Figure 2.23 Loading a Package or Development Class into the Object List Area

We haven’t completed all the preparatory steps to create our firstprogram. The Object List area displays our (empty) package and wecan add additional development objects to it.

2.4 First Program: “Hello World” — REPORT, INCLUDE, and Application Menu

The word “program” is now part of the vocabulary of every school-age child and is most commonly associated with terms like compu-ter, software, and Internet. But what’s special about an ABAP pro-gram? How do you create one? How do end users work with pro-grams?

Basics No other programming language has experienced the kind of check-ered history that ABAP has had over the past 30 years. From its con-ception to the advent of SAP R/3, ABAP was designed solely for thecreation of reports, like a listing of all liabilities to customers or acompany balance sheet at the end of a fiscal year. ABAP programscould read data in the database and output it to the screen in table-based texts, or lists. Customers who use SAP software could modify

Page 9: Sappress Abap Basics

73

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

the ABAP source code of these reports or design new reports to meettheir needs. At that time (SAP R/2), programs with write access to thedatabase had to be programmed in Assembler (directly in themachine language). You can imagine the complexity and effortinvolved, and you can certainly understand that the task wasreserved solely for SAP itself.

With the introduction of SAP R/3 at the beginning of the 1990s, theABAP programming language had expanded to the point whereby itcould be used to implement write access to the database. That ena-bled writing all SAP R/3 application completely in ABAP — withoutthe help of other programming languages.

Module pool and report

ABAP generally offers several options for writing an executable pro-gram. The module pool and the report are the most important. Origi-nally, it was clear which alternative could be used at any given time.Complex input screens that had to be realized with the Dynpro inter-face technique (see Section 5.2) required a module pool. Creation ofa posting document in accounting is a good example here. Simpleinput templates, like the selection criteria for year and period in aperiod-end balance sheet, were programmed as reports. There havenot been any technical limitations on the use of either technologysince Release 3.0. Nevertheless, SAP continues to offer only a fewprograms that have been realized as module pools. In other words,reports have been in the forefront. Accordingly, this book concen-trates on programs of the report type and doesn’t cover program-ming with module pools. For special cases, ABAP also offers a varietyof other program types that we cannot cover here. If you would likemore information on these topics, we recommend that you read TheOfficial ABAP Reference (Horst Keller, SAP PRESS, Bonn 2005).

Because of the history involved, those familiar with SAP might usethe term report to describe a program. Technically, a report is justone of several options that can generate a program.

ABAP programs: cut small

Anyone who has ever started Word or Excel in Windows is alreadyfamiliar with large programs that take up several megabytes on thehard drive and that are completely loaded into main memory. ButSAP applications (like the Object Navigator or SAP CRM) consist of alarge number (often more than 100) of individual programs. Theuser often doesn’t even notice the switch from one program to thenext. An individual ABAP program is often designed for a very spe-

Page 10: Sappress Abap Basics

74

Working with the Development Environment: The Object Navigator2

cific task. For example, one program might handle the creation of asales order, another the creation of a delivery note, and yet anotherthe printing of an invoice. The organization of programs on onetopic into one directory in the application menu (SAP Easy Access)and forward navigation give the user the impression that she isworking with one large application.

This concept reflects an essential difference between ABAP and otherprogramming languages, such as C, Basic, and Pascal. The differencearises from a historical background. Every operation that writes tothe database used to have its own assembler program, and the sameidea still exists in ABAP.

Includes Includes allow you to modularize source code, i.e., to split it intosmall, manageable parts. The approach in ABAP is similar to that ofinclude files in other programming languages, such as C or Pascal.You can store any-size sections of source code in units that you loadwith INCLUDE name, where name contains the name of the include thatstores that part of the source code. For example, you would useincludes to store constants that are used in several applications. Eachprogram then links parts of the source code to the correct location inthe program with an INCLUDE statement and can then use that part atwill. The following excerpt of code clarifies the situation. The codecalculates a gross price from the net price entered by the user. Itaccesses a constant, CON_SALES_TAX , defined in an INCLUDE namedZPTB00_CONSTANTS for the sales tax rate:

Include programs perform nothing more than a library function forABAP source code and cannot be executed as independent programs.

Making a programavailable

To make your own ABAP program available to end users, performthe following steps:

REPORT zptb00_business_transaction.

INCLUDE zptb00_constants.

PARAMETERS:

net_price TYPE p DECIMALS 2.

DATA:

gross_price TYPE p DECIMALS 2.

* con_sales_tax is in include zptb00_constants defined.

Gross_price = net_price + net_price * con_sales_tax.

Listing 2.1 Code Excerpt to Link an Include

Page 11: Sappress Abap Basics

75

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

1. Create program Executable programs are created as source code within the ObjectNavigator and introduced with the key words REPORT or PROGRAM.

2. Write program codeThe program code, which consists of individual ABAP commands,is inserted after the key word REPORT.

3. Create a transaction for the programOnce the program is complete, a transaction code is assigned to it.You can enter the transaction code in the command line to startthe program directly.

4. Assign rights for starting the transactionAs an option, the administrator can limit execution of a transactionto a specific user or user groups.

5. Record transaction in the application menu The transaction is ultimately recorded in the application menu ofSAP Easy Access, where end users can easily find and execute it.

First program:“Hello World”

We now have the knowledge we need to develop our first programin ABAP. The program is the typical example used by beginning pro-grammers. It displays “Hello World” on the screen. We’ll use thisopportunity to become more familiar with the Object Navigator.

� Go to the Repository Browser of the Object Navigator. The fastestway is to enter “/nSE80” in the command line.

� Select Package as the object type (Development class in Release4.6).

� Enter the name of your development class or package (Z00_PRACTICE_TRAINING_BEGINNER) and click the Display buttonor press Enter.

� In the context menu for your package or development class, selectCreate � Program.

Exercise 2.2

Create a program, ZPTB00_Hello_World, which queries your name andthen displays it on the screen.

Test the program with the debugger.

Assign a transaction code to the program so that end users can call it.

Enhance the SAP application with an entry that calls the transaction.

Page 12: Sappress Abap Basics

76

Working with the Development Environment: The Object Navigator2

Figure 2.24 Creating a Program with the Context Menu

A dialog appears: you can enter the name of the program in it:

� Enter “ZPTB00_Hello_World” as the name of your program.

� Deactivate the checkbox With TOP Include and confirm yourentry with OK.

Another dialog appears: you can enter additional information aboutthe program. As you can see, the implicit assumption is that the pro-gram will reside in the package Z00_PRACTICE_TRAINING_BEGIN-NER.

� Enter “Hello World” as the title of the program. Leave the otherdefault entries alone.

� Confirm your entries with OK.

The last dialog prompts you for the transport request that will recordyour development and that will later copy it from one system to thenext. Because we have already created a package, the entry giventhere for the package appears here as a suggestion (see Figure 2.26).

Page 13: Sappress Abap Basics

77

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

Figure 2.25 Additional Information on the Program

� Confirm the transport request set by default. If none appears, useF4 to select a transport request that has already been created.

Figure 2.26 Entering the Transport Request for the Program

Program framework and comments

The new program has now finally been created, and the first lines ofsource code and some comments have already been inserted auto-matically as a framework for the program. As discussed in Section1.3, good comments are extremely important so that developers whohave not helped write the program can easily understand what itdoes or should do. Comments can occupy an entire line or appear atthe end of a line of code. If comments occupy an entire line, theybegin with an asterisk (*). If they appear at the end of a line of code,

Page 14: Sappress Abap Basics

78

Working with the Development Environment: The Object Navigator2

they begin with quotation marks ("). The compiler regards every-thing after these characters in a line as non-ABAP text and ignores it.

� Type the following lines as an additional program frameworkbeneath the comment lines:

The WRITE command displays the text that follows on the screen. Wewill discuss the command in more detail later on.

� Click the Check button or use Ctrl+F2.

If the line does not contain any syntax errors, a message to that effectappears in the status line.

� Click the Activate button or use Ctrl+F3.

� If no other program checks and activations produce an error, amessage to that effect appears in the status line. The text next tothe program name in the Tool area changes from inactive toactive.

� Click the Direct button or use F8.

The program is started and displays the desired text on the screen.The title of the program, “Hello World,” appears again, twice: in thetitle of the program and again in the output area. In the output area,it appears as a headline and is separated from the actual output by ahorizontal line.

Figure 2.27 Program ZPTB00_Hello_World in Action

� Click on the Back button to return to the Object Navigator and itssource display.

WRITE: / 'Hello World', '!'.

WRITE / 'This is my first program.'.

WRITE 'And not my last one'.

Page 15: Sappress Abap Basics

79

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

As you can see, our program already has working Back, Exit, andCancel buttons.

Now let’s modify the title of the program.

� Select Goto � Properties in the menu.

� Enter “Hello my friend” in the Title field and confirm with theSave button.

In the next step, we’ll set the formatting of the source code to reflectthe most common usage.

� Select Utilities � Settings in the menu.

A dialog appears: you can change a number of settings of the ABAPEditor.

� Select the Pretty Printer tab.

� Activate the checkbox Convert upper-/lowercase.

� Select the Keyword Uppercase radio button and confirm the set-tings.

Figure 2.28 User-Specific Settings of the ABAP Editors

Page 16: Sappress Abap Basics

80

Working with the Development Environment: The Object Navigator2

We also want to enhance the program somewhat so that it asks theusers for a nickname and then greets them with their nicknames.

� Insert the following source code:

We’ll take a more detailed look at the PARAMETERS command later on.Here, it’s enough to note that it can accept user entries at the start ofa program and make them available for further processing.

� Click the Pretty Printer button.

� Activate the source code with Ctrl+F3 and start the program withF8.

Our program then appears with a modified title and an input fieldFigure 2.29).

� Enter your nickname, “Heidelberger,” and click the Execute but-ton or F8.

Figure 2.29 Entering a Nickname

The display now includes your nickname.

� Select the Back button or F3.

Figure 2.30 Output of Program ZPTB00_Hello_World

PARAMETERS:

p_nicknm(15) TYPE c.

WRITE: / 'Hello World', p_nicknm, '!'. "First statement

Page 17: Sappress Abap Basics

81

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

DebuggingNow let’s execute the program step by step to become more familiarwith the debugger. Users of Delphi, Visual Basic, and Java (JBuilder)will have to get used to a different user interface. Debugging of anABAP program occurs in a separate program rather than in the edi-tor, but the familiar functionality of other programming languages isstill available.

The ABAP debugger offers the following essential features:

� Single-step button Executes a program line by line. After execution of the statementin one line, the processing arrow is placed on the next statement.If the current statement involves a subprogram, function, ormethod, the debugger looks for the next complete statement andplaces the processing arrow there.

� Execute buttonExecutes a program line by line, but also executes the statementsof subprograms, functions, and methods as a whole (in a singlestep). The processing arrow is then placed on the next statementin the same part of the program.

� Return buttonExecutes all the lines of the current program at one time, so youcan use it to execute the remaining statements of a subprogram,function, or method. Our sample program contains only a mainprogram portion, so it is executed right up to its end.

� Continue (to cursor) buttonExecute the program as a whole rather than step by step, as is typ-ical without debugging. But if you have previously marked a state-ment in the debugger by double-clicking, execution stops and theprocessing arrow remains on that statement.

� Debugging/Goto statement If you have marked a statement by clicking it, the processingarrow moves to that statement, whether the statement is ahead ofor behind the processing arrow and whether doing so makessense in terms of the program logic.

� Debugging/RestartThis menu entry stops the program at the current statement andreturns to the Object Navigator. You can restart the program fromthere.

Page 18: Sappress Abap Basics

82

Working with the Development Environment: The Object Navigator2

� Create/Delete context menu/breakpoint You can create a stop, a breakpoint, on almost any statement. Exe-cution of the program will stop at the point, regardless of whatbuttons you've already clicked. If you then click the Save button,breakpoints remain in effect until you close the session. If youreselect the menu entry, the breakpoint is deleted. You can alsocreate and delete a breakpoint by double-clicking to the left of astatement.

� Breakpoint/Breakpoint atIn this menu, you can set breakpoints at specific locations withinthe program, even when the processing arrow is not located closeby. You often need Breakpoint at function module and Break-point at statement.

� Examine field content Double-clicking a field (such as parameter p_nicknm in our sourcecode) displays the content under the source code.

� Change field content button You can even change field content during debugging. Take thesame steps you do when you examine field content. You can enternew content where the previous content is displayed and thenkeep the modification by clicking the Change field content button.

� Calls buttonWhen debugging large programs that contain subprograms, func-tion modules, or methods, it's important to know where thoseitems are called in the source code. That's the information pro-vided by the stack list, which is displayed when you click the Callsbutton. You can also return to the source-text display of thedebugger with the Back button.

� Settings buttonYou can change the behavior of the debugger. You can use the Set-tings button to display and change all configuration options.

Let’s look at the ABAP debugger in the real world.

� Select Execute � Debugging in the context menu of the program.

An input field is displayed: you can enter your nickname here.

� Enter your nickname and confirm you entry with F8.

Page 19: Sappress Abap Basics

83

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

Figure 2.31 Context Menu: Execute � Debugging

After entering all the parameters, you move to the debugger. Theprocessing arrow points to the first statement, the REPORT statementin this case.

� Select the Single step button or F5.

Figure 2.32 The Debugger on the REPORT Statement

The processing arrow moves from the REPORT statement to the firstWRITE statement.

Page 20: Sappress Abap Basics

84

Working with the Development Environment: The Object Navigator2

� Double-click parameter p_nicknm.

The current content of the parameter is displayed in the list underthe source code.

� Select the Execute button or F6.

Figure 2.33 The Debugger Displays the Content of a Parameter

The processing arrow is now at the second WRITE statement.

� Change the content of the input field from “Heidelberger” to “Ber-liner.”

� Click the Change button.

� Click the first WRITE statement.

The processing arrow is still at the second statement.

� Select Debugging � Go to Statement in the menu.

The processing arrow returns to a position in front of the first WRITEstatement.

� Click the last WRITE statement.

� Select the Continue (to Cursor) button or F8.

Page 21: Sappress Abap Basics

85

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

Figure 2.34 The Debugger Displays the Modified Content of the Parameter

Figure 2.35 Manipulated Position of the Processing Arrow

The processing arrow then moves to the last WRITE statement.

� Select the Return button or F7.

Page 22: Sappress Abap Basics

86

Working with the Development Environment: The Object Navigator2

That executes all the statements of our main program (the last state-ment); the screen displays the results.

Figure 2.36 All Program Outputs Are Displayed

As you can see, we have twisted the logic of our program by modify-ing the parameters and executing the WRITE statement again. Now itoutputs two nicknames instead of one. Ultimately, the exampleshows the powerful features of the debugger, especially the ability tomodify and move the processing arrow deliberately. During debug-ging, you can force the program to behave in ways that would neveroccur in real operations.

Transaction Now let’s make our program available to end users who normallydon’t have access to development tools. You would typically create atransaction here: a link that enables starting the program from thecommand line.

Given this history at SAP, the term “transaction” often replaces “pro-gram.” In technical terms, however, a transaction is a link to a pro-gram, as described in the following. To explain the multiple mean-ings of the term thoroughly, Chapter 4 covers database transaction.

� Select Create � Transaction from the context menu of yourpackage or development class.

A dialog appears, in which you can specify additional detailed infor-mation on the transaction and a transaction code that is as short aspossible.

� Enter “ZPTB00_HW” as the transaction and “Hello World andNickname” as the short text.

� Define the transaction of type Program and selection screen(report transaction) and confirm it with OK.

Page 23: Sappress Abap Basics

87

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

Figure 2.37 Content Menu: Create � Transaction

Figure 2.38 Create Transaction

The tool area then displays additional information that you can spec-ify.

� Enter “ZPTB00_HELLO_WORLD” as the program.

� Define the GUI Ability as appropriate for HTML, Java, and Win-dows; click the Save button or Ctrl+S.

Page 24: Sappress Abap Basics

88

Working with the Development Environment: The Object Navigator2

As is always the case when you create a new development object,you must specify a transport request that will log your actions.

� Confirm the usual transport number with OK.

The transaction has now been created and we can try it out:

� Enter the transaction code (preceded by “/n”) in the command lineand confirm with Enter.

Figure 2.39 Trying Out the New Transaction

The program we have written, ZPTB00_HELLO_WORLD, then starts.

� Use F3 to return to the Object Navigator.

Area menu As you can see, it’s quite simple to make a program available to endusers. But end users learn a transaction code only for programs theyuse quite frequently, so let’s make access to the program more user-friendly, and include it in the application menu in SAP Easy Access.The application menu is a large menu tree that consists of individualarea menus. The area menus contain topically related applicationsand organize them into menus and submenus.

Figure 2.40 Application Menu of SAP Easy Access Consists of Several Area Menus

Abbildung 2.40

Area Menus

Menu Item

Page 25: Sappress Abap Basics

89

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

Accordingly, the application menu is really an area menu that’s par-ticularly large, is connected with many other area menus, and is dis-played by SAP Easy Access.

Creating an area menu

Our task here is to create an area menu we can use to store our trans-action and a menu text. We’ll then add it to a specific location in theapplication menu, making it available to all users.

� Select Create � Additional � Area Menu in the context menu of thepackage or development class.

A dialog appears: you can enter a unique name and short text as adescription.

� Enter “ZPTB00” as the name of the transaction.

� Enter “Training for beginners” and confirm with OK.

Figure 2.41 Creating an Area Menu

A program appears that fills the entire work area.

� Check the entry for Training for beginners.

� Select the Add entry as subnode button or Shift+F7.

Figure 2.42 Editing the Area Menu

A dialog appears: you can make entries for the area menu.

� Enter “Hello World and Nickname” and Transaction code“ZPTB00_HW” and confirm with OK.

Page 26: Sappress Abap Basics

90

Working with the Development Environment: The Object Navigator2

Figure 2.43 Creating a New Menu Entry

The main window reappears and we can save the area menu.

� Click the Save button or Ctrl+S.

A dialog appears that requests the name of the package or develop-ment class that will store the area menu.

� Enter “Z00_PRACTICE_TRAINING_BEGINNER” as the packageand save the entry.

Figure 2.44 Package That Will Store the Area Menu

As always, the last request is for the transport request that will logthe changes to this development object.

� Confirm with OK.

Page 27: Sappress Abap Basics

91

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

Adding to the application menu

We have now created a small submenu for our programs and trans-actions. But we still have not added the submenu to the applicationmenu provided by SAP.

� Select the Cancel button until you return to SAP Easy Access.

� Start SAP Menu � Tools � ABAP Workbench � Development � Addi-tional Tools � Area Menus or Transaction SE43N.

A window appears: you can enter the area menu you want to workwith. We want to enhance the SAP application menu that is storedunder the name “S000”.

� Enter the name of SAP application menu “S000” or select it withF4 help.

� Select the Display area menu button or F7.

The area menu then appears; you’re already familiar with it fromSAP Easy Access.

Figure 2.45 Selecting Area Menu S000

� Check the entry for SAP R/3 System.

� Select the Display <-> Change button or Ctrl+F1.

Page 28: Sappress Abap Basics

92

Working with the Development Environment: The Object Navigator2

Figure 2.46 Displaying Area Menu S000

A security query appears: enter the editing mode.

� Click the Enhance button.

Enhancement ID A dialog opens. Enter the Enhancement ID that you want to use tostore your modification. Put simply, your changes are not made tothe original, but in a copy that will later be blended with the original.If you have not yet created an enhancement ID, you must do so now.You can use this ID for all later modifications of the menu.

� Click the Create Enhancement ID button.

Another dialog opens, prompting you to enter a text that describesyour enhancement ID.

� Enter “ZPTB00” as the Enhancement ID, “Enhancement for ownarea menu” as the Explanatory text, and confirm with Enter.

Figure 2.47 Creating an Enhancement ID

Your enhancement ID appears under Enhancement ID: Original, andyou can now begin the modification.

� Click Enhancement ID ZPTB00.

� Select the Select button (magnifying glass).

You are now in editing mode for the menu and you want to insertyour area menu into the second level.

Page 29: Sappress Abap Basics

93

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

Figure 2.48 Selecting the Enhancement ID Originals

� Click the uppermost entry in the list (usually SAP R/3 System).

� Select Insert as subnode from the context menu.

Figure 2.49 Inserting the Area Menu One Level Deeper

Page 30: Sappress Abap Basics

94

Working with the Development Environment: The Object Navigator2

In the next dialog, you can enter your menu entries directly or addthem to an area menu. We’ve already created an area menu, so let’suse it here.

� Enter “Practice Training Beginner” as the text.

� Check the checkbox to identify your entry as an area menu.

� In the Transaction code/menu column, press the F4 key to selectyour area menu easily.

Figure 2.50 Creating New Entries

Your area menu appears at the bottom of the suggested values.

� Check area menu ZPTB00 and press the OK button to include yourarea menu as an input field.

� Click the OK button again to place your area menu in the applica-tion menu.

� Click the Save button to save your changes.

The familiar dialog that asks for the transport request appears.

� Confirm with Enter to use the suggested request.

Page 31: Sappress Abap Basics

95

First Program: “Hello World” — REPORT, INCLUDE, and Application Menu 2.4

Figure 2.51 Saving Menu Changes

Now let’s see what our enhancement actually looks like: we’ll goback to display mode.

� Click the Display <-> Change button to switch to display mode.

The application menu has now been enhanced with our area menuand contains the new transaction for our “Hello World” program.

� Quit the application by clicking the Cancel button until you returnto SAP Easy Access.

Figure 2.52 Application Menu with New Area Menu and Transaction

In SAP Easy Access, you’ll see that your changes are not (yet) dis-played. You have to restart the menu to see your changes.

� Click the SAP Menu button.

The complete menu is reloaded. As desired, your enhancementappears as the first submenu.

Page 32: Sappress Abap Basics

96

Working with the Development Environment: The Object Navigator2

Figure 2.53 Application Menu Before the Update

Figure 2.54 Application Menu After the Update

Page 33: Sappress Abap Basics

97

Online Help, help.sap.com, service.sap.com, and SAP Notes 2.5

2.5 Online Help, help.sap.com, service.sap.com, and SAP Notes

Help and support are your primary needs when learning a new pro-gramming language. Doing everything yourself and making sense ofit all requires a great deal of time. That’s the reason behind this book,and SAP offers a variety of other information.

BasicsIn addition to traditional training and support from consultants, SAPand its partners offer a large number of sources of electronic infor-mation to different target groups. This chapter introduces some ofthe most important sources of information.

� Online helpThese days, almost every application offers online help and SAPapplications are no exception. Note the distinction betweenonline help for various applications (Object Navigator, reuselibrary, etc.) and online help for ABAP itself, along with its state-ments (WRITE, PARAMETER, etc.) and development objects (programs,tables, etc.). Local installation of the web-based knowledge ware-house from SAP covers the first kind of online help; the databasemanages documentation on ABAP key words.

� SAP Help Portal (help.sap.com)This information source is designed for SAP users and developers.It is available to all free of charge over the Internet, and is compa-rable with the help portals of other manufacturers, such asMSDN.microsoft.com. In addition to online help for variousreleases of SAP software, it contains comprehensive, cross-applica-tion documentation on all development and administrative tools,ABAP statements, and ABAP development objects.

� SAP Service Marketplace (service.sap.com)This information source is primarily intended for SAP administratorsand consultants. It's accessible to SAP customers and partners on theInternet. In addition to technical installation and configurationguidelines, it offers lists of business functions, business scenarios,and descriptions of best practices for individual SAP applications.

� SAP NotesSAP calls its replies to support questions from customers and part-ners "SAP Notes." The term applies to questions that might wellhave general interest. The replies are made anonymously and areunderstandable to a general audience before being given a unique

Page 34: Sappress Abap Basics

98

Working with the Development Environment: The Object Navigator2

number, categorized by applications, and published. This channelprovides tips, solutions to problems, and even patches.

Online help Let’s start with online help, which you can call with F1 from everyprogram. Regardless of a focus on an input field, tab, or window,online help displays specialized help for applications and parts ofapplications. Here’s a brief example:

� Place the cursor on the key word REPORT in the source code of yourprogram and press F1 to call online help for this command.

A new window, ABAP Keyword Documentation, is displayed. Itexplains the REPORT command in a variety of forms. The left side dis-plays the navigation tree: a list of individual documentation that isorganized by topic.

Figure 2.55 Online Help for Key Word REPORT

Exercise 2.3

Use the online help on the ABAP editor to display information on the useof the ABAP key word REPORT.

Surf to the SAP Help Portal at help.sap.com, and read the information onexecuting a report.

Surf to SAP Service Marketplace at service.sap.com, and download themost recent problem reports and patches on activating data elements.

Page 35: Sappress Abap Basics

99

Online Help, help.sap.com, service.sap.com, and SAP Notes 2.5

We’re also interested in documentation on the key word PROGRAM;we’re already familiar with it from other programming languages asthe introduction to a source code.

� Double-click the key word PROGRAM in the navigation tree of onlinehelp.

The description on the right side changes and explains that thePROGRAM command is a synonym for the REPORT command.

SAP Help PortalLet’s take a closer look at the SAP Help Portal that supplies program-mers with information on ABAP development. As an example, we’lllook for information on reports.

� Start your browser and enter “help.sap.com” as the URL.

� Click SAP NetWeaver in the navigation bar on the left side. Ifyou’re working with SAP Application Server 4.6, you must clickSAP R/3 and R/3 Enterprise instead.

Figure 2.56 Online Help for Key Word PROGRAM

� A list of all available releases is displayed. Select the latest releasethat you use (SAP Web Application Server or SAP R/3 4.6C). Theright side of the help screen lets you select help for the latest sup-port package (including all previous support packages for therelease) and an entire help offering.

Page 36: Sappress Abap Basics

100

Working with the Development Environment: The Object Navigator2

� Click your preferred language from the entire help offering (seeFigure 2.57).

Figure 2.57 SAP Help Portal

The knowledge warehouse from SAP appears. It displays the entiresubject area on the left side and the contents on the right side. Youcan scroll by topic title or use the full-text search.

� Click Search in the menu.

Figure 2.58 Full-Text Search in the SAP Library

Page 37: Sappress Abap Basics

101

Online Help, help.sap.com, service.sap.com, and SAP Notes 2.5

� Enter “execute report” as the search string. Select AND as thesearch mode. Check to ensure that the additional arguments areset to include SAP NetWeaver, SAP Web Application Server 6.20as the application, and your preferred language. Confirm yourselection with the Search button.

The screen then displays a hit list based on the search string.

� Click Execute Report in the hit list.

Figure 2.59 Hit List for “Execute Report”

Figure 2.60 Help on “Executing a Report”

Page 38: Sappress Abap Basics

102

Working with the Development Environment: The Object Navigator2

The help document on “Executing a Report” is displayed.

The help portal is preferable even when the information (such ashelp for an ABAP statement) you are looking for is available in onlinehelp. That’s because of the high-performance search engine that dis-plays a list of results in a few seconds, offering you quick access tothe information.

SAP ServiceMarketplace

You can visit SAP Service Marketplace from the help menu of everySAP application and over a web browser. Let’s look at a few pagesfrom the comprehensive help portal as examples.

� Select Help � SAP Service Marketplace or open service.sap.com inyour web browser.

The home page of SAP Service Marketplace appears. Your SAPadministrator can supply you with the information you need to logon.

� Click the Login Now button and log on.

Figure 2.61 SAP Service Marketplace: Logon Page

After you have logged on, you reach the home page of SAP ServiceMarketplace. Here you’ll find very interesting “solutions in detail”and information on consulting, training, and support.

� Click Support in the menu.

Page 39: Sappress Abap Basics

103

Online Help, help.sap.com, service.sap.com, and SAP Notes 2.5

This area is by far the most comprehensive part of SAP Service Mar-ketplace. The right side has a menu area from which you can controlall further information on the support site.

SAP NotesSAP Notes are by far the most important element for administratorsand developers. You can call them via the Search for SAP Notes linkon SAP Service Marketplace. As a practical example, we’ll look forSAP Notes on activating development objects.

� Click the Search for SAP Notes link.

Figure 2.62 Support Page of SAP Service Marketplace

A search screen appears: you can search for SAP Notes on a specificapplication directly by entering key words and numbers or by enter-ing a topic.

� Click the magnifying glass icon next to Topic.

A selection dialog appears. It displays all SAP applications in a hier-archical list. We’ll search for SAP notes on activating developmentobjects.

� Navigate to the application components in the tree and click BC-DWB-DIC-AC.

Page 40: Sappress Abap Basics

104

Working with the Development Environment: The Object Navigator2

Figure 2.63 Searching for SAP Notes

Figure 2.64 Selecting Application Components

The selection dialog closes and your entry is copied to the searchscreen.

� Click the Search button.

Page 41: Sappress Abap Basics

105

Online Help, help.sap.com, service.sap.com, and SAP Notes 2.5

A hit list is displayed with all matches for the selected applicationcomponent.

� Navigate through the hit list and click the SAP Note you werelooking for: Error during background activation of data ele-ments.

The SAP Note is displayed.

Figure 2.65 Selected SAP Notes on the Background Activation of Data Elements

Page 42: Sappress Abap Basics

469

Index

1:1 relation 2083GL language 1074GL language 107

A

ABAP 17, 21, 109, 463ABAP debugger 81ABAP Dictionary 463ABAP Editor 50, 79ABAP Objects 13, 23, 320ABAP runtime environment 23, 463ABAP workbench 28, 56, 58, 463ABAP/4 22Adapter 463Advanced Business Application Program-

ming 463ALV 233Ancestor 352AND, boolean operator 177ANY TABLE 145any, data type 138API 463API layer 399APPEND 145Application 463Application base 17Application menu

adding 89Application Programming Interface 463Application toolbar 260Area menu 88

create 89Array 107AS CHECKBOX 119Assignment 111Attribute 324Authentication 35Avoiding redundancy 151

B

Back end 24, 25, 27Backward navigation 49BAdI 31BAPI 31, 463BEGIN OF 141BEGIN OF BLOCK 228BEGIN OF SCREEN 228BETWEEN, comparison operator 172Boolean data type 124Branching instruction 170Browser area 56Business module 21Business process 463Business scenario 463Business server pages 56, 463

C

c, data type 120CA, comparison operator 173Call by Reference 157Call by Value 157CALL METHOD 329CALL SCREEN 264CALL SELECTION-SCREEN 230CALL SUBSCREEN 264CASE ... WHEN 177Casting 119CHAIN ... ENDCHAIN 262CHANGING 156Changing parameter 155Character 120Check list for programmers 29Checkman checks 461Child class 352CLASS 323Class attribute 331Class definition 324Class hierarchy 352Class implementation 326CLASS_CONSTRUCTOR 330

Page 43: Sappress Abap Basics

470

Index

CLASS-DATA 331CLASS-EVENTS 372CLASS-METHODS 331Client 21, 29, 36, 464CLOSE CURSOR 214CN, comparison operator 173CO, comparison operator 173COLLECT 146Command line 40Comment 30Comment language 30Component 464Component information 46Constant 118Constraint 195CONSTRUCTOR 330CONTINUE 183, 184Control example 56CONTROLS 268Counting loop 183CP, comparison operator 174CREATE DATA 117, 125CREATE OBJECT 323, 328CS, comparison operator 174

D

d, data type 123Data 117, 324Data Dictionary 463Data element 192

create 199, 216, 274define 195edit documentation 200in tables 208

Data instances 322Data transfer 210Data type 120Database design 192Database table 208

fields 208DB layer 400DDIC 463Debugging 52, 81Decentralized build 53Declaration 117Declarative programming model 107

Deep structure 141DEFINITION 325DELETE 143, 147, 213Derived class 352Descendent 352DESCRIBE FIELD 332Descriptive properties 195DESTINATION 154Developer key 25, 26, 27Development class 63

create 69Development language 30Development object 52Development system 29Dictionary data type 193

built-in 194selecting 194

Directory 464DNS address 35DO ... ENDDO 183Domain 195

create 216, 272Drag&drop 32DUPLICATES 147Dynamic data 117, 125Dynpro 258, 464Dynpro flow logic 109

E

END OF 141, 228END OF BLOCK 228ENDFORM 152ENDING AT 231Engine 464Enhancement ID 92EnjoySAP 233EQ, comparison operator 171ERP 21Event 370, 371

declaring 372EXCEPTIONS 156EXIT 183, 184EXPORTING 155, 156, 326Extended program check 461

Page 44: Sappress Abap Basics

471

Index

F

f, data type 122F1 help 57F4 help 60FETCH 214FIELD 262FIELD-SYMBOLS 119Financials 13Flat structure 141Floating point number 122Font convention 16Foreign key 207FORM 152Forward navigation 49Framework 352Front end 24, 26, 27Front-end integration 33FUNCTION 153Function 151, 324Function group 153

create 284Function module 153

create 285

G

Garbage collector 125, 327GE, comparison operator 172GET 110GET CURSOR 110, 268GET PF-STATUS 265GET PROPERTY OF 110GET REFERENCE OF 110, 117GET TIME 110Global class

create 342, 363declaring an event 383defining a method 342defining attributes 346, 364defining event-handler methods 385redefining the method 364

Global table types 224, 340Glue-Logic 370GT, comparison operator 171GUI 464GUI status 236, 237, 260

create 289

GUI titlecreate 288

GUIDs 17

H

Handler class 373Handler method 372

declaring 373Hardware 25, 27Hash Algorithm 144HASHED TABLE 144help.sap.com 97, 99Hexadecimal 122Hierarchical database 20

I

i, data type 121IF ... ELSE 177IMPLEMENTATION 327IMPORTING 155, 156, 326IN 229INCLUDE 74, 152INDEX TABLE 145Inheritance 352INHERITING FROM 353Input elements 118Input interfaces, simple 227Input parameter 155INSERT 143, 145, 211Instance constructor 329Integer 121Interface 31, 154Interface element

create 292Interface parameter 151, 154Internal table 139, 143Internal table types 143

generic 145Internet standards 465Internet technology 17IS ASSIGNED, comparison operator 175IS BOUND, comparison operator 175IS INITIAL, comparison operator 176IS REQUESTED, comparison operator

176IS SUPPLIED, comparison operator 176

Page 45: Sappress Abap Basics

472

Index

J

J2EE 465Java 17Java 2 Platform Enterprise Edition 465Just-In-Time Compiler 50

K

Key 207Knowledge warehouse 100

L

Layer model 399LE, comparison operator 171LEAVE SCREEN 270Library 352License renewal 27List 72List heading 127List of functions 395Listener concept 371Local Class 332Local language 196Logical expression 170Logon 31Logon transaction 35LOOP 146LOOP ... ENDLOOP 263LOOP AT SCREEN 266LT, comparison operator 171

M

Main memory 116Main package 64MAPI layer 399Mapping 194Mass data 139Massachusetts Institute of Technology

(MIT) 319Master data check 195Materials management 13MDI window 32

Menu bar 260Menu entry

creating 90Menu system 39MESSAGE 231Message

create 241define 286output 231

Message class 232create 241, 286

Message server 35Metadata 124, 196METHOD 321, 331Method 323

defining transfer parameters 344Method pointer concept 371Method redefinition 354METHODS 324, 373Microsoft 19Microsoft .NET 465MM 13MODIFY 143, 147, 213MODIFY SCREEN 267Modularization 151MODULE 261Module pool 73MOVE 111MOVE-CORRESPONDING 142

N

n : 1 relation 207n : m relation 208n, data type 121NA, comparison operator 173Name conflict 67Namespace 30, 66

customer 453Naming convention

constants 455DDIC data types 456error messages 459function groups 457function modules 457general 452message classes 458

Page 46: Sappress Abap Basics

473

Index

messages 459modules 459program-local data types 455screens 460subprograms 458variables and parameters 453warnings 459

Native SQL 214, 465NE, comparison operator 172Nested structure 141NON-UNIQUE KEY 144NOT, boolean operator 177Notation rule 109NP, comparison operator 174NS, comparison operator 174Numeric 121

O

OBJ layer 399Object 319, 322Object creation 328Object dereferencing 328Object instance 322Object list area 56Object navigator 51

browser area 56getting started 54object list area 56tool area 56

Object orientation 319Object type 322Object-oriented Programming 320OBLIGATORY 119Offset 111Online help 97, 98OPEN CURSOR 214Open SQL 210, 465Operator 170OR, boolean operator 177Oracle 19Original class 352Original language 30Output parameter 155

P

p, data type 122Package 63Packed 122PARAMETERS 80, 110, 118, 227, 230Parent class 352passed data 154passed parameter 154passed variable 154Password 37PERFORM 152Performance example 57Polymorphism 351, 354Pretty Printer 79PRIVATE SECTION 324Procedural programming 151, 320Procedure 151PROCESS 261PROCESS AFTER INPUT 261PROCESS BEFORE OUTPUT 261PROCESS ON HELP-REQUEST 261PROCESS ON VALUE-REQUEST 261Production system 29Program 72

copying 134create 76

Program check 461Programming guideline 31, 451Property 326PROTECTED SECTION 324PUBLIC SECTION 324Publish and subscribe 371

R

RAD tools 370RAISE EVENT 375RAISING 152, 156RAM 116Rapid application development 370READ 143, 146Record 140, 206REDEFINITION 331, 354

class constructors 355Instance constructors 354methods 354

Page 47: Sappress Abap Basics

474

Index

REF TO 119REF TO OBJECT 328Reference variable 117, 125REFRESH CONTROL 269Relational database design 207Relational Type 208Release 465Remote Function Call 465REPORT 83Repository 466Return value 111RETURNING 326REUSE_ALV_GRID_DISPLAY 234REUSE_ALV_GRID_LAYOUT_INFO_rGE

T 234REUSE_ALV_GRID_LAYOUT_INFO_rSET

235RFC 465RTTI 332Runtime analysis, SE80 461Runtime type identification 332

S

SAP accesssetup 23

SAP Basis 20SAP Customer Relationship Manage-

ment 13SAP Easy Access 38, 466SAP GUI 35, 466SAP GUI for Java 26SAP Help Portal 97, 99SAP Library 100SAP List Viewer 225, 233SAP Menu Painter 259SAP NetWeaver 22SAP NetWeaver Application Server

17, 21SAP NetWeaver Exchange Infrastruc-

ture 397SAP Notes 97, 103SAP Screen Painter 259SAP Service Marketplace 97, 102SAP Supply Chain Management 13SAP System 466SAP system

back end 24front end 24

hardware 24Linux 25Windows 26

Save 40Screen 260

components 259creating 290

Screen flow logic 259, 261, 302, 305Screen painter 24SELECT 210Selection list 397Selection text 127

editing 202SELECTION-SCREEN 227SELECTION-SCREEN COMMENT 228SELECTION-SCREEN PUSHBUTTON

228SELECTION-SCREEN ULINE 228SELECT-OPTIONS 228Server cluster 35service.sap.com 97, 102Session 41

new 48SET 111SET CURSOR 267SET EXTENDED CHECK ON/OFF 111SET HANDLER 374SET HOLD DATA 269SET PARAMETER 111SET PF-STATUS 265SET SCREEN 265SET TITLEBAR 266Signature 154Single server 35Single Sign-On 37, 466SORTED TABLE 144Specification 394Stack list 82Standard business software 13STANDARD TABLE 144Standard toolbar 39, 260STARTING AT 230Starting program 47Static attribute 330Static constructor 330Static method 330Static variable 117Status bar 260Status line 41Stop transaction 39

Page 48: Sappress Abap Basics

475

Index

string, data type 124Structure 139, 140

create 282Structure package 64Subprogram 151subprogram return code 111SUPPRESS DIALOG 270SY 111sy-dbcnt 112sy-host 112sy-index 112, 184System command 110System field 111System information 41System requirements 16System setup 31System status 45sy-subrc 111, 156sy-tabix 112sy-uname 111

T

t, data type 123Table

create 216, 277Table control 263Table Control Wizard 295Table key 144TABLE OF 143Table type

create 281Table view 263TABLES 156Technical name 43Technical property 195Test system 29Text element 126Text symbol 127

creating 286TIME ZONE 116Title bar 260Tool area 56Transaction 43, 60, 86

create 87Transformation layer 398Transport management system 62

Transport organizer 62Transport organizer tool 67Transport request 70Transport system 54TRANSPORTING 147TYPE 117Type casting 334Type checking 196TYPE REF TO 118Type safety 196TYPES 141

U

Unicode 17UNIQUE KEY 144UPDATE 212Usage explanation 193User name 37USING 155

V

VALUE 117, 326Value help 60Variable 117Visibility 324

W

Web Dynpro 33, 109, 226, 466Web service 466WHERE 211WHILE ... ENDWHILE 184Workplace computer 21WRITE 78, 110

X

x, data type 122xstring, data type 124

Page 49: Sappress Abap Basics

476

Index

Z

ZPTB00_BUSINESS_TRANSACTION 271ZPTB00_HELLO_WORLD 75ZPTB00_HOTEL_RESERVATION 215ZPTB00_HOTEL_RESERVATION_COOL

236ZPTB00_INTERNAL_TABLE_JUGGLER

147ZPTB00_PERFORMANCE_TESTER 158ZPTB00_PRODUCT_CONFIGURATOR

335ZPTB00_PRODUCT_CONFIGURATOR_

GLOBAL 340

ZPTB00_PRODUCT_ENHANCER 355ZPTB00_PRODUCT_ENHANCER_GL

363ZPTB00_PRODUCT_EVENT 375ZPTB00_PRODUCT_EVENT_GL 383ZPTB00_PROVISION_CALCULATOR

179ZPTB00_ROOM_CHECKER 197ZPTB00_SALES_ORDER 127ZPTB00_SALES_ORDER_DYNAMIC 133ZPTB00_SAVINGS_CALCULATOR 185ZPTB00_SYSTEM_INFORMATION 112