(This page has no text content)
SAP PRESS is a joint initiative of SAP and Rheinwerk Publishing. The know-how offered by SAP specialists combined with the expertise of Rheinwerk Publishing offers the reader expert books in the field. SAP PRESS features first-hand information and expert advice, and provides useful skills for professional decision-making. SAP PRESS offers a variety of books on technical and business-related topics for the SAP user. For further information, please visit our website: http://www.sap-press.com. Kiran Bandari Complete ABAP (3rd Edition) 2022, 912 pages, hardcover and e-book www.sap-press.com/5567 Baumbusch, Jäger, Lensch ABAP RESTful Application Programming Model (2nd Edition) 2025, 576 pages, hardcover and e-book www.sap-press.com/6161 Colle, Dentzer, Hrastnik Core Data Services for ABAP (3rd Edition) 2024, 754 pages, hardcover and e-book www.sap-press.com/5642 Brian O’Neill, Jelena Perfiljeva ABAP: An Introduction (2nd Edition) 2020, 684 pages, hardcover and e-book www.sap-press.com/4955 Paul Hardy ABAP to the Future (4th Edition) 2022, 877 pages, hardcover and e-book www.sap-press.com/5360
Fabian Lupa, Sven Treutler ABAP® Cookbook Practical Recipes for Modern Programming
Imprint This e-book is a publication many contributed to, specifically: Editor Megan Fuerst Acquisitions Editor Hareem Shafi German Edition Editor Janina Schweitzer Translation Winema Language Services, Inc. Copyeditor Julie McNamee Cover Design Graham Geary Photo Credit Shutterstock: 1321600256/©Alexander Raths Layout Design Vera Brauner Production E-Book Kelly O’Callaghan Typesetting E-Book SatzPro, Germany We hope that you liked this e-book. Please share your feedback with us and read the Service Pages to find out how to contact us. Library of Congress Cataloging-in-Publication Control Number: 2025040738 ISBN 978-1-4932-2777-8 (print) ISBN 978-1-4932-2778-5 (e-book) ISBN 978-1-4932-2779-2 (print and e-book) 1st edition 2026 1st German edition published 2025 by Rheinwerk Verlag © 2026 by: Rheinwerk Publishing, Inc. 2 Heritage Drive, Suite 305 Quincy, MA 02171 USA info@rheinwerk-publishing.com +1.781.228.5070 Represented in the E.U. by: Rheinwerk Verlag GmbH Rheinwerkallee 4 53227 Bonn Germany service@rheinwerk-verlag.de +49 (0) 228 42150-0
(This page has no text content)
Contents Preface ............................................................................................................................... 15 1 Introduction to Modern ABAP Development 21 1.1 The Role of ABAP in SAP Development ................................................ 22 1.2 The New Development Model for ABAP ............................................. 23 1.3 The ABAP Language Version ..................................................................... 25 1.4 APIs Released via Release Contracts ..................................................... 30 1.5 Development Environment ...................................................................... 32 1.6 Programming Model .................................................................................... 32 1.7 Usage Scenarios for ABAP Cloud ............................................................ 34 1.8 ABAP Releases On-Premise and in the Cloud .................................... 37 1.9 Restrictions Depending on the Release and Runtime Environment .................................................................................................... 38 1.10 Summary ........................................................................................................... 39 2 The Application Scenario 41 2.1 Concept of the Sample Application ....................................................... 41 2.2 Creating Dictionary Objects ...................................................................... 45 2.3 Generating an ABAP RESTful Application Programming Model Application ......................................................................................... 52 2.3.1 Generating an OData Service and a Virtual Data Model .................................................................................................. 53 2.3.2 Generated CDS Entities of the ABAP RESTful Application Programming Model Application ...................... 56 2.3.3 Publishing the OData Service ..................................................... 64 2.3.4 Testing the Application ................................................................ 65 2.4 Creating Associations .................................................................................. 667
Contents2.5 Application Scenario from a User’s Perspective ............................... 73 2.6 Summary ............................................................................................................ 77 3 Handling System Fields and Runtime Information 79 3.1 System Fields in ABAP Cloud ..................................................................... 80 3.2 Overview of the Available APIs ................................................................ 82 3.3 Access to Time Information ....................................................................... 83 3.4 Accessing User Data ...................................................................................... 90 3.5 Access to Technical Information on the Current Program Execution ........................................................................................................... 92 3.6 Accessing Messages ...................................................................................... 94 3.7 Accessing System Data ................................................................................ 95 3.8 Summary ............................................................................................................ 97 4 Table Analysis 99 4.1 Table Analysis Using the Customer Data Browser .......................... 100 4.2 Table Analysis Using ABAP Development Tools ............................... 106 4.3 Summary ............................................................................................................ 110 5 Table Maintenance Using Business Configuration Maintenance Objects 111 5.1 Overview of the New Table Maintenance Concept ........................ 112 5.2 Creating Customizing Tables .................................................................... 114 5.3 Generating the Business Configuration App ..................................... 124 5.4 Assigning Authorizations ........................................................................... 132 5.5 Configuration from a User’s Perspective ............................................. 136 5.6 Settings in the Business Configuration Maintenance Object .... 1438
Contents5.7 Lifecycle Management with Deprecation .......................................... 145 5.8 Documenting Business Configuration Maintenance Objects ... 148 5.9 Summary ........................................................................................................... 150 6 Application Logs 151 6.1 Application Log for the Sample Application ...................................... 152 6.2 Maintaining Application Log Objects and Subobjects .................. 155 6.3 The BALI API ..................................................................................................... 159 6.4 Creating a Log ................................................................................................. 161 6.4.1 Adding Free Text Messages ........................................................ 163 6.4.2 Adding Messages from Message Classes ............................... 165 6.4.3 Adding Messages from Exception Classes ............................. 169 6.5 Saving a Log ..................................................................................................... 172 6.6 Displaying Logs ............................................................................................... 174 6.7 Summary ........................................................................................................... 175 7 Change Documents 177 7.1 Maintaining Change Document Objects in the ABAP Development Tools ....................................................................................... 178 7.2 Calling the Logging Function via the Generated Class ................. 182 7.3 Change Document Update Using the ABAP RESTful Application Programming Model ........................................................... 189 7.4 Displaying Change Documents ............................................................... 195 7.5 Summary ........................................................................................................... 197 8 Lock Objects 199 8.1 Lock Mechanisms in the Database Environment ............................ 199 8.2 Locks on the ABAP Platform ..................................................................... 203 8.3 Using Lock Objects ........................................................................................ 2049
Contents8.4 API for Lock Objects ....................................................................................... 206 8.5 Integration into the Sample Application ............................................ 212 8.6 Summary ............................................................................................................ 215 9 Number Range Objects 217 9.1 Number Ranges in SAP Systems .............................................................. 218 9.2 Maintaining a Number Range .................................................................. 218 9.3 API for Number Range Objects ................................................................ 223 9.4 Numbering in the ABAP RESTful Application Programming Model ................................................................................................................... 226 9.4.1 Unmanaged Early Numbering .................................................... 227 9.4.2 External Early Numbering ............................................................ 231 9.4.3 Managed Early Numbering ......................................................... 233 9.5 Summary ............................................................................................................ 235 10 Background Processing 237 10.1 Developing an Execution Logic ................................................................ 238 10.2 Creating Application Jobs ........................................................................... 242 10.2.1 Creating an Application Job Catalog Entry ............................. 243 10.2.2 Creating an Application Job Template ..................................... 245 10.2.3 Creating an Application Job ........................................................ 246 10.3 Checks ................................................................................................................. 252 10.4 Logging ............................................................................................................... 257 10.5 Summary ............................................................................................................ 259 11 Email Dispatch 261 11.1 Configuring and Monitoring the Email Dispatch ............................. 262 11.2 ABAP Cloud API for the Email Dispatch ................................................ 26510
Contents11.3 Integrating the Newsletter Dispatch into the Recipe Portal ..... 271 11.3.1 Creating an Application Job ........................................................ 272 11.3.2 Email with Error Message ............................................................ 274 11.4 Summary ........................................................................................................... 278 12 Parallelizing Application Logic 279 12.1 Parallelization on the ABAP Platform .................................................. 280 12.2 The CL_ABAP_PARALLEL Class ................................................................. 281 12.3 Refactoring the Sample Application ..................................................... 285 12.3.1 Implementing the IF_ABAP_PARALLEL Interface ................. 288 12.3.2 Sequence and Debugging of Parallel Processes ................... 294 12.4 Summary ........................................................................................................... 297 13 File Upload 299 13.1 Extending the Sample Application to Include a File Upload Option ................................................................................................................. 299 13.2 Summary ........................................................................................................... 308 14 Using Excel Files 309 14.1 Creating an Excel File ................................................................................... 313 14.1.1 Creating the Action ........................................................................ 313 14.1.2 Creating the Excel Document .................................................... 314 14.1.3 Creating the Workbook ................................................................ 315 14.1.4 Writing the Recipe Data to the Worksheet ........................... 315 14.1.5 Addition to the Header ................................................................. 317 14.1.6 Adding Another Worksheet ........................................................ 318 14.1.7 Saving the Excel File ...................................................................... 320 14.1.8 Testing the Application ................................................................ 321 14.2 Reading an Excel File .................................................................................... 324 14.2.1 Creating the Action ........................................................................ 324 14.2.2 Creating the Document Object .................................................. 32411
Contents14.2.3 Reading a Worksheet ..................................................................... 325 14.2.4 Reading the Header ........................................................................ 326 14.2.5 Reading Data into an Internal Table ......................................... 328 14.2.6 Executing the Mass Change ........................................................ 330 14.2.7 Testing the Application ................................................................. 332 14.3 Summary ............................................................................................................ 333 15 Documenting Development Objects 335 15.1 ABAP Doc ........................................................................................................... 336 15.2 Knowledge Transfer Document ............................................................... 343 15.2.1 Creating a Knowledge Transfer Document ............................ 343 15.2.2 Linking a Knowledge Transfer Document to a Development Object ...................................................................... 347 15.3 Summary ............................................................................................................ 350 16 Authorizations 351 16.1 Authorization Checks for Read Operations ........................................ 352 16.2 Authorization Checks for Change Operations .................................. 357 16.2.1 Global Authorizations ................................................................... 358 16.2.2 Instance-Dependent Authorizations ........................................ 361 16.2.3 Authorization Precheck ................................................................. 363 16.3 Summary ............................................................................................................ 365 17 Using APIs 367 17.1 Finding the Right APIs .................................................................................. 368 17.1.1 Successor Objects ........................................................................... 368 17.1.2 Searching via CDS Entity I_APIsForCloudDevelopment ..... 370 17.1.3 Searching via the Open ABAP Development Object Dialog Box ......................................................................................... 371 17.1.4 Searching via ABAP Object Search ............................................ 373 17.1.5 Grouping and Filtering in Project Explorer ............................. 374 17.1.6 External Search Options ............................................................... 37812
Contents17.2 Calling APIs Based on the ABAP RESTful Application Programming Model via EML ................................................................... 381 17.3 Summary ........................................................................................................... 385 18 Extensions in ABAP Cloud 387 18.1 Key User Extensibility .................................................................................. 388 18.1.1 Setting Up the Adaptation Transport Organizer ................. 388 18.1.2 Custom Fields .................................................................................. 391 18.1.3 Custom Logic .................................................................................... 396 18.1.4 Transporting Key User Extensions ............................................ 400 18.1.5 Custom CDS Views ......................................................................... 403 18.2 Developer Extensibility ............................................................................... 408 18.2.1 Extending Database Tables ........................................................ 409 18.2.2 Extending CDS Entities ................................................................. 411 18.2.3 Implementing Custom Logic ...................................................... 414 18.3 Summary ........................................................................................................... 417 19 Outlook 419 Appendices 425 A Installing the Sample Application .......................................................... 427 B Naming Conventions for the Sample Application .......................... 429 C Installing the ABAP Development Tools for Eclipse ....................... 433 D The Authors ...................................................................................................... 435 Index .................................................................................................................................. 437 Service Pages ................................................................................................................. I Legal Notes ..................................................................................................................... II13
(This page has no text content)
Preface Continuous development of ABAP ABAP continues to evolve, and it has been doing so at a rapid pace for sev- eral years now. With the ABAP RESTful application programming model, SAP has been offering an increasingly mature framework for development since 2018. More and more applications in the standard SAP system are being transferred to this programming model. In combination with ABAP core data services (ABAP CDS) and SAP Fiori elements, application behavior is modeled in a separate syntax and not implemented directly in ABAP, as in previous programming models. At the same time, ABAP Cloud is playing an increasingly important role as a development model for modern appli- cations that is available in both on-premise and cloud systems. With the clean core approach, ABAP Cloud is also being promoted in on-premise sys- tems, which means that the role of classic ABAP is increasingly changing. Target groupPerhaps you’ve already been able to familiarize yourself with the techniques mentioned in your work as a developer and are also familiar with ABAP in cloud systems. Or maybe you haven’t yet migrated to SAP S/4HANA, so you’ve been limited technologically to ABAP 7.50 with SAP ERP 6.0 EhP8, and you’re wondering what lies ahead and what has happened in the past 10 years. The level of knowledge of ABAP developers couldn’t be further apart at the moment. In addition, the upgrade problem still exists for many companies. The issues of training and continuous education, as well as enabling devel- opers for project deployment are correspondingly difficult. In this book, we want to meet you where you are and introduce you to the latest technical solutions for recurring problems, regardless of where you’re in the spec- trum described. Our book is therefore intended for ABAP developers who are interested in modern solutions and want to develop their software to a high standard, prepare for its possible operation in the cloud, and adhere to the clean core approach. Goals of this bookYou won’t find any marketing buzzwords in this book—it was written by developers for developers. We introduce you to technologies that enable you to solve recurring problems using state-of-the-art methods and com- pare them with previous solution approaches. It’s particularly important to us that you can use the solutions in both on-premise and cloud systems. We’ll therefore limit ourselves to the range of functions available in SAP S/4HANA 2023 using ABAP Cloud, which means that you can use the solu- tions presented in all current ABAP runtime environments: SAP S/4HANA 2023 (on-premise version), SAP S/4HANA Cloud Private Edition 2023, SAP15Personal Copy for Rubens Lenzi, fawax21610@gamepec.com
PrefaceS/4HANA Cloud Public Edition, and the SAP BTP ABAP environment. How- ever, many newer functions are heavily release-dependent, so there may be restrictions on ABAP releases below 7.58. Prerequisites To be able to follow the contents of this book optimally, you should be familiar with the basics of the ABAP programming language, including ABAP objects, and have gained some hands-on experience. In addition, you should already be familiar with the ABAP development tools for Eclipse, that is, the Eclipse-based ABAP development environment (successor to the ABAP Workbench) as this is the only development environment available for all runtime environments and fully supports the object types used there. Nevertheless, you can still find tips and tricks for using the ABAP development tools as well as step-by-step instructions for the individual techniques. This is because switching from Transaction SE80 to the ABAP development tools often involves a significant learning curve, especially for experienced ABAP developers. Instructions for installing the ABAP development tools can be found in Appendix C. Structure of the book The chapters in this book each address a specific problem and present an up-to-date solution. As a rule, the chapters can be read independently of each other. That means you can either read the book from start to finish to get a comprehensive overview, or jump straight to the chapter you need if you’re looking for specific information on a certain topic. Throughout the chapters, we use an overarching sample application that establishes the ref- erence to real-life business. We took particular care to choose an example that was realistic, not too simple, but also not too complex. The individual chapters expand this sample application step-by-step so that you can fol- low our development steps. Chapter 1 (Introduction to Modern ABAP Development) serves as an intro- duction to the technical concepts that are relevant in modern ABAP-based applications and positions ABAP development in the current SAP product portfolio. In Chapter 2 (The Application Scenario), we describe the business example we’ll use as a guide in the subsequent chapters and explain how the sample application is structured from a technical point of view. Chapter 3 (Handling System Fields and Runtime Information) is the first chapter in which specific techniques are presented—in this case, accessing information in the ABAP runtime environment using modern classes and statements. In Chapter 4 (Table Analysis), you’ll learn how to give users, key users, or application support staff access to table content in an SAP Fiori app. You’ll also learn how you as a developer can analyze database table contents using the ABAP development tools.16© 2025 by Rheinwerk Publishing Inc., Boston (MA)
PrefaceChapter 5 (Table Maintenance Using Business Configuration Maintenance Objects) describes how you can develop a maintenance interface for cus- tomizing settings in the form of an SAP Fiori app. Such an app can be regarded as the successor to the maintenance dialogs created via the table maintenance generator. Chapter 6 (Application Logs) deals with the logging of user actions and pro- cess steps with the application log. You’ll get to know the new object type and the new classes that enable you to replace the old function modules for logging. In Chapter 7 (Change Documents), we describe class-based change logging, which you can use to track changes to master and transaction data, as well as their integration into ABAP RESTful application programming model business objects. In Chapter 8 (Lock Objects), you’ll learn about the new class-based API for locking objects as well as the optimistic and pessimistic locking concept. You’ll also learn how to integrate lock objects into applications based on the ABAP RESTful application programming model. Chapter 9 (Number Range Objects) shows how you can use the new, class- based access option to draw numbers for primary key fields or check them. You’ll also gain an insight into the program-based maintenance of number range objects and intervals. In Chapter 10 (Background Processing), we present the application jobs, the cloud-enabled successor concept to the classic, report-based batch jobs. Application jobs are used for the regular execution of applications. In Chapter 11 (Email Dispatch), you’ll learn how to send emails from the SAP system—including attachments and using new classes. Chapter 12 (Parallelizing Application Logic) shows you how you can gain performance in your programs by executing subtasks in parallel with multiple processes—without having to create your own function modules directly in ABAP objects. The uploading of files is described in Chapter 13 (File Upload). You’ll learn how you can use the ABAP RESTful application programming model and SAP Fiori elements to enable users to upload files and consume the file con- tent in your applications. In Chapter 14 (Using Excel Files), you’ll learn how to read and create XLSX files using the XCO library. The file upload and download described in the previous chapter is used for this purpose.17Personal Copy for Rubens Lenzi, fawax21610@gamepec.com
PrefaceChapter 15 (Documenting Development Objects) presents the current options for documenting development objects using ABAP Doc and knowl- edge transfer documents. Chapter 16 (Authorizations) deals with the assignment of authorizations. You’ll learn how to authorize access to your applications in ABAP Cloud. In Chapter 17 (Using APIs), we move away from our sample application and refer to the standard SAP system. You’ll learn how to find shared objects and APIs, as well as how to call them in the correct way. In the context of ABAP Cloud, the search for reusable and released objects is very relevant because unreleased objects can no longer be used. The details of current extension techniques are described in Chapter 18 (Extensions in ABAP Cloud). You’ll learn how to extend applications that are based on the ABAP RESTful application programming model with your own functions and fields using the developer and key user extensibility. Finally, we provide an outlook in Chapter 19 (Outlook). We take a look at where we currently are in terms of technological development, where there are still gaps in the coverage of new technologies, and what new functions can be expected in future releases. Information boxes The highlighted boxes in this book contain information that’s good to know and useful but outside the context. To help you immediately identify the type of information contained in the boxes, we’ve assigned icons to each box: ▪ Boxes marked with this icon contain information on related topics. ▪ This icon refers to specifics that you should consider. It also warns about frequent errors or problems that can occur. ▪ The tips marked with this icon provide specific recommendations that can make your work easier. Use of the Sample Application In the materials accompanying the book at www.sap-press.com/6198, you’ll find the sample application, which is built up successively in the indi- vidual chapters. You can also find it on GitHub at http://s-prs.co/v619800. Details on the use of the individual development objects are explained in Appendix A. The introduction to each of the following chapters mentions which objects are used. As far as technically possible, there is a separate subpackage for each chapter. The assignment of chapters and packages can also be found in Appendix A.18© 2025 by Rheinwerk Publishing Inc., Boston (MA)
PrefaceThe sample application enables us to explain the individual techniques described in this book in a hands-on manner. However, you shouldn’t use it directly for real-life production scenarios. For example, for presentation reasons, we’ve omitted translatable texts in some places. We’ve also short- ened some of the error handling to focus on the actual topic of the respec- tive chapter. Acknowledgments Writing a book for the first time is a project in itself. We would therefore like to express our special thanks to Rheinwerk Verlag and specifically to Janina Schweitzer for her support during the writing process and for accompany- ing us “from kick-off to go-live.” We also want to thank Björn Schulz and Sebastian Freilinger-Huber for their feedback on the individual chapters and technologies. Thanks also to the abapGit community, whose open source tool gave us the opportunity to collaborate on our sample applica- tion and make it easily available to you. Acknowledgments from Fabian Lupa I would particularly like to thank Patrick Holdschlag for the constant pro- fessional and technical exchange on SAP topics and the review work in this book project. A big thank you also goes to Leon Requardt for the in-depth discussions on the ABAP RESTful application programming model and thoughts on best practices. Thank you, Elena, for your understanding, your patience, and your support. Acknowledgments from Sven Treutler I wrote this book so that my cat Marie can continue to enjoy her life of luxury. Thank you, Grandma, Grandpa, Marion, Werner, Toni, and Patrick for always believing in me. I would like to thank you, mom and dad, for teaching me the value of edu- cation and curiosity from an early age. But my special thanks go to you, Antonia. Your patience, love, and ass- kicking have carried me through the many hours of writing. We both hope that this book provides you with a practical introduction to current software development with ABAP and that it has aroused your interest in discovering old technologies in a new guise or even completely new technical possibilities. Let’s go! Fabian Lupa and Sven Treutler19Personal Copy for Rubens Lenzi, fawax21610@gamepec.com
© 2025 by Rheinwerk Publishing Inc., Boston (MA)
Chapter 1 Introduction to Modern ABAP Development In modern ABAP development in SAP S/4HANA and in the SAP BTP ABAP environment, there are some new fundamental technical concepts. In this chapter, you’ll learn how to write ABAP code that runs in all runtime envi- ronments—whether in a cloud or an on-premise solution. You’ll learn which technical underpinnings are relevant for that. In particular, we look at the language version and the application scenarios. Modern ABAP development is based on many technical concepts of the ABAP platform that are still comparatively new. These include the ABAP language version, the ABAP RESTful application programming model, and release contracts. In addition, there are now multiple different runtime environments for ABAP, each of which has different requirements. The question arises as to how you can implement applications that are stable, low-maintenance during upgrades, and cloud-capable. This chapter pro- vides you with an introductory overview before the following chapters go into more detail. Structure of this chapter Section 1.1 takes a look at the role of ABAP within the overall software devel- opment in the SAP context. In Section 1.2, we then present the new ABAP Cloud development model and describe the aspects it’s made up of. We’ll explain these in more detail in the subsequent sections. Section 1.3 deals with the ABAP language version as a technical option for differentiating between classic ABAP and ABAP Cloud. Section 1.4 deals with calling and using objects available in the standard SAP system. In Section 1.5, we briefly discuss the ABAP development tools as a development envi- ronment, before introducing the programming model for transactional applications, the ABAP RESTful application programming model, in Section 1.6. Section 1.7 deals with current SAP products that can be used to develop with ABAP. In particular, we look at the application scenarios for ABAP Cloud. In Section 1.8, you can find out what changes have been made to the ABAP release count and how you can establish the connection between cloud and 21Personal Copy for Rubens Lenzi, fawax21610@gamepec.com
Comments 0
Loading comments...
Reply to Comment
Edit Comment