Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
277 views
SAP Library - ABAP Objects
SAP Library - ABAP Objects
Uploaded by
Diogo Max
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save SAP Library - ABAP Objects For Later
Download
Save
Save SAP Library - ABAP Objects For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
277 views
SAP Library - ABAP Objects
SAP Library - ABAP Objects
Uploaded by
Diogo Max
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save SAP Library - ABAP Objects For Later
Carousel Previous
Carousel Next
Save
Save SAP Library - ABAP Objects For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 287
Search
Fullscreen
HORST KELLER ee KRUGER ABAP Objects An Introduction to Programming SAP Applications MW Library a AYEOther titles in the series Flying start with SAP R/3 by Gabriele Schicht and Andrea Schmieden SAP R/3 Quality Management by Michael Hélzer and Michael Schramm ‘SAP R/3 Plant Maintenance by Britta Stengl and Reinhard Ematinger SAP R/3 Financial Aecounting by Sandra Brinkmann and Axel Zelinger Security and Data Protection with SAP Systems by Werner Homberger and Jirgen Schneider mySAP.com Industry Solutions by Prof Dr Henning Kagermann and Dr Gerhard Keller SAP R/3 Performance Optimization by Thomas Schneider SAP R/3 Change and Transport Management by Sue McFarlane Thetzger and Susanne Roehrs ‘SAP R/3 System Administration by Liane Will ABAP Objects Introduction to Programming SAP Applications Dr Horst Keller and Sascha Kriiger Wy Addison-Wesley {london «Boston» Indianapolis. New York. Mexico Cty» Toronto Sydney «Tokyo» Singapore» Hong Kong + Cape Towa» New Dell Madi: Pariss Amsterdam » Munich = Milan StockholmsBAP Workbench 1 Navigator 1 Jen the program and screen| | viene | 23:12 23.13 23.14 23.15 23.16 23.17 Creating a class Working with objects Working with global classes Final steps Resources Final comments on the practical introduction ees! BASICS OF ABAP PROGRAMMING 3A i 32 33 34 The environment of an ABAP program Bad “The architecture of an SAP System ABAP programs in the client-server architecture 3.2.1 3.2.2 The SAP Basis System ‘The ABAP runtime environment ABAP programs in the runtime environment 331 332 33.3 334 335 3.3.6 337 BAP program structure Processing blocks Program types Screens Program execution Calling programs internally Ending ABAP programs ‘Memory organization of ABAP programs (4 }mibasrcrABAPILANGUAGE"ELEMENTS! aa l 42 43 Introduction Data types and data objects 421 422 423 424 425 426 427 428 Introduction to the ABAP type concept The ABAP type hierarchy Built-in elementary data types Data types and data objects local to the program Data types in the ABAP Dictionary Flat and deep data types Generic data types for typings Data objects in detail Operations and expressions 43d 432 433 ‘Assigning values ‘Type conversions Numeric operations 4s a7 48 82 55 57 59 59 6 62 63 64 64 69 2B 76 76 82 84 84 87 88 88 90 31 96 104 13 4 ns 124 124 126 131 CONTENTS 4.3.4 Logical expressions 44 Control structures 4.4.1 Conditional branches 44.2 — Loops 4.5 Processing character strings 4.5.1 Operations with character strings 4.5.2. Comparing character strings 4.5.3 Addressing subfields 4.6 Field symbols and data references 4.6.1 Field symbols 4.6.2 Data references 4.7 Internal tables 4.7.1 Defining internal tables 4.7.2 Working with internal tables 4.7.3. Internal tables with header rows 4.7.4 — Extract datasets 4.8 Error handling in ABAP programs 48.1 Statically identifiable errors 4.8.2 — Runtime errors THE ABAP' PROGRAMMING MODELS. 5.1 Introduction 5.2. The classical (procedural) programming model 5.2.1 Modularization 5.2.2 Excursion: source code modularization 5.2.3. Visibility and lifetime of data 5.3. The object-oriented programming model 5.3.1. How do we define object-orientation? 5.3.2 Classes 5.3.3. Objects and object references 5.34 — More on defining and calling methods 5.4 Summary and outlook ADVANCED °CONCEPTS’OF OBJECT-ORIENTED. PROGRAMMING WITH ABAP OBJECTS 6.1 Introduction 6.2 Inheritance 6.2.1 Basic principles 6.2.2 Syntax for subclasses 137 142 142 144 147 147 152 154 195 156 164 169 170 175 187 189 190 191 192 196 197 197 20 224 29 229 232 238 250 262 263 264 264 266vili_ CONTENTS! 623 624 6.25 626 6.2.7 6.2.8 6.2.9 6.2.10 Visibility sections and namespaces in inheritance Method redefinition Abstract classes and methods Final classes and methods Static components in inheritance Constructors in inheritance Object references in inheritance Polymorphism through inheritance 6.3 Interfaces 631 632 633 634 635 636 637 638 64 Events 64) 6A2 Basic principles Definition of interfaces Implementing interfaces in classes Composing interfaces Alias names for interface components Interface references Polymorphism through interfaces Interfaces and inheritance Defining and triggering events Handling events 6.5 Global classes and interfaces 65.1 65.2 653 654 Class pools and interface pools Creating global classes Testing global classes Using global classes PROGRAMMING: SCREENS 7.1 General screens 244 71.2 71.3 714 715 71.6 747 718 ‘What are screens? Defining screens Calling screens and screen sequences User actions on screens Dialog module and data transport Input checks Field and input helps ‘An example transaction 7.2 Selection screens 724 722 723 What are selection screens? Why selection screens? Defining selection screens 268 269 271 273 273 274 279 287 295 295 296 296 300 302 304 312, 315, 316 318 321 325, 326 328 334 334 336 336 338 346 350 356 359 362 367 380 380 383, 384 73 74 75 CONTENTS: 7.2.4 Calling selection screens 7.2.5 Selection screen processing 7.2.6 User actions on selection screens Classical lists 7.3.1 What are classical lists? 7.3.2 Classical lists prior to the advent of ABAP Objects 7.3.3 Classical ists in ABAP Objects 7.34 — Creating classical lists 7.3.5 Displaying classical lists 7.3.6 User actions on classical iss 7.3.7 Classical list processing anc detail ists 7.3.8 Example of classical ist processing 7.3.9. Sending lists to the SAP spool system Messages 7.4.1 Creating messages 7.4.2 Sending messages 7.4.3 Message Processing Advanced screen techniques 7.5.1 Context menus you program yourself 7.5.2 Drop-down boxes 7.5.3 Classical controls 754 GUI controls WORKING WITH EXTERNAL DATA ES} 82 83 84 Database access 8.1.1 Introduction 8.1.2 Defining database tables in the ABAP Dictionary 8.1.3. , Editing data with Open SQL 8.1.4 | Consistent data retention 8.1.5 Special sections on database access File interfaces 8.2.1 Files on the application server 8.2.2 Files on the presentation server Storing data as clusters 8.3.1 Data clusters in the ABAP Memory 8.3.2 Data clusters in database tables 8.3.3. Data clusters in cross-transaction application buffers, Authority checks 8.4.1 Authorizations and authorization objects 8.4.2 Evaluating authorization objects 391 393 397 401 401 402 403 405 410 a4 416 418 42i 426 426 426 428 430 430 432 435 443 467 467 469 470 498 505 508 509 510 512 513 515 si7 318 518 519! CONTENTS APPENDICES Appendix A A.1 The key flight data model tables A2 Glossary ‘A3_ABAP system fields Appendix B Literature ca C2 c3 ca Appendix C Installing the SAP Mit cs C6 cr c8 co C10 i Basis System System requirements Preliminary remark Installing the application server and the database Installing the SAP GUI (front end) Starting the SAP System ‘Configuring the SAPLogen and calling the SAP GUI Logging on to the SAP System Generating example data Linking the Basis Documentation to the SAP Library License 522 522 526 532 537 539 539 539 540 541 S41 541 542 942 542 342 ff Preface from SAP ABAP, the programming language of SA? for business applications, is a language with a long-standing tradition. Having started off over 20 years ago as a reporting language in the mainframe world and having developed between 1985 and 1995 into a com- plete 4GL with SQL integration and language support for dialog and transaction programming, ABAP is now a modern object-oriented, statically typed yet flexible, portable and universally applicable programming language offering particular sup- port for control- and web-based applications. However, ABAP is more than just a language. It Is embedded within a complete development envionment with all the editors, tools and repositories needed for large and complex software development projects. A large number of services contained in SAP's application server middleware infrastructure can also be addressed readily and independently of a particular platform. Iam delighted that the two authors, Horst Keller and Sascha Krilger, have taken it upon themselves to portray the object-oriented basic structure of modern ABAP alongside the full scope of the programming concepts developed over time in ABAP. Within a single book they offer the reader the distinct advantage of being able to find descriptions of both the new concepts of object-oriented development with ABAP ‘Objects and the older technologies of earlier releases ~ a knowledge of which remains essential due to the volume of ABAP code still in existence. Thope that this book will bring all readers further joy and success in programming in ABAP, Walldorf, August 2000 Andreas Blumenthal Development Manager ABAP Language SAP AGPreface from SHS Informationssysteme AG Dear Reader As a member of the board of SHS Informationssysteme AG it is a particular pleasure for ‘me that our employee Sascha Kriiger has found time in his busy schedule to publish the present book on ABAP Objects together with Dr Horst Keller, Practical and customer- driven implementation based on a thorough theoretical grounding in technological developments as well as dedication is the sole basis for any successful project. In the past SAP has played a significant part in the development of standard ERP software and will, in particular through mySAP.com, continue to do so in the future. From the position of our company, SAP's development in CRM (Customer Relationship Management) with new technological and strategic market orientation Is of particular interest in this respect. Following the ERP boom of the past two decades, these customer-oriented systems are now in widespread use throughout companies — above all in the telecommunications industry with its enormous growth in new customers, Anyone wishing to be successful in this kind of market must come to terms with the SAP Basis technology in order to integrate CRM systems in their existing IT land- scape. As many leading companies implement the SAP System, this requires innovative concepts. Not least through the use of EAT (Enterprise Application Integration) tools, object-otientation Is being increasingly established as the standard in integration. With ABAP Objects, SAP is intensifying its support of object-oriented (outbound) development and thereby allowing the seamless integration of different object models such as DCOM and CORBA The present book by Dr Horst Keller and Sascha Kriiger is an introduction to the new world of ABAP Objects and will give you an understanding of how to start with or change to a new programming model. Our wish for both authors is that this book will soon become the standard for the new type of object-oriented development ‘under SAP and will become an indispensable resource in practical applications. Munich, August 2000 Dr Stefan Méller SHS Informationssysteme AG ‘Member of the Board Foreword In recent years the ABAP programming language has undergone an enormous devel- ‘opment, the latest stage of which has been the gradual introduction of ABAP Objects between Releases 4.0 and 4.6, Of the books concerned with ABAP currently available on the market, only a few really get to grips with the new language concept. Those that refer to ABAP Objects do so only in terms of a supplement to existing material, This situation therefore led us to write the present book on ABAP Objects. As, how- ever, ABAP Objects cannot be considered in isolation from ABAP as a whole, it developed into a comprehensive description of the ABAP programming language based on the current Release 4.6, If you compare the current scope of the language with that of Release 3.0, for which the last official ABAP book [KRE9¢] was written, you will find many other new additions apart from the introduction of ABAP Objects. These include the integration of the ABAP type concept into the ABAP Dictionary, the introduction of new intemal tables, the possibility of using GUI controls and not least the redesigned ABAP Workbench, to name but a few. All these new concepts have finally transformed ABAP from a language focused on genezating lists and processing transactions to a universally applicable programming language. This development required us to pres- ent ABAP from a universal standpoint, with less emphasis on the earlier programming paradigms of reporting and dialog programming. In this context, it has been helpful that the book has been written jointly by an SAP employee and an external consultant. The insider view from a member of the ABAP Language Group, with precise ideas as to how ABAD should be used, has blended well with the view of an external user with a knowledge of ABAP gained from training seminars, previous publications and daily experience. We have used the synergy effect resulting from these different viewpoints to provide you with a thorough and yet practical guide to ABAP Objects. Certainly, we could not have successfully concluded this project without the direct, and indirect contribution of many people in drawing up and checking the manu- script. We are grateful to the following colleagues from the “ABAP and GUI” department of SAP who despite their many duties found time to proof-read the sec- tions on their specialized subjects: Thomas Barei&, Adrian Gorler, Mathias Hanbuch, Rolf Hammer, Peter Januschke, Ulrich Koch, Andreas Neubacher, Helmut Prestel,Cai ooreomenron Andreas Simon Schmitt, Werner Schuster, Christoph Stick, and Ralf Wendelgass. In Particular we thank Mrs Kerstin Gebhard from the ABAP Training Development department who read large parts of the manuscript and was always on hand to pro- vide constructive criticism, We would like to thank the students Wolfgang Kiess and Torben Simon for creating the ABAP system field overview and proof-reading some of the chapters, Jirgen Heymann kindly provided us with the object-orientation litera- ture references, We would also like to thank anyone else we have not mentioned but ‘who has suggested improvements along the line, ‘We have Michael Demuth’s initiative to thank for the fact that the accompanying CDs contain an SAP Basis system Including the example programs from this book. ‘Andrea Fritsch entered the examples into the system and created the template. Jlxgen Kciiger supported us with the downloadable files for the transport request for the exam- ple programs. For the program for generating training data we used an ABAP training ‘template from Thilo Buchholz. Lastly, we would like to thank also Tomas Wehren and his team from Galileo Press, in particular Iris Warkus, for their cooperation. For the English edition we would especially like to thank Gabriele Buchner, Michéle Coghlan, and Julie Plummer from Product Management (Development Platforms) for their indispensable commitment during our technical editing of the translated text. Horst Keller would also like to thank the Development Manager of the ABAP Language Group, Andreas Blumenthal, for all his support with the project in provid- ing all the necessary resources and many useful hints. Above all he Is indebted to his wife Ute for her patience and encouragement over the many evenings and weekends he spent working on the book, Sascha Kriiger would like to thank Stefan Méller, board member of SHS Informationssysteme AG, and the manager of the Cologne office, Frank Pensel, for thelr support. He would also like to thank his SHS project team for their excellent cooperation which allowed him to spare the time for writing this book. Particular thanks go to his wife Katja who continued to support his authoring commitments throughout, despite the restrictions it placed on their private life. Horst Keller Walldorf, August 2000 Sascha Krier Cologne, August 2000 CHAPTER 1 | aSEeaerr ciate eer sre nmr ERR perce aSES Introduction Before you get to grips with the material, her are a few tips on how to use this book WHAT IS'ABAP OBJECTS? ‘You are probably reading this book to cbtain a clear answer to this question. We shall provide you with the answer in Its most succinct form from the outset ABAP Objects is the object-oriented extension of the ABAP programming language. ABAP Objects and ABAP are inextricably linked and therefore any book concerning ABAP Objects by definition also concerns ABAP. ABAP is the programming language of SAP. Since its first release it has undergone several evolutionary stages, the latest of which is ABAP Objects, issued with Release 4.6. Other stages will doubtless follow. Let us consider the developments to date: In the seventies ABAP stood for “Allgemeiner Berichts-Aufbereltungs Prozessor” (General Report Preparation Processor). Implemented as a macro assembler within BY/2, ABAP was used solely to generate reports, By the mid-eighties ABAP had develeped into an interpreter language which was a ‘main component of the R/2 System and which could cope with the requirements of creating business application programs. In particular, dialog-controlled trans- actions could now be programmed using ABAP. ‘The early nineties saw the release of zhe SAP R/3 System and ABAP was introduced as a 4th generation programming language under the name ABAP/4, “Advanced ee2_ SAsamositersmmnoesama Business Application Programming.” This did not involve simply adding a pro- gramming language to R/3, actually it formed the software basis of the entire system. With the exception of the system core written in C, all SAP application modules, components of the R/3 Basis System, and even the development environ- ment were created in ABAP/4. a At the turn of the new century ABAP completed a new stage in its evolution with ABAP/4 being superseded by ABAP Objects. To be more precise, ABAP Objects is only the object-oriented language extension which implements all the major con- cepts of the object-oriented programming paradigm such as encapsulation, inheritance, and polymorphism. We shall therefore refer to ABAP when we mean the overall language of ABAP, and ABAP Objects when discussing the object- orlented aspects, AA frequently asked question is whether the introduction of ABAP Objects implies that the existing ABAP Is now obsolete. This is of course not the case. There are more than 100 million lines of productive ABAP code which still have to function after the advent of ABAP Objects. Therefore great care was taken throughout all development stages to maintain maximum downward compatibility with former versions, This has Jed to the current situation where ABAP supports two programming models in paral- lek: a classic procedural and an object-oriented programming model. In addition the language allows you to use ABAP Objects language elements in existing programs, and conversely you can use almost all previous language elements in ABAP Objects. Using the previous language elements in ABAP Objects has the immeasurable advantage that you can continue to use the strengths of a programming language ‘which has focused on developing client-server business applications. This includes supporting multilingual applications, easy access to the SAP System database, and the option of performing business calculations. In addition you can use an integrated development environment which supports the creation of large application systems by different developers. Of course, downward compatibility has its price: the language scope of ABAP includes many obsolete constructs which have since been replaced by improved con: cepts, but which have had to be left in order to support older ABAP programs. In this book we shall largely avoid outdated language elements and will mention them only where they are considered necessary for gaining an understanding of older programs. Within ABAP Objects, ie. in classes, many of these obsolete language elements are syntactically forbidden, This does not constitute an incompatible change since older coding cannot exist within classes. In newer programs, however, only the syntax allowed in ABAP Objects should be used, both within and outside of classes.* 1. The ABAP keyword documentation contains a dealledlsting of the language constructs prohibited in ABAP Object. Tic INTRODUETIONNS(_3 ‘TARGETSREADERSHIP™ ‘The readership we wish to address covers a broad spectrum. We are targeting begin- ners as well as “old hands" in SAP programming, as with ABAP Objects even the most experienced SAP developers will be encountering new territory. We do assume basic programming expertise. For example, we will not explain what a loop is, but how it is Implemented in ABAP. To work with this book and to understand ABAP Objects, you do not have to be familiar with ABAP or with object-orientation; but, of course, knowledge of either subject will help yeu get started. We offer a thorough introduc. tion to all the concepts and techniques necessary for creating and editing SAP applications in Release 4.6. For anyone participating in ABAP tréining this is exactly the right book for sup- porting and expanding on the course. We offer a solid foundation for junior developers and an easy conversion to ABAP Objects for senior developers. Project members confronted with Release 4.6 can also benefit from reading this book. In addition we wish to provide all students and interested parties with a deeper under- standing of SAP programming and on this basis encourage them to get more involved with the subject of ABAP Objects. If you have been programming with ABAP for many years you will find that we present many language elements and concepts differently from those you will be used to, We are following the approach SAP has used since Release 4.0 for its docu- ‘mentation and training, We would therefore encourage you to take a fresh look at [ABAP from this perspective. We hope this will provide you with a better understand- Ing of many aspects which might have seemed obscure in the past, and that you will, be able to frame your existing knowledge within the overall picture presented here If you are a beginner, you will be in:roduced directly to the basics of ABAP pro- ‘gramming and be spared any unnecessary baggage from the onset. However, we shall still point you towards older concepts so that you will be able to analyze, understand, and maintain existing programs. HOW'TO!READTHIS BOOK If you are devoting yourself seriously to ABAP for the first time with this book, It will probably be of litle help to start reading from the first page and finish at the end. As with a spoken language, It Is impossible to learn a programming language by reading a book from start to finish. You will only progress by practicing, Le. by analyzing existing programs and getting to grips with examples of specific problems. You can benefit from this process even if you alzeady have some experience in SAP program. ming. This is why we have placed spetial emphasis on providing a wide range of examples covering all the concepts explored.(4 Pestarosiects ‘This book follows a new approach to the ABAP programming language in its struc- ture, deviating from many familiar structures found in existing literature. The previous book by SAP authors on ABAP programming [KRE96] generally followed the Classical division between reporting and dialog programming. In the present book, however, you will find no such chapters. We aim to present ABAP as a universal tool {for all application programs. This new approach has been necessitated not least by the fact that ABAP has now become a hybrid language, supporting both the proce- ‘dural and the object-oriented programming models. As we alm to provide a well-knit portrayal of ABAP, we find ourselves at a crossroads between the old and the new ‘world. We will therefore now provide a brief overview of each chapter to show the topies covered and how you can best use them, 8 Chapter 2, A practical introduction This chapier is designed for anyone wanting to “get their hands dirty* straight away. You are given a guided tour of ABAP and ABAP Objects and join us in devel oping a fairly complicated program containing the key elements of all ABAP applications. At the same time you will learn how to handle the new ABAP devel- opment environment with Release 4.6. We shall not explain every detail in this chapter, and so you will probably not understand everything straight away. In fact, the chapter will raise more questions than it answers. However, the following chapters will provide detailed information and explanations for all aspects cov- ered. We recommend that even experienced ABAP developers read this chapter because in it we start to work with object-oriented language elements and also use one of the new GUI controls 1 Chapter 3, Basics of ABAP programming ABAP has certain characteristics which it is essential to understand in order to apply the language successfully. In Chapter 3 you will learn about where ABAP programs run, how they are structured in principle, and what happens in the back ground when you execute an ABAP program. We shall explain how the runtime environment and event control work. Although slightly theoretical, you should read this short chapter carefully. It introduces and describes many terms which form the basis for an understanding of the other chapters. 8 Chapter 4, Basic ABAP language elements ‘This chapter has its equivalent in many programming language books. In it you will be introduced to the elementary modules with which you can implement the functionality of your programs. The type concept, operations, and expressions as ‘well as control structures are just some of the topics treated in this chapter. We shall also cover in detail internal tables, character string processing, and error hand ling. This chapter adopts almost the character of @ language reference and you will probably not read it through in one go. You can rather use it to gain introductory information on the various concepts and later look up the concrete syntax of vat ous statements as well as find examples of how to use them, © Chapter 5, The ABAP programming models ‘This chapter has two main functions. Fistly, it shows you the options you have for structuting your ABAP programs. Secondly, it builds the bridge between the class- cal (procedural) and the new (object-oriented) worlds of ABAP programming. In the first part of the chapter we will show you the options available in the proce- ural programming model for modularizing your programs with procedures, and the significance of local and global data. In the second part we will contrast these findings with the concepts of the object-oriented programming model and thereby provide the transition to the basics of object-oriented programming with ABAP Objects. What we cannot achieve inthis chapter (nor in the book as a whole) isan introduction to object-oriented analysis or object-oriented design. These topics are largely independent of the programming language and are covered extensively in many other good books. However, you will cope with this chapter even if you have no experience in object-oriented programming, Each of the new language elements and its underlying concep’ is explained in detatl. Chapter 6, Advanced concepts of object-oriented programming with ABAP Objects This chapter forins a seamless link to Chapter $ and concentrates on all the ele- ments which make the object-oriented approach really powerful. We focus on inheritance, polymorphism, interface, and the event concept, and with the aid of examples we show you how to hendle these language elements. In short, this chapter provides the basis for advanced programming with ABAP Objects 1 Chapter 7, Programming screen layouts Here you will find an extensive and systematic illustration of how to program screens with ABAP. At the beginning we explain the general concepts of screen programming and then discuss how to create selection screens and classical lists You will also find how to create and handle dialog messages in this chapter. large part of the chapter is a recapitulation of concepts which were already valid before ABAP Objects, Finally we examine the GUI controls of the Control Framework (CEW) which you can only use with the new language elements of ABAP Objects. While beginners cannot avoid this chapter, we recommend that people with expe- rience in ABAP programming at least glance over the first sections as they will certainly gain some new insights into famillar concepts. The last partis completely new and should be read by everyone, Bi Chapter 8, Working with external data Vircually no ABAP program can manage without processing external data, At the forefront of this is accessing the central database of an SAP System. The chapter ‘examines all the statements for read and write access to the database ancl provides extensive guidelines on how to use them etticienti. in addition we summarize the key aspects for accessing files and introduce you to working with data clusters. The end of the chapter provides a summary of the authorization checks for ABAP‘ABAPO BIECTS programs. Like Chapter 7, this chapter can be read independently of the object- oriented extension. As many examples in the entire book use database access, you will probably want to Keep returning to Chapter 8. ‘We hope you will find in the course of this book that ABAP is not difficult to learn, spite its power, and that on the contrary many language elements have been intro- cuced to save you work and to create stable and powerful applications. HOWTO USE THIS BOOK IN: PRACTICE To work effectively with this book you should have access to an SAP System. The enclosed CD contains a complete SAP Basis System which you can install on your PC, containing all the example programs referred to. You can also download all examples from the It-minds website (www.it-minds.com/goto/abapobjects): the source code of the exemple programs In text format as well as the files for a transport request, in order to import all example objects into an existing SAP System. ‘We shall use the SAP flight data model for all exercises in this book which require access to the SAP System database. This is a simplified form of a fight booking system, concerning flights, flight connections, bookings, etc. The flight data model is essen- tially a set of relational database tables which are linked by foreign key relationships. ‘The flight data model Is used in all SAP ABAP training classes and in ABAP docu- mentation for demonstration and exercise purposes. The database tables are part of every SAP System delivered. In order to fill the database tables with sample data, you can use the S_FLIGHT_MODEL_DATA_GENERATOR program contained in the Basis, System of the enclosed CD. You will also find its souzce code on the it-minds website. ‘The most important flight data model database tables for our purposes are shown, below. The primary key fields have a light gray background. Appendix A provides the exact structure of each individual database table. TABLET. | This four-column table contains the 10, the full name, the currency code and the web address of some international airlines. SSCARR~ An Aitine Table CARRID._ CARRNAME ‘CURRCODE URL iw LUFTHANSA, oem TTP:// WWW. LUFTHANSA.COM sua oANTRODUETIONT [7 ‘This table consists of 15 columns and contains flight connections offered by the airlines from the SCAR& table. SPELI— A Fight Connection Table CITYROM—_AIBPFROM—_CITYTO ‘AIRPTO iH 0400 FRANKFURT FRAU NEWYORK JFK SFIARLESTS©] This table consists of nine columns and contains the data of actual flights for flight connections from the sPFti tabl SFLIGHT A Flight Table CONNIE CORTE, uw 0400 2000/06/27 ‘This table consists of 19 columns and contains the flight bookings for the flights from the SFLIGHT table. ‘S8OOK- A Fight Booking Table ane SOUND HOATE BOOKID: uw 0400 In addition to the columns mentioned, each of these tables has a first column con- taining a client ID which is, however, only significant If the data of several ‘commercially independent companies is kept within a single SAP System (see Section 8.1.8). In the examples in this book we will only work with these database tables, In the following practical introduction we shall, for example, read and dis- play the flight connections of an airline selected by the user. Figure 1.1 shows the section of the flight data model used by us as a SERM (Structured Entity Relationship Model) diagram.| | | TS Aine | SPFLI Flight connection [ srucHT Fight oe ‘SBOOK | Booking TEIGURE TA] A section from the SAP Flight Data Model SYNTAX:CONVENTIONS®* Alongside many source code examples, you will find in this book numerous syntax diagrams which illustrate the Key areas of application for a statement. able 1.5 describes the syntax conventions of the diagrams. We have placed special emphasis ‘on keeping similar conventions to the ones used in the SAP System online help and the ABAP training documentation. sanmopocrionss[ 9] TABLETS] Syntax conventions Key Definition KEYWORD Al keywords and additions to statements which are part ofthe language scope are shown in upper case. ‘operand Operands and similar expressions are shown in lowercase. 0 ‘Square brackets mean that you can use the sections of the statement enclosed therein, although this isnot ebligatory. Do not include the square brackets. I ‘line between two options meine that you can use only one ofthe two options. 0 If when you use the line, |, the alternative options are nat clearly identifiable, they willbe indicated by pointed brackets. These brackets are not included either. 0 Round brackets must always be included as part ofthe statement 'A comma means that you can enter as mary of the options separated by commas as you wish, The commas are part ofthe syntax. ne Expressions with indexes mean that you can lit as many expresions as you wish, Dots mean that you can use here any elements you Tike that wil fit into the respective context.‘CHAPTER 2 _ A practical introduction Join us on our first tour of the world of ABAP. In this chapter we will show you step by step how to create a program and how to handle the development environment. By the end of the chapter you will have written your fist extensive program in ABAP. INTRODUCTION ‘This chapter is @ guided tour or tutorial of the ABAP language. Together we will create a program that reads data under certain conditions from the database and displays it in a list. The introduction will touch on many key concepts of the ABAP language that will be covered systematically in later chapters, We will also introduce the use of the ABAP Workbench with Release 4.6, which otherwise will not be covered specifi cally in this book. Let's start with a few basics. You knew that SAP supplies business application sys- tems that generally maintain their data in a variety of tables within a central database. The application programs of the SAP System work with the data from these database tables. This means that data is read, analyzed, displayed, modified, reset, and passed to other programs. ABAP Is a programming language that has been specifically designed for these requirements of business data processing, and all application programs of the SAP System that work with the database are written In ABAP. ABAP allows the developer to concentrate mainly on logical tasks, without having to bother about the details of the SAP System architecture, One of the main strengths of ADAP Is that with Tittle effout and in a comfostable development env ronment you can write relatively small programs that provide a complete dialog between user and database, (22) SAD Easy cess Sy: ALPRACTICALINSRODUETIONS=|_11 In this practical introduction we shall make fall use of this particular aspect of ABAP. We will program a small application to perform user-driven database access, specifically accessing the database tables cf a flight data model (see Appendix A). The program will allow the user to enter an alrline and then access the SPFLI database table according to the user input. The data imported from the database table will then be displayed on screen. -FIRSTUSTERS WITHETHE: ABAP:WORKBENCH™ SE ‘The development environment for ABAP programs and all thelr components is the ABAP Workbench. We must therefore access the ABAP Workbench in the SAP System to write an ABAP program. The ABAP Workbench is a component of the SAP Basis system and is part of every SAP System, However, you need authorization as an SAP developer within your SAP System to work with the Workbench. The ABAP Workbench is itself also written entirely in ABAP. In addition to development authorization, you must have a developer key. This key is registered with SAP through SAPNet and allows a developer to be assigned to any modified original objects In the SAP System. Even though in the course of this book we shall make no modifications to originals, you must still be registered as a developer. 2.2.1 Getting started with the ABAP Workbench fo access the ABAP Workbench, open the Tools node in SAP Easy Access followed by the ABAP Workbench node (see Figure 2.1). ‘The sub-nodes provide an overview of the various functions of the ABAP ‘Workbench, At frst sight it may be difficult to find your bearings. There is no specific node that allows you to write an ABAP application program directly. However, if you open the Development node (see Figure 2.2), you will find a list containing several key programming tools of the ABAP Workbench, including the ABAP Editor, which allows you to edit ABAP programs; the Screen Painter and the Menu Painter, which allow you to create screens; the Function Builder and Class Builder, which allow special ABAP programs such as functions and classes to be programmed; and the ABAP Dictionary, which can be used to perferm global data declarations in the ABAP Dictionary. The abbreviations, such as $E38, SES1, etc., are the transaction codes of the individual tools (see Section 7.1.3).! 1, ‘To ensure the tanzaction code ae visible, the Display Technleal Names entry must be seca nthe Extras Settings menuTools 12 sa6ai [EFREUREAT] Accessing the ABAP Workbench via SAP Easy Access. Copyright © SAP AG ‘The number of tools indicates that an application program contains several compo- nents, such as source code and screens. We could start the ABAP Editor directly in this list to create an ABAP program or to edit an existing one. However, we would then be able to edit only one component of the program at a time, namely the source code, and would not have an overview of the other program components. Therefore it is. only worthwhtle choosing a specific component if you already know the program and. components you wish to edit, and wish to access them quickly and directly, Overview Favorites S01 Data hodoie 1b Qiserriace O68 AA Ever © 1 Bert Hineten Bugor OSE cians uiuer © 645: ContetBilose © Gi prosammina Envconment Drowor- Bueiness obit ult. b Baviomon & Gomer one The various tools of the ABAP Workbench. Copyright © SAP AG FIGURE ‘We will now propose another way of gaining entry to ABAP programming. Open the Overview node, Here you will find the Object Navigator listed (see Figure 2.3). The Object Navigator is the starting tool for the ABAP Workbench. If you find it too complicated to look for the starting node in SAP Easy Access each time, we recommend creating a favorite or the top Ievel. To do this, select Object Navigator in SAP Easy Access and choose Add to Favorites, or choose Favorites —4 ABARIOBILCTS tose Saas cs © SE05- Hoatieston Browser 1 SE83- Reuse Ubray @ SE8-Iocmaton syste Q se18- Data srowser = Transpo Organier FER LIDeit 3 tes ion FIGURE Calling the Object Navigator. Copyright © SAP AG Add Transaction and then enter the transaction "SE80."? From now on you will always find the Object Navigator node on the top level under Favorites in your SAP Initial screen (see Figure 2.4) 2, We shall be using te terms “selection” and “ehoose/selece” quite ofter. Depending on thet context, they «can refer to double-clicking the mouse, pressing a pushuton, selecting an icon ora mens ent, et The SAP System user interface willy offers a variety of election options fora function which we cannot Ist in fll In gener, the most important function canbe selected via icons at the top of the screen or via the keyboatd function keys All functions can be achieved through menu entries, We will show You ‘through the course ofthis Book how you can define this for your own progr mouelenenec The Object Navigator as a favorite. Copyright © SAP AG You can now always call the Object Navigator directly after logging onto the SAP system by choosing this node. As in previous releases, you can also call the Object Navigator by entezing “/nse80" In the standard toolbar* input field from any SAP screen. 4. Although the it eld of the standard toolbar i not visible as standard with Release 4.64, 1 can be ‘opened by clicking onthe litle tae n the standard tool,RPRACTICAINTRODUCTION‘|_17 16 aBAPIOBIECTS 2.2.2 Working with the Object Navigator {As soon as it is called forthe first time, the Object Navigator is displayed as shown in Figure 2.5 tepostoy abet As the name suggests, the Object Navigator provides access to objects. Since the Object Navigator is part ofthe ABAP Workbench, the objects involved are those that can be edited withthe tools of the ABAP Workbench. We refer to these objects as repository ‘objects. These inciude all the ABAP programs of the SAP System with all their compo- nents such as source code and layouts, There are, however, many other repository abjects such as global data definitions in the ABAP Dictionary or database table defini tions (also in the ABAP Dictionary). Together these development objects form a repository. This repository is a special section of the database contents ofthe central database, which includes the programs ofthe SAP System itself Instead of customer data Object st You access the repository objects via object lists in the Object Navigator. You ‘must select one of these lists in the drop-down list box in the top left-hand corner, In Figure 2.5 the Development class object list has been selected. Choose the input help key on the right of the field to obtain a lst of the other object list options (see Figure 2.6). Since you wish to write a program, choose the third entry, Program, Enter a name for your program and confirm using Enter (i (see Figure 2,7). Porte tee FIGURES] Object lists in the Object Navigator. Copyright © SAP AG ‘Object Navigator eisai ABAP OBJECTS a FIGURE 2.7, Copyright © SAP AG Entering a new program name. Copyright © SAP AG[18] “aeapiosiects i Namespace Program atibutes Program type [THGURERE™] creating an ABAP program. Copyright © SAP AG If there is no program with this name, the prompt in Figure 2.8 will appear. Otherwise try again with a different name. Bear in mind that customer programs have different naming conventions from SAP programs, and so as a customer, instead of the “S” used by SAP for the first letter, you ‘will have to use a “Yor 2 “Z" or the abbreviation reserved by SAP for your company. In this book we shall use “S” as a prefix for almost all repository objects. This means that ‘our example programs will be in the SAP-specific namespace for you to use as templates. Confirm the dialog box from Figure 2.8, and in the following dialog box in Figure 2.9 uncheck the check box for Top Include. Confirm here as well. We will expand on. the role of Top Include at a later stage, A dialog box now appears as shown in Figure 2.10. Here, you have to define spe- cific program attributes. One of the most important attributes of a program is its type. As we will see later in more detail, a program's type determines its entire way of operating. The default value of the Workbench is the executable program type. Since we wish to execute our program we leave it as itis and choose Save. A prompt then appears for a devel- opment class (see Figure 2.11). This term has already appeared as a possible object list type. What does it signify? A development class* provides a structure for development objects. You organize your work FIGURE 2.9] Prompt for a Top Include. Copyright © SAP AG 44. Please note that development classes and repository object have got nothing toda with clases and objets in ABAP Objects, PRACTICAL INTRODUCTION auroraion pours ical databas Ty Eater abe FIGURE 2.10) Defining program attributes. Copytight © SAP AG ie atersaes Peo aioe Ofgaalemer ‘ranean? (ete [FIGURE 217] Assigning a development class. Copyright © SAP AG by assigning various objects to a development class. All repository objects ~ ie, not just programs but all objects that can be modified with the ABAP Workbench ~ must be assigned to a development class, If you specify a development class as an object list type in the Object Navigator, you can then access all the objects of this development class.S 5. As of Release 6.10 the term development cass has been replaced by Package. A package includes all the attributes of development clase but in adation offers nesting, interfaces, and Ws definitionA PRACTICAL INTRODUCTION [ZT Development iss Development classes are actually repository objects themselves. As well as organtiz- {ng development projects they have the impoztant task of connecting development objects to the SAP Change and Transport System. The latter is responsible for trans- porting objects between different SAP Systems, For obvious reasons, applications are always developed in a development system, never in a procuction system. The appli cation programs created in this system have to be transported, mainly via other consolidation or test systems, to a production system where the business data Is located. The SAP Change and Transport System is used to define transport layers for each SAP System. These layers specify the target systems into which objects from a given development system are to be transported. Each development class is assigned to one of these transport layers and therefore specifies the transport attributes of all its development objects. In principle, a naming convention is used to specify whether or not a development class and its objects are transportable. A development class starting with the *$” sign cannot be transported and you cannot assign it to a transport layer, All other development classes must be assigned to a transport layer and both the class and their development objects thereby are subject to the SAP Change and Transport System. Modifications in transportable development classes are organized into tasks and are cartied out solely in Transport or Correction Requests, which are administered by transaction SE09, the Transport Organizer of the ABAP Workbench. In our case we shall use a transportable development class S_A8AP_800k, which ultimately vill contain all the repository objects required for this book. For example, for exercise purposes you can create your own non-transportable development class $_ABAP..800K. To do this, proceed in the Object Navigator exactly as if you were cre- ating a program and simply enter the new name in the Development class object list type in the top left-hand corner in the Object Navigator. However, SAP also provides 2 special development class called TMP, which is also designed for local, non-trans portable development objects. Each developer can store his or her own exercise and demo programs In STP. In the dialog box in Figure 2.11 you can either enter “STMD" as the development class and choose Save, or ditectly select the Local object button. Both have the same effect. Through the Local Objects object list type (see Figure 2.6), the Object Navigator provides each developer with direct access to his or her local exercise objects. Naturally, the assignment of a development object to a development class can be amended later. Once you have specified the development class, the basis for creating a program is complete. In the object list of the Object Navigator you will now find the entry S_FIRST_PROGRAM. You Can click this with the alternate mouse button and will then see a context menu with the editing options see Figure 2.12). If you choose Change in this context menu, the ABAP Bditor appears in the right ide of the Object Navigator scrcen (see Figure 2.13). ABAP Ector Figure 2.13 shows how the Object Navigator appears as you would normally see it when editing repository objects. The object list on the left-hand side shows your ‘objects hierarchically in a tree structure. Throughout this introduction a large one (B0}:asarionjecrs FIGURE 213] The Object Navigator and the ABAP Editor. Copyright © SAP AG
You might also like
BC404 ABAP Object Oriented Programming in R3
PDF
No ratings yet
BC404 ABAP Object Oriented Programming in R3
6 pages
ABAP - Objects An - Introduction.to - Programming.sap - Applications
PDF
No ratings yet
ABAP - Objects An - Introduction.to - Programming.sap - Applications
287 pages
ABAP Objects
PDF
No ratings yet
ABAP Objects
3 pages
Abap 001 Intro To SAP ABAP
PDF
No ratings yet
Abap 001 Intro To SAP ABAP
4 pages
State-of-the-Art ABAP - A Practical Programming Guide
PDF
No ratings yet
State-of-the-Art ABAP - A Practical Programming Guide
26 pages
ABAP Objects - ABAP Programming in SAP NetWeaver
PDF
0% (1)
ABAP Objects - ABAP Programming in SAP NetWeaver
4 pages
Fundamentals of ABAP Objects: IBM Global Business Services
PDF
No ratings yet
Fundamentals of ABAP Objects: IBM Global Business Services
46 pages
08.abap Screens
PDF
No ratings yet
08.abap Screens
70 pages
Sales Order Creation Using Web Dynpro ABAP
PDF
No ratings yet
Sales Order Creation Using Web Dynpro ABAP
12 pages
Practical Way of Enhancing Adobe Smartforms Form Output SAP
PDF
No ratings yet
Practical Way of Enhancing Adobe Smartforms Form Output SAP
5 pages
MVC in ABAP OO
PDF
No ratings yet
MVC in ABAP OO
26 pages
ABAP LIST VIEWER (ALV) - Presentation
PDF
No ratings yet
ABAP LIST VIEWER (ALV) - Presentation
37 pages
Oops Abap
PDF
100% (1)
Oops Abap
123 pages
ABAP Debugger New
PDF
100% (13)
ABAP Debugger New
6 pages
Abap Oops
PDF
No ratings yet
Abap Oops
117 pages
Sap Idoc Interface (Development)
PDF
No ratings yet
Sap Idoc Interface (Development)
50 pages
Sap Abap
PDF
No ratings yet
Sap Abap
17 pages
Adobe Forms 1 How To Create A Adobe Form and Print The Form
PDF
No ratings yet
Adobe Forms 1 How To Create A Adobe Form and Print The Form
24 pages
ABAP Best Practices - Field Symbols
PDF
No ratings yet
ABAP Best Practices - Field Symbols
3 pages
Ooabap Questions
PDF
No ratings yet
Ooabap Questions
69 pages
Advanced ALV With ABAP Objects
PDF
No ratings yet
Advanced ALV With ABAP Objects
19 pages
Fundamentals of ABAP Objects
PDF
No ratings yet
Fundamentals of ABAP Objects
31 pages
Types Type Table of With KEY Data Type Ref To Create Data NEW NEW
PDF
100% (1)
Types Type Table of With KEY Data Type Ref To Create Data NEW NEW
11 pages
Debugging in SAP
PDF
No ratings yet
Debugging in SAP
11 pages
Employee Photos
PDF
No ratings yet
Employee Photos
25 pages
SAP ABAP New Syntax
PDF
No ratings yet
SAP ABAP New Syntax
10 pages
Select Statements in Abap
PDF
No ratings yet
Select Statements in Abap
79 pages
ABAP
PDF
No ratings yet
ABAP
361 pages
How To Use The BOL Tree
PDF
100% (1)
How To Use The BOL Tree
13 pages
Sap Abap SQL Select Statements With Examaple
PDF
No ratings yet
Sap Abap SQL Select Statements With Examaple
5 pages
ABAP Objects
PDF
No ratings yet
ABAP Objects
202 pages
Abap CDS
PDF
No ratings yet
Abap CDS
12 pages
SAP ABAP Syllabus 20090624
PDF
100% (2)
SAP ABAP Syllabus 20090624
7 pages
Sams Teach Yourself ABAP/4 in 21 Days: Program Naming Conventions
PDF
No ratings yet
Sams Teach Yourself ABAP/4 in 21 Days: Program Naming Conventions
6 pages
ABAP Performance and Best Practices A Bible V1 0
PDF
100% (1)
ABAP Performance and Best Practices A Bible V1 0
77 pages
ABAP Objects - Advanced Exercises
PDF
No ratings yet
ABAP Objects - Advanced Exercises
4 pages
Master The Five Remote Function Call
PDF
No ratings yet
Master The Five Remote Function Call
25 pages
D-Code Presentation - Overview of ABAP 7.4 Development For SAP HANA
PDF
No ratings yet
D-Code Presentation - Overview of ABAP 7.4 Development For SAP HANA
51 pages
Step-By-Step Guide To Ale and Idocs: Sap Virtual/Onsite Trainings
PDF
No ratings yet
Step-By-Step Guide To Ale and Idocs: Sap Virtual/Onsite Trainings
3 pages
ABAP Certification Questions (Scribd)
PDF
No ratings yet
ABAP Certification Questions (Scribd)
2 pages
BDC Part4 For Abap
PDF
No ratings yet
BDC Part4 For Abap
8 pages
Object Oriented Approach For ALV Lists in ABAP
PDF
No ratings yet
Object Oriented Approach For ALV Lists in ABAP
33 pages
23-Useful Abap Tips
PDF
100% (3)
23-Useful Abap Tips
62 pages
ABAP 7.40 Quick Reference
PDF
100% (1)
ABAP 7.40 Quick Reference
15 pages
ABAP Objects
PDF
No ratings yet
ABAP Objects
84 pages
Sap Abap Notes.
PDF
No ratings yet
Sap Abap Notes.
3 pages
Object Oriented ABAP
PDF
No ratings yet
Object Oriented ABAP
42 pages
ABAP 7.40 Quick Reference
PDF
No ratings yet
ABAP 7.40 Quick Reference
13 pages
SAP NetWeaver Gateway
PDF
No ratings yet
SAP NetWeaver Gateway
16 pages
ABAP BASIC DOCUMENT
PDF
No ratings yet
ABAP BASIC DOCUMENT
53 pages
Sap - Abap: Introduction To ERP
PDF
No ratings yet
Sap - Abap: Introduction To ERP
8 pages
01 ABAP Overview
PDF
100% (1)
01 ABAP Overview
30 pages
Learn ABAP in 1 Day: ALL RIGHTS RESERVED. No Part of This Publication May Be Reproduced or
PDF
No ratings yet
Learn ABAP in 1 Day: ALL RIGHTS RESERVED. No Part of This Publication May Be Reproduced or
20 pages
ABAP and Netweaver Day 1: Hong Kong, China 3 - 7 July 2012
PDF
No ratings yet
ABAP and Netweaver Day 1: Hong Kong, China 3 - 7 July 2012
83 pages
SBasic ABAP
PDF
100% (2)
SBasic ABAP
168 pages
Sap Abap Books
PDF
No ratings yet
Sap Abap Books
678 pages
SAP ABAP Introduction and Overview
PDF
No ratings yet
SAP ABAP Introduction and Overview
36 pages
Erp and Sap Historical Overview
PDF
No ratings yet
Erp and Sap Historical Overview
18 pages
An Insider's Guide To Writing Robust, Understandable, Maintainable, State-Of-The-Art ABAP Programs
PDF
No ratings yet
An Insider's Guide To Writing Robust, Understandable, Maintainable, State-Of-The-Art ABAP Programs
27 pages