ebook img

development in ABAP. This is why the PDF - SAP.com PDF

94 Pages·2010·2.1 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview development in ABAP. This is why the PDF - SAP.com

How to Develop in ABAP Applies to: SAP NetWeaver 7.0.For more information, visit the ABAP homepage. Summary This is the PDF version of the development blog series on SDN published in 2007 that gave an introduction to ABAP newbies who want to learn how to develop simple programs in ABAP. This PDF file does not contain the few blogs of the original series that explained how to install and administrate the ABAP demo version and how to import and export programs. This PDF document solely focuses on the many blogs that focused on development in ABAP. This is why the PDF file starts with blog 3 and has some gaps in the numbering. The author of the relevant part is listed at the beginning of each blog. If there is no author listed, the blog is written by Thomas Weiss. If you are interested in the comments and answers to the comments on the blogs you should read the original blogs on SDN. Otherwise this PDF file gives you an easy opportunity to work your way through the whole series. Author: Thomas Weiss Company: SAP AG Created on: 28 January 2010 Author Bio Thomas Weiss has a Ph.D. in analytic philosophy. He worked as a professional writer before joining, in 2001, the SAP NetWeaver product management training team where his responsibilities included the e-Learning strategy for ABAP. After becoming more involved in writing ABAP material himself, he is now a member of the SAP NetWeaver Application Server Solution Management. One of his main interests lies in rolling out ABAP topics both for experts and for beginners by writing blogs in SDN. SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2010 SAP AG 1 How to Develop in ABAP Table of Contents Why and How the Server Matters to You as a Developer: Server Architecture and Work Processes .............. 4 ABAP Application Server for Newbies – Why and How the Server Matters to You as a Developer .............. 4 Developing on the Server................................................................................................................................ 4 The Three-Layer Architecture ......................................................................................................................... 5 Work Processes in Some Detail ..................................................................................................................... 5 The Three Layer Architecture Continued ........................................................................................................ 7 Summary ......................................................................................................................................................... 8 Many Developers on one Central Server - How Does It Work? ......................................................................... 9 Many Developers on One Server – How Does It Work? ................................................................................ 9 Developing on a Central Server – The Way to Keep Your Sources in Sync ................................................ 10 Summary ....................................................................................................................................................... 11 Navigation in the Application Server ................................................................................................................. 12 A First „Hello World‟ Program ' .......................................................................................................................... 15 The Repository Browser – The Central Place in the ABAP IDE ................................................................... 15 Packages ...................................................................................................................................................... 16 A Package for Local Objects ......................................................................................................................... 16 „Hello World‟ as a Local Program .................................................................................................................. 16 Summary ....................................................................................................................................................... 19 Creating a Program and a Package - An Introduction to the SAP Change and Transport System ................. 20 Some Words of Motivation: Why Your Programs Deserve Better than Package $tmp ................................ 20 Creating a Package - the Chance to Get in Touch With the CTS ................................................................ 21 Creating a Package - the Details .................................................................................................................. 21 The Concept of a Transport Layer ................................................................................................................ 22 Some More Basic Concepts of the SAP Change and Transport System ..................................................... 23 Package Building Continued ......................................................................................................................... 25 Creating a Program within a Package .......................................................................................................... 27 Outlook .......................................................................................................................................................... 28 A First Little Business Program ' ....................................................................................................................... 29 The Aim: Our first Little Business Program ................................................................................................... 29 How to Use the ABAP Documentation .......................................................................................................... 29 How to Get an Internal Table with the Line Type of a Database Table ........................................................ 30 Open SQL in ABAP ....................................................................................................................................... 30 Test Output of an Internal Table 1: A Loop and a Write-Statement ............................................................. 31 How to Get to Know the Properties of a Database Table ............................................................................. 31 What the List Output with the Write Statement Looks Like ........................................................................... 32 Test Output of an Internal Table 2: A Dynamic Way to Output Any Internal Table ...................................... 33 Test Output of an Internal Table 3: The Object Oriented Way ..................................................................... 33 The Whole Code of the Three Alternatives – An Overview .......................................................................... 34 Summary ....................................................................................................................................................... 36 Getting More Familiar With the ABAP Dictionary ............................................................................................. 37 PARAMETERS and the Selection Screen .................................................................................................... 38 SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2010 SAP AG 2 How to Develop in ABAP From the ABAP Dictionary to the Data Browser ........................................................................................... 39 Data Element, Domain, and the Way They Interact ..................................................................................... 41 At Last: The Source of Our Search Help ...................................................................................................... 43 Summary ....................................................................................................................................................... 43 Debugging in ABAP .......................................................................................................................................... 45 Defining a Custom Structure in a Program ................................................................................................... 45 A Useful Addition to the SELECT Statement ................................................................................................ 46 What Is Wrong With Our Program – We Start to Debug .............................................................................. 47 The New ABAP Debugger – A Short Overview ............................................................................................ 47 Debugging Our Program ............................................................................................................................... 48 Some Words on Efficient SQL Programming ............................................................................................... 49 How to Use the ABAP Language Documentation Efficiently ........................................................................ 50 Summary ....................................................................................................................................................... 52 Get Your Program up to Speed - Overview & Introduction .............................................................................. 53 The Programs to Be Analyzed ...................................................................................................................... 53 ABAP Runtime Analysis: Tool & Procedure ................................................................................................. 54 The Foundation of an Application - Creating the Database Tables ................................................................. 59 The Contents of this Blog in Some Detail ..................................................................................................... 59 The Concept of a Client: A Key-Player in the SAP World of Business Programming .................................. 60 Defining the Data Elements .......................................................................................................................... 61 Creating Database Table YACCOUNT ......................................................................................................... 62 Providing Some More Check Tables ............................................................................................................ 66 Summary ....................................................................................................................................................... 67 How to Dynamically Create Test Data for Our Database Table ....................................................................... 68 The Basic Principle of How to Create the Entries Randomly........................................................................ 68 How to Fill Database Tables in the Data Browser ........................................................................................ 69 Looking at the Program Itself ........................................................................................................................ 70 Running the Program .................................................................................................................................... 73 Summary ....................................................................................................................................................... 74 The Complete Program Code ....................................................................................................................... 74 Your First ABAP Objects .................................................................................................................................. 77 Starting with Web Dynpro for ABAP ................................................................................................................. 82 Create your First Web Dynpro Component ................................................................................................... 82 Model View Controller and the Context ........................................................................................................ 83 Data in the View ............................................................................................................................................ 85 Defining the View Layout .............................................................................................................................. 86 A First Test .................................................................................................................................................... 89 Bringing Life into the Component .................................................................................................................. 90 Conclusion .................................................................................................................................................... 93 Copyright........................................................................................................................................................... 94 SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2010 SAP AG 3 How to Develop in ABAP Why and How the Server Matters to You as a Developer: Server Architecture and Work Processes In general, you develop on a central server in ABAP. That is why the server matters to ABAP developers from the very outset. In this blog I explain the three layer architecture of the SAP NW Application Server ABAP and the basics of how users are distributed on work processes. The result of this architecture is a highly scalable and robust server. ABAP Application Server for Newbies – Why and How the Server Matters to You as a Developer Usually as a developer in a language like C or C++ you need not care so much about the server. It might only matter to you if your program should run on a server in the end. When you are developing in ABAP things are different in this regard. In this blog I will explain why the server concerns you from the very outset and why, consequently, you need to have some knowledge about the SAP NetWeaver Application Server ABAP. And this is what I want to provide you with in this blog: some basic information on the SAP NW Application Server ABAP. Developing on the Server For those experienced with other programming languages like C, Java, or Visual Basic working with ABAP offers some features they might not be accustomed to. The structure of the development environment for ABAP is different from probably everything that you might have encountered so far: In ABAP, you program on the server from the outset. You do not develop the programs locally on your PC, nor do you store the sources in a versioning system or deploy the programs on the server at a later stage. In order to program with ABAP, you therefore require access to and developer authorization for the SAP NW Application Server ABAP. You write your programs using the ABAP Editor of the ABAP Workbench and the tools integrated there, which are also part of the server. However, the SAP NW Application Server ABAP not only contains the programming environment with its tools and utilities for supporting the software lifecycle. Developing with ABAP is closely connected to the server in another respect: Once you activate your source code, platform-independent byte code is generated, which the runtime environment interprets for the program execution. And this byte code generated from your ABAP program runs on the SAP NW AS ABAP. Usually many developers are working on the same server. This way, a problem known to all developers in large projects does not even arise: No quality manager needs to care about providing a system on which to deploy the programs from different developers and where to test the interaction of the programs from different developers in a project. Everything to accomplish this is already done, and you as a developer already have your programs in the right place: As soon as your source code is activated the respective development object is visible on the central system. So the principle in ABAP is: Development on a central server. You need also not care about checking in and out your sources in a content management system. The whole persistence and administration of different versions of your sources also happens transparently to the users. Pushing the Save-button in the ABAP Workbench stores your program in the database. You retrieve it by the program name: There is no fumbling with program files in ABAP. Again the server does it all for you. By the way, this is a typical experience when working with the SAP NW AS ABAP: Many things you need for business programming are provided by the system. The ABAP server does a lot of services for you in the background that developers or quality manager usually have to care about. The explanation for these conveniences is the fact that the organization and structure of and the technology behind the development process in ABAP is different. Some these features need getting used to, but after a while you will like them because thanks to them you can concentrate on what your job really is about: developing business logic. It is for this reason that you must take into account the architecture of the environment in which ABAP programs run when designing and developing these programs. For this purpose, you first require some information about this architecture. SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2010 SAP AG 4 How to Develop in ABAP The Three-Layer Architecture The SAP NW Application Server ABAP consists of three layers: presentation, application, and database. The database layer of a system is made up of a central database with a database management system and the database itself. It not only contains the user data, but also the entire program code of the SAP NW AS and application programs, all administrative data, and Customizing settings. That is, the programs you develop are stored in the database of the system. The application layer lies between the database layer and the presentation layer. It consists of one or more application servers (more than 100 servers possible) and a single message server, which is responsible for communication and load distribution within this layer. The programs that process the business logic of an application and all the development tools, such as the ABAP Workbench, run in this layer. Work Processes in Some Detail Technically, the actual processing takes place in work processes, which represent processes of the operating system. A fixed database connection is assigned to each work process. For you as a developer this means: You always have a database connection at hand. No need to get a database manager, to open, handle and close the database connection. The whole database handling is done for you in the background by the server. There is no fixed assignment of users to work processes. A lengthy user session can utilize different work processes sequentially, and one work process is used by different users consecutively. Still the state of your program is kept. The context of your work process is rolled in as soon as your program is processed and once the work process returns a result, your context is rolled out. It is this so-called roll area that contains all the data and programs that are currently processed by a user. This architecture makes for robustness and scalability. It is robust because every user has a work process of his own, for the time his program is processed. All that can happen in the worst case only concerns the work process your program currently occupies. There is no such thing like crashing the whole engine in ABAP by a severe syntax error in your program. The way user requests are distributed to work processes combines the advantages of stateful and stateless communication. On the one hand, a user does not occupy a process for a long period while he might not be doing anything. On the other hand, the Dispatcher (within the server) knows and remembers the identity of a user over time: This way each time a user session gets processed its context is known. To give you a better understanding of this mechanism I will present you an example of how a user of a particular application is assigned to different work processes at different points in time when performing different steps in a application. To avoid one possible misunderstanding from the outset: In general, one request is processed within a single work process though it is possible to write programs in ABAP that distribute different costly tasks on several work processes (such as, for example, several large selects on the database if they do not depend on each other). Let us suppose a loan officer, let us call him Jones works with an application in the office: First retrieves the table of debtors in a particular region. His request is processed by work process 1 (picture 1). But, of course, he might get any other work process that is currently free. SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2010 SAP AG 5 How to Develop in ABAP If the request is processed the result is sent back to the user. The roll area that keeps the state and data of user 1 is rolled out and the work process is freed for requests of other users (picture 2). As long as user Jones does not interact with the application he does not occupy any work process. By the way, the other users in our pictures are assigned to other free work processes in the same way as user Jones is. But this is not shown in the picture, as I want to keep the focus on the way user Jones is assigned to work processes. Next our loan officers want to get the details of a particular customer. He gets assigned to work process 3 and his roll area in the state he has left it is rolled into this work process (if there is not much traffic on a server, you will in general stay into the same work process, because the server tries to minimize the cost for rolling-in and –out, but this are optimization details, and I am interested here in the general mechanism). Again the work process is freed after the request is processed (picture 2). Next the loan officer sets a new credit limit for Smith and saves it. Again he gets another work process. His roll area is rolled in, the request is processed and the data is saved on the database. This way a user does only occupy a work process when the application he uses actually sends a request. Due to this mechanism it is possible to have far more users than work processes on an AS ABAP. So a typical SAP ERP System running on an AS ABAP server might have 50 work processes and 500 users currently logged on (This is, of course, only an example to show the ratio, the actual number of work processes on a server depends on many technical details such as the CPU power of the servers, the RAM that is available, what kind of applications the users typically are running, how many users are logged on simultaneously etc.. The number of work processes for a system is determined in the profile by the system administrator). SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2010 SAP AG 6 How to Develop in ABAP The Three Layer Architecture Continued The kernel and the Basis services make up the part of the application layer that is specific to both the operating system and the database. They are responsible for user and process management, database access, communication with other systems, as well as system monitoring and administration. The software processes or virtual machines, that interpret the platform-independent byte code as operating system- specific machine language commands, run in the kernel. The presentation layer represents the interface with the user and is responsible for the screen display. This layer receives user entries – that is, mouse-clicks and keyboard input – and passes them on to the application layer. Furthermore, it receives data from the application layer and displays it to the user. When writing a business application you should use Web Dynpro ABAP as a state-of-the-art user interface. A Web Dynpro ABAP component may run on the same server as the underlying business logic. A ABAP Web Dynpro application is displayed in the Browser or the Business Client. The ABAP workbench and all the other tools you need for developing use the Dynpro technology (Dynpros are the classical user interfaces of most ABAP-based SAP programs and run in the SAP GUI). In our demo programs in this series, we will sometimes use classical Dynpros to input and output data as a handy device just as you use the output to the console in Java Tutorial. It saves you time if you want to test a backend program and the real user interface written in Web Dynpro ABAP is not yet available or you want to test the business logic apart from the presentation logic. The real user interface of your programs should always be developed with Web Dynpro ABAP. Presentation Layer: Client-Side Presentation Browser BSroAwPs er NW Business Client GUI Application Layer: Presentation Logic Dispatcher Business Logic: Buffer • Functions Work Work Work Proces Proces Proces • s s s ABAP Programs D•atabase Layer BAPIS DB Processes DB • Web Services The purpose of this division in three layers is high performance and scalability. The layer division is purely logical. It does not imply over how many machines the system is distributed. In fact, all three layers can actually run on a single computer. For demonstration purposes, such as you have just done it in the case of this demo system, it is possible to install all three layers on a single PC. However, in the case of large, production applications of customers, this is more of a theoretical possibility, since it would counteract the scalability of the three-level architecture. SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2010 SAP AG 7 How to Develop in ABAP Summary Now you should have understood that you always work on the server when developing in ABAP. It is for this reason that I have explained to you the basics of the three-level architecture of the server and the way users are assigned to work processes. In the next blog I will explain the impact of development on a central server on the developing process. Again I will focus on an example that is intended to illustrate a basic mechanism. This time you will lean some details about what happens when you activate your program. SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2010 SAP AG 8 How to Develop in ABAP Many Developers on one Central Server - How Does It Work? In this blog I show you one big advantage of central development in an example: You will always use the latest sources as soon as they are activated instead of developing against proprietary source versions that you have on your PC and not updated for weeks. This is ensured by the technology underlying the development process in ABAP. An simple example illustrate how this works. Many Developers on One Server – How Does It Work? In the last blog I have explained some basics about the ABAP server: Let us now combine what I have explained about the three-layer architecture of the server and the fact that developers always develop on the central ABAP server in real-world projects. As in the last blog I will provide a little example to illustrate what happens when you activate your program. As I have told you, there are many developers developing on the same server. Each developer has his own “instance” of the development environment on the server within his roll area. You can compare this to many clients working with different instances of a class. Technically the development environment comprises a set of programs such as the ABAP Editor, the ABAP Workbench or the Class Builder plus a lot of other tools to support the development process. An ABAP developer works on the client and has the classical SAP GUI that presents the user interface of the respective development tools. The program(s) under development are stored on the central database. The program a developer writes within development client 1 is only visible to this developer as long as the program is not activated. SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2010 SAP AG 9 How to Develop in ABAP As soon as the developer activates a program it is visible on the whole server. This means, of course, that other programs can access it. Developing on a Central Server – The Way to Keep Your Sources in Sync One great advantage of this organization lies in the fact that incompatibilities will become visible very early. Let us refine our small sketch a bit to show you how this works in detail: Let us assume that program 1 uses class 3 (developed by development client 3). Remember: It is the active version of class 3 that is used. Inactive versions are not visible to other users (in fact they are not visible to any other development objects). Meanwhile there is a new inactive version of class 3 under development. As developer three is not very experienced he changes the interface of the method that is called by program 1. Let us assume he renames the parameters of the method. Unaware of the consequences of this incompatible change developer 3 activates his class. What happens? The old inactive version becomes the new active one and … there is an syntax error as soon as program 1 (the client of class 3) is recompiled: SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com © 2010 SAP AG 10

Description:
Jan 28, 2010 focuses on the many blogs that focused on development in ABAP. writing ABAP material himself, he is now a member of the SAP NetWeaver
See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.