Develop ABAP

download Develop ABAP

of 94

Transcript of Develop ABAP

  • 8/4/2019 Develop ABAP

    1/94

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    How to Develop in ABAP

    Applies to:SAP NetWeaver 7.0.For more information, visit theABAP homepage.

    Summary

    This is the PDF version of the development blog series on SDN published in 2007 that gave an introductionto 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 andadministrate the ABAP demo version and how to import and export programs. This PDF document solelyfocuses on the many blogs that focused on development in ABAP. This is why the PDF file starts with blog 3and 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 iswritten by Thomas Weiss. If you are interested in the comments and answers to the comments on the blogs

    you should read the originalblogs on SDN. Otherwise this PDF file gives you an easy opportunity to workyour 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 beforejoining, in 2001, the SAP NetWeaver product management training team where hisresponsibilities included the e-Learning strategy for ABAP. After becoming more involved inwriting 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 forexperts and for beginners by writing blogs in SDN.

    https://www.sdn.sap.com/irj/sdn/abaphttps://www.sdn.sap.com/irj/sdn/abaphttps://www.sdn.sap.com/irj/sdn/abaphttp://www.sdn.sap.com/irj/scn/weblogshttp://www.sdn.sap.com/irj/scn/weblogshttp://www.sdn.sap.com/irj/scn/weblogshttp://www.sdn.sap.com/irj/scn/weblogshttps://www.sdn.sap.com/irj/sdn/abap
  • 8/4/2019 Develop ABAP

    2/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    Table of Contents

    Why and How the Server Matters to You as a Developer: Server Architecture and Work Processes .............. 4ABAP Application Server for Newbies Why and How the Server Matters to You as a Developer .............. 4Developing on the Server................................................................................................................................ 4The Three-Layer Architecture ......................................................................................................................... 5Work Processes in Some Detail ..................................................................................................................... 5The Three Layer Architecture Continued ........................................................................................................ 7Summary ......................................................................................................................................................... 8

    Many Developers on one Central Server - How Does It Work? ......................................................................... 9Many Developers on One Server How Does It Work? ................................................................................ 9Developing on a Central Server The Way to Keep Your Sources in Sync ................................................ 10Summary ....................................................................................................................................................... 11

    Navigation in the Application Server ................................................................................................................. 12A First Hello World Program '.......................................................................................................................... 15

    The Repository Browser The Central Place in the ABAP IDE ................................................................... 15Packages ...................................................................................................................................................... 16A Package for Local Objects ......................................................................................................................... 16Hello World as a Local Program.................................................................................................................. 16Summary ....................................................................................................................................................... 19

    Creating a Program and a Package - An Introduction to the SAP Change and Transport System ................. 20Some Words of Motivation: Why Your Programs Deserve Better than Package $tmp ................................ 20Creating a Package - the Chance to Get in Touch With the CTS ................................................................ 21Creating a Package - the Details .................................................................................................................. 21 The Concept of a Transport Layer ................................................................................................................ 22 Some More Basic Concepts of the SAP Change and Transport System ..................................................... 23Package Building Continued ......................................................................................................................... 25Creating a Program within a Package .......................................................................................................... 27Outlook .......................................................................................................................................................... 28

    A First Little Business Program ' ....................................................................................................................... 29The Aim: Our first Little Business Program ................................................................................................... 29How to Use the ABAP Documentation .......................................................................................................... 29 How to Get an Internal Table with the Line Type of a Database Table ........................................................ 30Open SQL in ABAP ....................................................................................................................................... 30Test Output of an Internal Table 1: A Loop and a Write-Statement ............................................................. 31How to Get to Know the Properties of a Database Table ............................................................................. 31What the List Output with the Write Statement Looks Like ........................................................................... 32Test Output of an Internal Table 2: A Dynamic Way to Output Any Internal Table ...................................... 33Test Output of an Internal Table 3: The Object Oriented Way ..................................................................... 33The Whole Code of the Three Alternatives An Overview .......................................................................... 34Summary ....................................................................................................................................................... 36

    Getting More Familiar With the ABAP Dictionary ............................................................................................. 37PARAMETERS and the Selection Screen .................................................................................................... 38

  • 8/4/2019 Develop ABAP

    3/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    From the ABAP Dictionary to the Data Browser ........................................................................................... 39Data Element, Domain, and the Way They Interact ..................................................................................... 41At Last: The Source of Our Search Help ...................................................................................................... 43Summary ....................................................................................................................................................... 43

    Debugging in ABAP .......................................................................................................................................... 45Defining a Custom Structure in a Program ................................................................................................... 45A Useful Addition to the SELECT Statement ................................................................................................ 46What Is Wrong With Our Program We Start to Debug .............................................................................. 47The New ABAP Debugger A Short Overview ............................................................................................ 47Debugging Our Program ............................................................................................................................... 48Some Words on Efficient SQL Programming ............................................................................................... 49How to Use the ABAP Language Documentation Efficiently ........................................................................ 50Summary ....................................................................................................................................................... 52

    Get Your Program up to Speed - Overview & Introduction .............................................................................. 53The Programs to Be Analyzed ...................................................................................................................... 53 ABAP Runtime Analysis: Tool & Procedure ................................................................................................. 54

    The Foundation of an Application - Creating the Database Tables ................................................................. 59The Contents of this Blog in Some Detail ..................................................................................................... 59The Concept of a Client: A Key-Player in the SAP World of Business Programming .................................. 60Defining the Data Elements .......................................................................................................................... 61Creating Database Table YACCOUNT ......................................................................................................... 62Providing Some More Check Tables ............................................................................................................ 66Summary ....................................................................................................................................................... 67

    How to Dynamically Create Test Data for Our Database Table ....................................................................... 68The Basic Principle of How to Create the Entries Randomly........................................................................ 68How to Fill Database Tables in the Data Browser ........................................................................................ 69Looking at the Program Itself ........................................................................................................................ 70Running the Program .................................................................................................................................... 73Summary ....................................................................................................................................................... 74The Complete Program Code ....................................................................................................................... 74

    Your First ABAP Objects .................................................................................................................................. 77Starting with Web Dynpro for ABAP ................................................................................................................. 82

    Create your First Web Dynpro Component ................................................................................................... 82Model View Controller and the Context ........................................................................................................ 83Data in the View ............................................................................................................................................ 85Defining the View Layout .............................................................................................................................. 86A First Test .................................................................................................................................................... 89Bringing Life into the Component .................................................................................................................. 90Conclusion .................................................................................................................................................... 93

    Copyright........................................................................................................................................................... 94

  • 8/4/2019 Develop ABAP

    4/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    Why and How the Server Matters to You as a Developer: Server Architecture andWork Processes

    In general, you develop on a central server in ABAP. That is why the server matters to ABAP developersfrom the very outset. In this blog I explain the three layer architecture of the SAP NW Application ServerABAP and the basics of how users are distributed on work processes. The result of this architecture is ahighly 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 mightonly matter to you if your program should run on a server in the end. When you are developing in ABAPthings are different in this regard. In this blog I will explain why the server concerns you from the very outsetand why, consequently, you need to have some knowledge about the SAP NetWeaver Application ServerABAP. And this is what I want to provide you with in this blog: some basic information on the SAP NWApplication Server ABAP.

    Developing on the Server

    For those experienced with other programming languages like C, Java, or Visual Basic working with ABAPoffers some features they might not be accustomed to. The structure of the development environment forABAP is different from probably everything that you might have encountered so far: In ABAP, you programon 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 NWApplication Server ABAP. You write your programs using the ABAP Editor of the ABAP Workbench and thetools integrated there, which are also part of the server.

    However, the SAP NW Application Server ABAP not only contains the programming environment with itstools and utilities for supporting the software lifecycle. Developing with ABAP is closely connected to theserver in another respect: Once you activate your source code, platform-independent byte code isgenerated, which the runtime environment interprets for the program execution. And this byte codegenerated from your ABAP program runs on the SAP NW AS ABAP. Usually many developers are workingon the same server.

    This way, a problem known to all developers in large projects does not even arise: No quality managerneeds 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 accomplishthis is already done, and you as a developer already have your programs in the right place: As soon as yoursource code is activated the respective development object is visible on the central system. So the principlein 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 wholepersistence 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 theprogram 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 forbusiness programming are provided by the system. The ABAP server does a lot of services for you in thebackground 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 technologybehind the development process in ABAP is different. Some these features need getting used to, but after awhile 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 ABAPprograms run when designing and developing these programs. For this purpose, you first require someinformation about this architecture.

  • 8/4/2019 Develop ABAP

    5/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    The Three-Layer Architecture

    The SAP NW Application Server ABAP consists of three layers: presentation, application, and database. Thedatabase layer of a system is made up of a central database with a database management system and thedatabase itself. It not only contains the user data, but also the entire program code of the SAP NW AS andapplication programs, all administrative data, and Customizing settings. That is, the programs you developare stored in the database of the system.

    The application layer lies between the database layer and the presentation layer. It consists of one or moreapplication 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 anapplication 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 theoperating system. A fixed database connection is assigned to each work process. For you as a developerthis 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 backgroundby the server.

    There is no fixed assignment of users to work processes. A lengthy user session can utilize different workprocesses sequentially, and one work process is used by different users consecutively. Still the state of yourprogram 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 allthe 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 ofhis own, for the time his program is processed. All that can happen in the worst case only concerns the workprocess your program currently occupies. There is no such thing like crashing the whole engine in ABAP bya severe syntax error in your program.

    The way user requests are distributed to work processes combines the advantages of stateful and statelesscommunication. On the one hand, a user does not occupy a process for a long period while he might not bedoing anything. On the other hand, the Dispatcher(within the server) knows and remembers the identity of auser 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 aparticular 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, onerequest is processed within a single work process though it is possible to write programs in ABAP thatdistribute different costly tasks on several work processes (such as, for example, several large selects on thedatabase 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 thetable 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.

  • 8/4/2019 Develop ABAP

    6/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    If the request is processed the result is sent back to the user. The roll area that keeps the state and data ofuser 1 is rolled out and the work process is freed for requests of other users (picture 2). As long as userJones does not interact with the application he does not occupy any work process. By the way, the otherusers in our pictures are assigned to other free work processes in the same way as user Jones is. But this isnot 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 3and his roll area in the state he has left it is rolled into this work process (if there is not much traffic on aserver, you will in general stay into the same work process, because the server tries to minimize the cost forrolling-in andout, 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. Hisroll 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 atypical SAP ERP System running on an AS ABAP server might have 50 work processes and 500 userscurrently logged on (This is, of course, only an example to show the ratio, the actual number of workprocesses 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 onsimultaneously etc.. The number of work processes for a system is determined in the profile by the systemadministrator).

  • 8/4/2019 Develop ABAP

    7/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    The Three Layer Architecture Continued

    The kernel and the Basis services make up the part of the application layer that is specific to both theoperating system and the database. They are responsible for user and process management, databaseaccess, communication with other systems, as well as system monitoring and administration. The softwareprocesses 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 theapplication 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 ABAPWeb 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 (Dynprosare the classical user interfaces of most ABAP-based SAP programs and run in the SAP GUI). In our demoprograms 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 backendprogram and the real user interface written in Web Dynpro ABAP is not yet available or you want to test thebusiness logic apart from the presentation logic. The real user interface of your programs should always bedeveloped with Web Dynpro ABAP.

    The purpose of this division in three layers is high performance and scalability. The layer division is purelylogical. It does not imply over how many machines the system is distributed. In fact, all three layers canactually run on a single computer. For demonstration purposes, such as you have just done it in the case ofthis 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 thescalability of the three-level architecture.

    Browser

    WorkWork Work

    Dispatcher

    Application Layer:

    PresentationLogic

    Business Logic:

    Functions

    DB

    NW Business Client

    PresentationLayer: Client-Side

    SAP

  • 8/4/2019 Develop ABAP

    8/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    Summary

    Now you should have understood that you always work on the server when developing in ABAP. It is for thisreason that I have explained to you the basics of the three-level architecture of the server and the way usersare assigned to work processes. In the next blog I will explain the impact of development on a central serveron 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.

  • 8/4/2019 Develop ABAP

    9/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    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 thelatest sources as soon as they are activated instead of developing against proprietary source versions thatyou have on your PC and not updated for weeks. This is ensured by the technology underlying thedevelopment 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 haveexplained about the three-layer architecture of the server and the fact that developers always develop on thecentral ABAP server in real-world projects. As in the last blog I will provide a little example to illustrate whathappens when you activate your program.

    As I have told you, there are many developers developing on the same server. Each developer has his owninstance of the development environment on the serverwithin his roll area. You can compare this to manyclients working with different instances of a class.

    Technically the development environment comprises a set of programs such as the ABAP Editor, the ABAPWorkbench or the Class Builder plus a lot of other tools to support the development process. An ABAPdeveloper works on the client and has the classical SAP GUI that presents the user interface of therespective 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.

  • 8/4/2019 Develop ABAP

    10/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    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 usesclass 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 program1. Let us assume he renames the parameters of the method. Unaware of the consequences of thisincompatible change developer 3 activates his class. What happens? The old inactive version becomes thenew active one and there is an syntax error as soon as program 1 (the client of class 3) is recompiled:

  • 8/4/2019 Develop ABAP

    11/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    So you see: As I have already explained, there is no need to maintain a dedicated test system if thedevelopers belonging to a project develop on the same server. So, one typical problem of local developmentdoes not occur when you develop in ABAP. Instead of developing against proprietary source versions thatyou have on your PC and not updated for weeks, you will always use the latest sources as soon as they areactivated. This way, incompatibilities will be realized in a very early state.

    Summary

    I hope, by now you have understood what is so good about many developers working on one central system.

    Once you activate your program it is visible to everybody else on the system, and possible conflicts aredetected in a very early state.

  • 8/4/2019 Develop ABAP

    12/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    Navigation in the Application Server

    This Blog was posted by Manfred Lutz on 5 April, 2007, on SDN at ABAP ApplicationServer Beginner.

    InPart 2of this blog series, you logged onto the Application Server as 'BCUSER'. From this starting point,this blog explains how to find the functionality you need.

    Item No.1 is a Command field for the 'transaction code'. This is a shortcut to the transaction (functionality)you want to execute. Position the cursor in the field and press 'F1' to display the documentation.

    This is a general feature of the Application Server for online help on input fields.

    InPart 2of this blog series you were asked to enter 'SE80' in this Command field, which takes you directly tothe ABAP workbench. This works only in the logon screen, in all other screens you have to add '/' as the firstcharacter and a letter as described in the documentation. For example, if you add an 'o' (as in 'other') beforethe transaction code, a new window will be opened for that transaction.

    To the right of the Command field, there is an icon to display a history of commands used. Just click the iconand a pull down menu appears with all the transaction codes you entered so far.

    Item No.2 is two buttons in the toolbar. The left button opens a new window, which is the same as '/o' in theCommand field. The right button is for creating a shortcut on your desktop that will start the transaction youare currently in. You also can create a shortcut to any other transaction.

    Item No. 3 is a folder for your favorite transactions. Since it is not easy to remember all the transaction codesyou can collect the ones you'd like to use more often in that folder. To make it more convenient for you, thefolder displays the title of the transaction instead of the transaction code. Click the folder icon to open thecontext menu. 'Insert transaction' adds a new item to your favorites. You can do the same thing by clicking'Favorites' in the menu bar.

    If you are in a screen and you don't know the transaction code, just click the 'System' button in the menu barand select 'Status'. A new dialog box will appear.

    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6143https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6143https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6143https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6143https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6143https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6143https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6143https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6143
  • 8/4/2019 Develop ABAP

    13/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    This dialog box shows all the system information for your session. The transaction code used in the favoritesfolder can be found under 'Transaction'.

    One useful hint: In the Favorites folder and in the SAP Menu you can display the transaction code in thebeginning of each line (see screenshot below). For that, click on 'Extras' in the menu bar and select 'Settings'and check for 'Display technical names'.

    Item No. 4 is a navigation tree to the different transactions. Just open up the SAP menu, click 'Tools', openthe 'ABAP Workbench' folder, open 'Overview' folder, and then you'll find the 'Object Navigator' item.

    Double-click that item, and the 'SE80' transaction is started.

    Since the ABAP Trial Version is only the Application Server, there are no business-oriented transactions inthe navigation tree.

  • 8/4/2019 Develop ABAP

    14/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    There are three buttons in the middle of the toolbar, all for navigation purposes. They are highlighted when

    active.

    The green button is the 'Back' button, which goes back to the previous screen.

    The yellow button is the 'Exit' button that interrupts the transaction and takes you straight back to the entryscreen.

    The red button is the 'Cancel' button that stops the transaction, but will not always return you to the entryscreen.

    To close the session, just enter '/nex' in the Command field and press 'Enter' or the green 'OK' icon to the leftof the toolbar. All open sessions will then be terminated without any dialog.

  • 8/4/2019 Develop ABAP

    15/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    A First Hello World Program '

    After you have learned how to get the ABAP Object Navigator (transaction SE80) in the last blog it is nowtime to do it. And we will do here and now in this blog, we will write a Hello World program.

    Again, you will recognize a principle that I have explained in my blogs on the server. The ABAP developmentenvironment offers you a lot of benefits for free that take quite some extra work when developing in otherlanguages. When developing in ABAP, your program becomes part of a large mechanism that helps tomanage and organize development objects in a system landscape from the very outset. Let my elucidate this

    by an analogy. Creating a development object with C or Java is in a way like writing a text with a wordprocessor: You write it, save it where you want and that's it. In contrast, developing a program in ABAP is likewriting a text with a content management system where you are forced to create a document as part of alarger context with a number of default attributes, which help to pigeonhole your document within thissystem.

    The main structure is pretty simple: Every development object in ABAP belongs to a package. In general,every package has a property that determines to which other systems the package plus its content istransported if the package plus its elements are assigned to a transport request. The only exception to thisrule is the package $tmpwhich is made for local developments. The content of this package is nottransported to any other systems. In this blog we will create a program in this package for localdevelopments, while in a later blog we will create a package that we will use as a container for all elementswe will create in other blogs.

    The Repository Browser The Central Place in the ABAP IDE

    First we navigate to the transaction SE80 and have a short look at what we see there:

    The Object Navigator is the development environment for the central editing of all development objects. Wecall these objects repository objects. This includes all ABAP programs of AS ABAP and all their components.However, there are many other repository objects, such as global data definitions in the ABAP Dictionary,

    global classes, or XSLT programs. Together, these development objects in the ABAP Workbench form a so-called repository. This repository is a special part of central database, which, instead of customer data,comprises the programs of AS ABAP itself.

    The buttons in the upper part of the navigation area allow the selection of a browser. You can configure inUtilities - Settings which browsers are presented for selection with buttons. The browser we will generally beusing is the Repository Browser(1). It is the default setting of the Object Navigatorand also the mostgeneric browser, which provides an overview of all important repository objects sorted by different criteria.

    You access the repository objects through the Repository Browser by using so-called object lists. You mustselect such an object list in the dropdown list box, which is displayed in the navigation area under the

  • 8/4/2019 Develop ABAP

    16/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    buttons. In our screenshot you see the local objects(2) of user bcuser. As we have not created any localobjects by now, the area that shows these local objects is still empty (4). By choosing another entry in thedropdown list you can see other objects such as package, programs, function groups etc. The whole list isshown in the screenshot (3).

    Packages

    As already mentioned above, every development object must belong to a package. Packages organizedevelopment objects and handle their connection to the AS ABAP software logistics. That is a package is like

    a folder in a way. As for the software logistics, in ABAP your objects have to be assigned to a specific"software transport track" and a particular transport request. As soon as you release the relevant transportrequest, your object will be transported to the next system on that track. I will explain in another blog moretechnical terms what these tracks and transport requests look like in detail.

    You can view a package plus all its elements also in the SE80. Just choose the entry Packagein the objectlist of the Repository Browser, enter the name of the relevant package in the input field below and press"Enter". Then all the objects of that package are displayed.

    A Package for Local Objects

    We will make do with the default package for local development for our first program. In this case we do notneed to create a package and need no transport request. As already told, every AS ABAP contains apredefined package named $TMP, in which you can create local practice and test programs, that need notbe transported to other systems. Each user has a local package of his own in a system. If the SE80 does notalready show the space for your local objects, select "Local Objects" in the Repository Browser, enter"BCUSER" in the input field under the dropdown list box, and press "Enter": As result the Repository Browserdisplays all the development objects in this special package, which were created under your user name.

    Hello World as a Local Program

    To create a local program we select "Program" in the Repository Browser and enter the namez_hello_word_local in the input field below and press "Enter" or select the glassesicon.

    Here you see a very helpful feature of the ABAP development environment. If you want to edit an object thatdoes not exist, in general the system asks you if you want to create the respective object. We confirm andget to the next dialogue window.

    By the way, you should note and always remember as from now that repository objects created forcustomers in customer systems have different naming conventions than those that apply to Sap's ownprograms: A customer must use "Y" or "Z" for the first letter, or the abbreviations reserved by SAP for

    the customers company. Our Trial Version is set up as a customer system in which the user BCUSER isregistered as a customer. Therefore the names of the objects we create must start with an "y" or "z".

    In the next dialog window we deselect the item "With TOP INCL", confirm, and get to the next dialog window.

  • 8/4/2019 Develop ABAP

    17/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    In here you can define the properties of the new program. This is important, since the program propertiesdetermine the execution of the program in the ABAP runtime environment. One of the most importantprogram properties of an ABAP program is its type. From the list provided, we want to select the type"Executable program" for our simple Hello-World- program, and change or add no other properties. In

    particular, ensure that the properties "Unicode checks active" and "Fixed point arithmetic" should always bechecked.

    In the next dialog window we select "Local Object" and, thus, do not need to input a package name. Andthere we are. Now we have done everything we need to input the code of our first program.

    Note that in our blogs we will be using the new frontend editor available as of SAP NetWeaver 2004s, whichlike all modern editors supports syntax highlighting and so on. To configure this editor, select Utilities -Settings - Frontend Editor (new). To configure the editor for your own preferences, you can select the icon inthe lower right-hand corner. Up to and including Release 6.40 (SAP NetWeaver 04), you will still need to usethe old frontend, which provides a lot less support for programming.

    To go on, we double-click the program name in the object list of the SE80.

    On the right the editor opens. In it you see the framework predefined by the ABAP Workbench. This syntaxconsists of a few lines of comments, and also contains an initial statement named Report.

    *&----------------------------------------------------*

    *& Report Z_CREATE_EXAMPLE_DATA *

    *& *

    *&----------------------------------------------------*

    *& *

    *& *

    *&----------------------------------------------------*

    REPORT Z_CREATE_EXAMPLE_DATA.

    The first seven lines are comment lines, and the eighth line is a statement.

  • 8/4/2019 Develop ABAP

    18/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    Comment lines are introduced by an asterisk * in the first position. The rest of the line is arbitrary and isshown in a different color by the editor. To mark only the final portion of a line as a comment, you can usethe character ".

    As we want to input some code, we have to change the program. In order to do this we have to go to the

    change mode by pressing the respective button:

    Below the report-statement we enter:

    REPORT Z_HELLO_WORLD_LOCAL.

    data output_text type string.

    output_text = 'Hello World'.

    write output_text. "obsolete statement

    Admittedly, this listing needs some beautifying. The tool to do this is the Pretty printer. We configure thePretty Printer at Utilities-Settings-ABAP Editor-Pretty Printer and select Convert Uppercase/Lowercaseandbelow Keyword Uppercase. Next we press the Button Pretty Printer and our program now looks a bit nicer asall the keywords are now in capitals.

    To run the program we press the icon:

    Now let us spend some words on the syntax of this little program. Though this program is as simple as couldbe, I still want to add some comments on the general way ABAP programs are structured.

    Every standalone ABAP program, that is, all types of programs except for so-called include programs, startwith an introductory statement. In our first program, the introductory statement is REPORT. This designationis historical and expresses the fact that an executable program was once exclusively used for reporting.Here, however, it suffices to know that our first statement introduces the program z_hello_world_local.

    After the introductory statement, every ABAP program follows a fixed program structure that divides it intotwo parts:

    a global declaration part

    a procedural part

    In the global declaration part, which directly follows the introductory statement, declarative statements can beused for definitions and declarations, which will be visible and applicable throughout the entire ABAPprogram. Examples of objects that can be declared or defined here are data types, classes, and dataobjects. For larger programs, these declarations are generally made in a special include program, the "topinclude," which is supported by the ABAP Workbench and inserted at this position. After the globaldeclaration part comes the implementation part, in which the actual processing logic of the ABAP program isimplemented.

    The keywords and statements used in this program do not need many explanations. We declare a field of

    type string, assign a value to, and output it.

    Note some important information on the write-statement. The write statement outputs a list and it is driven bythe classic SAP Dynpro technology which should not be used to write to used to write applications with anstate-of-the-art user interface. You should use Dynpro-based UIs only in test-programs if you want to output(or input) some values in a quick and dirty way.

    You can compare the write-statement to the output to the console in Java. Just the same way you should notuse the write-statement to output something in an application proper. The right way to do this is to use a WebDynpro ABAP application as a user interface and to encapsulate all the logic of your programs in function

  • 8/4/2019 Develop ABAP

    19/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    modules or classes. Still, we will use the write-statement sometimes in our blog series in order to outputsome results or to input some values a program needs. And this is the way, you should use this classic, butby now obsolete UI technology yourself: Use it (only) to test your business logic separately from thepresentation logic.

    In order to show you, how the syntax check works in ABAP, let us change the Keyword DATA to DTA and

    press the Check Icon .

    At the bottom of the editor we get the information:

    This check gives you precise information as to in which line the error is. In case of a slip of pen like this, thesystem can make a reasonable guess as to what you wanted to type in, and proposes an semi-automaticcorrection. By pressing the Correct Errorsbutton (marked by the red-dotted frame) you can accept theproposal and your syntax error gets corrected.

    Next we save our program by pressing the Save button:

    The real storage of the program in the database is done by the system. You need not worry about it. All youneed to retrieve the program is the name. So there is no fumbling with files on the Web AS ABAP.

    If you remember the blog about the activation of programs, you probably know that this program is still notvisible to other users. Why? There is no active version of this program. A version of program that is notactivated is only visible to the developer of this program.

    In order to make our program visible in the whole system, we activate the it by pressing the Activate

    button:

    Now our program is visible to every user in the system.

    Summary

    Now you have learned all you need to develop a simple program in ABAP.

    You know that you need a package for every development object. If your objects does not need to

    be transported to another system the package $tmp for local development will do.

    You have seen how to find your way in the Repository browser of the SE80 and how easy you can

    create a new program. Just input the name of a new object and the system asks you if you want to

    create it.

    You are able to save, activate, run, or check a program for syntactical correctness

    In other words, now you know the basics, and we can go on with something more complex in the next blog.

    Special thanks to Horst Keller and the Galileo Press. By courtesy of the author and the publishing houseI could reuse some explanations of ABAP concepts from the lately published book: ABAP Objects. ABAP-Programming in SAP NetWeaverin this blog. And I will also do this in the following blogs of this series, as itis faster sometimes to reuse an explanation of some ABAB basics to some extent if it fits in the structure ofthe blog.

    In case, you want to know anything about ABAP in more detail than we can present here in our blog series,just consult the book. On 950 pages it covers, I feel temped to say, almost every conceivable detail of theABAP language

  • 8/4/2019 Develop ABAP

    20/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    Creating a Program and a Package - An Introduction to the SAP Change andTransport System

    This blog is about how to create a transportable package, how to create a program within this package, andhow to get the connection to the integrated software logistics of the server, the SAP Change and TransportSystem(CTS) right from the beginning. Doing this you will get a grasp of what a multi layer systemlandscape for development is for and what the concepts of a transport layer and a transport requests meanin this context. This will provide you with a basic understanding of the complex world of software logistics in

    the ABAP world.

    Unfortunately, I must confess it, you need a lot of dialog windows to define the relevant properties of apackage and a program. And clicking through these windows is a bit of a bore. No kidding. And the worst is:It will take so much time to show you what attributes the package and the program need and to explain whythey need these attributes with which value that I have decided to postpone any program code to the nextblog.

    But still I believe that you need the information I present in this blog. And I will try to make the long walkthrough many dialog windows more interesting by adding some more basic information to the CTS. But donot expect too much from it. The world of SAP CTS is complex, and I can only scratch its surface. But let mefirst spend some thoughts on why we are not content with our demo programs in the package $tmp for localdevelopments.

    Some Words of Motivation: Why Your Programs Deserve Better than Package $tmpDevelopment is not only about devising cool patterns, algorithms and coming up with a hip design. This isthe bright side of developing. What I show in this blog is, in a way, the monotonous housekeeping of thedeveloper. It is not cool, but it has to be done, if you will not end up in a mess with your cool programs. Andyou will get rewarded for it. By assigning your development objects to a package and a transport request withthe right properties, you will keep your developments tidy, from the very outset.

    This proper structuring of development objects becomes particularly important if you work in a team on adevelopment project. When just developing on your own at home, this assignment of your objects to thesoftware logistics is not strictly necessary and means some overhead expense for you. Nevertheless, youmight also profit from it when just working on your own. To return to our analogy of housekeeping: Avoidingproducing a mess is more important if you share an apartment, but it is not wrong if you live on your owneither. The same applies in analogy to developing on your own with our demo version at home. There is onlyone default package $tmpfor local development for each user. And you need more packages to manage alot of different developments. Just imagine you had all files on you PC in one folder. In the same way, it doesno good to have all your development objects in your package $tmp.

    But there is an even more compelling reason to use a transportable package as a container for yourprograms right from the beginning: You cannot even export local objects to a file. (In fact this isunconditionally true only for objects in package $tmp. They can never be transported. Objects in a localpackage can be transported in a special type of transport request: a request for the transport of copies. Butthis type of request can only be created in the Transport Organizer, SE09 and not from the dialog windowsprovided by the ABAP Editorin the SE80. As I do not want to introduce the SE09 in this blog we have tomake do with a normal transportable package).

    As ABAP development objects are stored in the database of the system you cannot just copy a program fileif you need it elsewhere. You need to export it to transport files first, and then you can import these files intoany other application server ABAP if you have access to the file system of the underlying physical server.

    This is the motivation and an explanation as to why even solitary developers at home should not be contentwith developing in package $tmp. Your programs deserve better. They should live in a transportablepackage.

  • 8/4/2019 Develop ABAP

    21/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    Creating a Package - the Chance to Get in Touch With the CTS

    This walk through a lot of dialog windows, cumbersome as it is, might still be interesting to those who havesome experience in handling these things. In a way, this cascade of dialog windows resembles a wizarddriven activity. You may get along in these windows, and still not really know what you are doing. This is theway I got through some wizards. I was happy to be out of it, and hoped that I had fed the wizard the info itneeds and that the wizard would not take revenge on me: Maybe due to my limited knowledge I had providedsome syntactically correct data that nevertheless did not lead to a semantically meaningful outcome.

    Since the input in these dialog windows connects your development objects to the SAP Change andTransport System and this powerful system is really complex, the odds are good that you do not really knowwhat you are doing there, though you get along quite successfully in these windows. In any case, if you areone of those you will probably profit from this blog.

    Creating a Package - the Details

    By creating a package we are laying a cornerstone for all subsequent developments in later blogs, as we willuse it throughout all parts of our little demo application. Moreover you learn the little steps you have to takebefore you can start typing in the code, whenever you need a new development object. After this blog we willsimply presuppose that you know how to perform these steps, and if we create other development objectssuch as a global class, a function group and a function module, a database table or a data element in theABAP Dictionary, we will only explain what is different from the procedure explained in this blog.

    As packages themselves are also repository objects, which can be edited using the ABAP Workbench, weuse this tool to create our package. To do this, we select the package object list in the Repository Browser,and enter the name y_abap_demo into the input field below.

    Again you see this very helpful feature of the ABAP development environment: If you want to edit an objectthat does not exist, in general the system asks you if you want to create the respective object. We confirmand get a dialogue window:

    In addition to a short description you must specify the Application Component, the Software Component, andthe Transport Layer. In order to input the software component, we select suitable entries from the selectionlist, which is displayed after pressing the input help key (F4). As already mentioned, this value help is animportant and extremely helpful feature, and you find it throughout the SAP AS ABAP and all ABAP-basedapplications if their developer has provided it. So let me show you in the next figure how this value helpworks. You select the field with the label Software Component, enter (F4) and you get the value help if it isprovided:

  • 8/4/2019 Develop ABAP

    22/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    In our case the values you see are created by the system administration when the system was set up: It is alist the software components that are available in the system. The software component HOMEis meant bySAP for customer development and equipped with all the tools available for this. We select it and confirm byselecting the check mark (1). In case a list in a value help is very long, select the telescopeicon (2) and starta search.

    The Concept of a Transport Layer

    The transport layer is an important concept. It refers to the transport path a package should take in a systemlandscape. The usual landscape has a least three layers:

    The basic idea behind this layered system structure is simple: You develop an object in the developmentsystem and test it in the consolidation system. When all tests are successful you transport your testeddevelopment objects to the productive system. The SAP CTS enables you to define this path as an attributeof a package. Due to this feature there is no fiddling about with the destinations of development objects. You

    just define them in the properties of the respective package in the beginning.

    How useful the concept of a transport layer is, becomes in particular evident if you have, for example, onedevelopment system for different productive systems.

  • 8/4/2019 Develop ABAP

    23/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    In the landscape shown in this figure it makes sense to define two transport layers, one that for a path fromthe development systemover consolidation system 1 to productive system 1 and the other layer that leadsfrom the same development systemto consolidation system 2and productive system 2.

    Due to this organizational structure development objects destined for productive System1 are from the veryoutset in a different pigeonhole than those for productive System 2.

    The arrows in these figures only show the direction and the destination of the relevant transports. Thetransport layer by itself does not transport anything. You need a transport request to get somethingtransported. Maybe an analogy can help to expose the way the concepts of a package, a transport layer, its

    respective destination system, and the export from and import into a system are interrelated:

    The transport layer is like a subway line and the transport request is like the tram. Assigning some object to atransport line is like buying a ticket for this line, while assigning an object to a transport request is likeactually putting it on the train. Exporting the transport request is like the train leaving the station, and theimport is the reverse.

    Some More Basic Concepts of the SAP Change and Transport System

    Let me show you an example to help you understand how a program BB in a package z_my_package

    assigned to transport layer DeCoPro and transport request 1 is transported through a system landscape withthree layers (the names of the transport request and the transport layer are simply chosen for didacticreasons and irrespective of existing conventions and technical constraints). The figures just concentrate onthe entities mentioned: The program, its package, the transport request and the transport layer.

    1. Our Program is assigned properly to the package, this in turn is assigned to a transport layer, both areassigned to the same transport request, that is a transport request that has the same destination as the firstdestination defined in the transport layer. So far nothing has been transported. The transport is not releasedand you can still change it, that is, you can, for example, assign other objects to it or change programs in therequest.

    2. The transport request has been released from the development system and been imported into theconsolidation system. As you see, there are copies of program BB and its package in the relevantdestination system after the transport. And this makes sense: If the transport moved the program, manytransports would empty a system, and above all, you could no longer change a program after it has been

  • 8/4/2019 Develop ABAP

    24/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    transported out of a system. The released transport request is in the consolidation system too, and it also stillexists in the development system. In fact, this is only the logical perspective. Physically the objects in areleased transport request are written to a file, and this file exists only once. When it is imported into anothersystem, this system gets a reference to this file.

    3. Next after the tests in the test system are completed successfully we import the transport request into theproductive system.

    Again, physically the productive system just gets a reference to the exported transport request in the file.So the arrow between the systems only expresses a temporal and logical sequence. I still decided to usethese arrow as this is the typical way to sketch the structure of the transports through a SAP systemlandscape. The physical structure (see figure below) is like this: When importing the Transport Request 1into the consolidation and the productive system these systems just get a reference to the export files of therelevant transport request:

    At this stage of the explanation, you might ask yourself what happens if you have to change program BB forsome reason. Well, let us suppose in the productive system a branch of your program is executed that hasnot been tested so far, and the program does not behave as expected. So we have to change it, and we dothis in the development system. This is what the division in the three layers is for. As the name suggests, ingeneral, you only develop in the development system. Of course, there are some situations when you bettercorrect errors in the consolidation system (for example if this system gets programs from differentdevelopment systems and the error does not appear in the development systems, but only when the sourcesfrom the relevant development systems are activated and run on one system), but then you should change

  • 8/4/2019 Develop ABAP

    25/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    the relevant development objects in the consolidation and the development system. Otherwise you will easilyget inconsistencies between these two systems. But in our example we can stick to the general rule todevelop in the development system.

    In order to change the program, we need to assign it to a new unreleased transport request:

    There we are. We have assigned the program to a new unreleased transport request, which can still bechanged. A package is usually only transported once, except for the case that the package properties havechanged. For this reason we only assign the program to a new transport request and not the package. Butwhat happened to the previous assignment of the program to transport request 1? Nothing. The point is

    simple: A development object can be assigned to one unreleasedchangeable transport request only, but,in addition to many released transport

    requests.

    But why is it that the assignments to the old, released requests do still exist, if they are not changeable?What are they good for? Probably you guess the answers: This is for matters of versioning. Whenever atransport request is released a actual version of the program state at this time is stored. You can both returnto this old version in case you need to or simply use it to track when which version of a program wasreleased. Before leaving this short introduction to the transport system, let me mention that, of course in ourexample we need to transport our bug fix to the productive system, before our problem is corrected there.

    But this should suffice by now to give you a basic understanding of the SAP Change and Transport System.As I told you before, the CTS offers a complex set of features, and in this intro blog I can do no more thangive you a clue as to what you are doing when you fill out the relevant fields during the creation of packageand a program.

    Package Building Continued

    So let us go on with our example. For our demo system you should use the transport layer znsp throughout

    (as already told, you also need a transport layer if want to export a development object to a file. In a laterblog we show how you export and import development objects to or from a file).

    If you have input all values as shown on the last figure you press the Create button .

  • 8/4/2019 Develop ABAP

    26/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    In the next dialog window you have to assign your package to a transport request.

    As we do not have a transport request of our own so far we create one by pressing the Createbutton in thisdialog window and the next dialog window appears. We input some short description as shown:

    Just note in this context: In a real-world development project you will always use a transport request that iscreated in the transaction SE09 and paste this into the window with the header Prompt for transportableWorkbench Request, that is the window we have just shown, and not create the transport request by usingthe Createbutton in this window. By using the SE09, you have more control on the transport request you get.

    If you just need a transport request without any particular properties, you can do it the way we do it here.Pressing the Savebutton opens another dialog window:

    There it comes: Our first transport request. We finish the creation of our package by pressing the Createbutton. And now we have done it. We have created a package of our own.

    The package we have just created is shown in the list below the input field of the Repository Browserwherethe $tmppackage of our BCUSERwas shown before.

    In case you feel a bit dizzy by now because of the bunch of dialog window, do not hesitate. Let us dosomething similar again and pass a similar cascade of dialog windows in order to create a program in ourpackage.

  • 8/4/2019 Develop ABAP

    27/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    Creating a Program within a Package

    So we create a program within this package, or to put it another way, create a program and assign it to thispackage. If you have completed this task you will see that these dialog windows always appear in a definedorder, and once you have understood this order, you will feel no more confused by clicking your way throughthe dialog windows that by walking through a long floor with several doors.

    So let us start. We right-click on the package Y_ABAP_Demo and choose Create - Program.

    Again we are lead to a dialogue window, where we input the name of the program we want to createy_select_f_flight. We deselect "Top Include" because we still do not need a top include, and weconfirm. As in the case of our last program z_hello_word_local we get the dialog window that definesthe program properties. We confirm again and in the dialog window we see that the system already proposesy_abap_demo as the package for our program. We press the Savebutton.

    The next dialog window also offers little work for us. The transport request our package belongs to is alreadyin the relevant field.

  • 8/4/2019 Develop ABAP

    28/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    Again we confirm and we have done it: We have created a new program within a package.

    The procedures I have just described might look like a lot of work, but let me repeat it: After a short while itwill cause no more trouble than getting the car key, opening the car, sitting down, fastening the seat belt, andturning the ignition key. In real life, you hardly pay any attention to these actions. In the same way you willcreate programs in ABAP. The steps are always the same:

    Give the program name,

    Define the properties of the programs (in general, you just accept the values proposed by the

    system),

    Assign your program first to a package,

    Assign your to a transport request.

    Outlook

    Instead of a summary I want to finish this blog by giving an outlook on what we will do in the next blog. Bynow the ABAP Editor has opened in the change mode and below the usual comments at the beginning of areport you have the first line: report y_select_f_sflight. You know this already from the last blog

    From here we will start in one of the next blogs and write a program that performs the task of a typical

    business program: It selects some lines from a database table that fulfill a given condition, stores them in acontainer in the program, an internal table, and shows this internal table in a quick and dirty way on thescreen. We will use a Dynpro-based list and an object-oriented alternative to do this. As already mentioned,you should use this technology for test purposes only: It facilitates a fast and easy output to the screen, butdoes not support the model-view-controller paradigm.

    In some later blog we will show you how to output a table like this in a real world program: You encapsulateyour business logic that contains the SELECT statement in a global class or a function module and offer therelevant data in a getter method. The presentation in the UI is done in a Web Dynpro ABAP application thataccesses the relevant modularization unit that offers the data.

  • 8/4/2019 Develop ABAP

    29/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    A First Little Business Program '

    Now it is time to write a program that does something more than just output "Hello World". In blog 7 of ourseries we have done the necessary preparatory work, that is, we have created a transportable package forall our programs and a program within this package. With some more experience you will handle this prep-work very fast with hardly paying any attention to it, though it might look time consuming at first sight. Theother reason why I spent some more time on this is that it will pay if you know what your are doing whenclicking your way through these dialog windows: The SAP CTS (Change and Transport System) does not

    exist for its own sake, but it has proven to be highly useful in large development projects and that is why SAPcreated the CTS.

    In any case, the result of the last blog will be the starting point at which be begin to write our program. Youwill only be able to reproduce what we are doing in this blog, if you have the results of this blog or are able tocreate an empty report, that is a program of the type report. If you have trouble doing this, just look inblog 7.

    The Aim: Our first Little Business Program

    These were the preliminaries. So let us resume the work we have begun in the last blog. Our aim is to write atypical business program: It selects some lines from a database table that fulfill a given condition, storesthem in a container in the program, and shows this data in a quick and dirty way on the screen. As to thepresentation of the result in the user interface I will show three alternatives that are easy to realize, straightforward to understand and require a minimum of coding effort. You will probably be surprised at how simple it

    is to output a result table on the screen in ABAP.All three alternatives are based on classic Dynpro technology. That means you should use them for testpurposes only, if you need to output some result fast. Each alternative has an advantage of its own andcontains new ABAP commands for you: The first one is straight forward in that you see all the differentcomponents that you output. You can use the second alternative to output any result table of a SELECT onthe screen no matter what its components are. Understanding this you get to know two important means fordynamic programming: the field-symbol, which is a sort of a pointer and the dynamic assign. The thirdalternative is based on a service class that needs hardly more than the name of table you want to output.The code of this gives you an impression of how object orientation is realized in ABAP.

    Nevertheless, useful and fast-to-realize as these alternatives are, they are all more or less comfortable waysto output results for test purposes. In a real-world program you use Web Dynpro ABAP, encapsulate yourbusiness logic in a global class or a function module and hand over the data needed in the user interface asparameters. But I think it is perfectly legitimate to use this classic technology at this stage of our blog series.Just compare it to the output to console so widely used in Java tutorials though nobody would bother a realend user with such a user interface.

    How to Use the ABAP Documentation

    Our example is based on the SAP flight model: This model gives a simple description of seat bookings inpassenger airplanes by flight customers and is realized in a set of database tables such as SCARR for aircarriers, SPFLI for flight connections, SFLIGHT for flights and SBOOK for bookings. You find moreinformation on this model in the SAP Help Portal under thislink. The SAP Help Portal contains the SAPdocumentation in different tree structures. The key node of the ABAP documentation in this portal ishere.The topics we touch in our blogs are mainly covered under these three subnodes

    https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6313https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6313https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6313http://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21f304446011d189700000e8322d00/frameset.htmhttp://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21f304446011d189700000e8322d00/frameset.htmhttp://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21f304446011d189700000e8322d00/frameset.htmhttp://help.sap.com/saphelp_nw2004s/helpdata/en/74/f72707c850b6489e32614108e38ecb/frameset.htmhttp://help.sap.com/saphelp_nw2004s/helpdata/en/74/f72707c850b6489e32614108e38ecb/frameset.htmhttp://help.sap.com/saphelp_nw2004s/helpdata/en/74/f72707c850b6489e32614108e38ecb/frameset.htmhttp://help.sap.com/saphelp_nw2004s/helpdata/en/74/f72707c850b6489e32614108e38ecb/frameset.htmhttp://help.sap.com/saphelp_nw2004s/helpdata/en/cf/21f304446011d189700000e8322d00/frameset.htmhttps://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6313
  • 8/4/2019 Develop ABAP

    30/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    The documents under the node ABAP Programming and Runtime Environmentdescribe language-relatedtopics. Under the header ABAP Workbenchyou find documentation on the tools to edit objects like reports,function modules, and global classes, on the Transport Organizer, on test tools like the ABAP Debugger andthe Performance Trace and all the other tools of the ABAP Workbench. The Web Dynpro ABAPdocumentation provides a description of the complete architecture of Web Dynpro ABAP and its mainconcepts. You should consult the Help Portal for ABAP topics when you have questions that are related totools, the architecture or the relation of concepts. For information on the keywords and syntax of thelanguage itself there is the system documentation. One way to access the system documentation is bymarking the relevant command in the editor and pressing the F1 button.

    How to Get an Internal Table with the Line Type of a Database Table

    This was a short digression to the ABAP documentation and how to access it. Let us go on and select someflights from the database table sflight, in particular the flights that fulfill two conditions: The airline isAlitalia and the seat capacity of the airplane is smaller than 250 seats. We want to output the result set of thisselect condition on the screen. We begin our program by declaring the data we need:

    DATA: itab_flight TYPE STANDARD TABLE OF sflight,

    wa_flight TYPE sflight.

    In the first statement we define an internal table with the line type of the database table sflight. The waythis works in general is simple:

    DATA: sometable TYPE STANDARD TABLE OF [any database table].

    This declaration defines the internal table some_table with the line type of the database table given in thesquare brackets at the end. A internal tableis the ABAP data type that is tailor made for businessprogramming. It is a dynamic data field that can contain a practically infinite number of lines. You can usecentrally defined line types or define a line type within your program.

    The figure shows a linetype for contacts (1). It consists of forename, last name and city. The internal tableitab_contacts (2) can contain a practically infinite number of lines, the technical size limit for an internal tableis 2 GB.

    Open SQL in ABAP

    Next we select from the database table sflights all flights of the carrier Lufthansa with airplanes that haveless than 250 seats:

    SELECT * FROM sflight INTOTABLE itab_flightWHERE carrid = 'LH' AND seatsmax < 250.

  • 8/4/2019 Develop ABAP

    31/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    As you can see a subset of SQL is part of ABAP. This so-called Open SQL has a big advantage for you: It isa database independent subset an SQL, so that your SQL statements are valid for the database of everyvendor that is supported by the SAP NetWeaver Application Server ABAP. As the application server alwayshas a database connection at hand, you need not care about opening, administrating and closing such aconnection. By using the keywords INTO TABLE you perform an array fetch, that is, the whole result set istransported into the internal table. The only precondition is that the database table and the internal tablehave the same line type.

    Next we want to see the content of the internal table. One way to see the content of this internal table at

    runtime is to switch to the debugger and to have at a look at the content of it. We will show in a later bloghow easy this is in ABAP. You can just set a breakpoint at a particular statement and the debugger opens assoon as this statement is processed.

    Test Output of an Internal Table 1: A Loop and a Write-Statement

    Here we will output the content of the internal table on the screen by using a classical list. ABAP has aparticular control statement to loop over all lines of an internal table. Let us use it:

    LOOPAT itab_flight INTO wa_flight.

    WRITE: wa_flight-mandt,

    wa_flight-carrid,

    wa_flight-connid,

    wa_flight-fldate,

    wa_flight-price,

    wa_flight-currency,

    wa_flight-planetype,

    wa_flight-seatsmax,

    wa_flight-seatsocc,

    wa_flight-paymentsum,

    wa_flight-seatsmax_b,

    wa_flight-seatsocc_b,

    wa_flight-seatsmax_f,

    wa_flight-seatsocc_f.

    SKIP.

    ENDLOOP.

    Every line of the internal table is put into the work area consecutively. Inside the loop the differentcomponents of the work area wa_flight are written to the list output. In ABAP the hyphen is the componentselector for a structure.

    How to Get to Know the Properties of a Database Table

    You may ask how could I know the components of this structure. Answering this question is a good

    opportunity to show another useful feature of ABAP. Obviously, the work area is a structure of the line type ofthe database table sflight. So we double click the name of this database table in the declaration at the top

  • 8/4/2019 Develop ABAP

    32/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    of our report. We are asked to save the program, and we confirm. There we are:

    The system has led us to the location where the table is defined. This is the ABAP Dictionary(transactionSE11). By using the Backbutton we return to our program. So this is the way you get to know thecomponents of the line type of a database table.

    What the List Output with the Write Statement Looks Like

    The way the output to a list works is simple: As soon as the whole list is filled it is output to the screen. So letus save and run our program, and the upper part of the result on the screen looks like this:

    Obviously this way to write the lines of the internal table while looping over it presupposes the knowledge ofwhat the components of this table are.

  • 8/4/2019 Develop ABAP

    33/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    Test Output of an Internal Table 2: A Dynamic Way to Output Any Internal Table

    Next I will show you a way to write the lines of a table without knowing the different components of its linetype. First of all you can reuse these lines of code to output any result of a SELECT that is stored in aninternal table. And secondly, you encounter two important means to realize dynamic programming in ABAP:the field-symboland the dynamic assign.

    First we have to declare such a field-symbol, this is a particular field type in ABAP. Without going into thedetails of it, you should know that a field symbol works like a pointer without pointer arithmetics, but has avalue semantics. That is you can assign it to different data fields and when accessing their content there is

    no need for dereferentiation.

    FIELD-SYMBOLS: TYPEANY.

    The typing ANY is necessary because the field symbol should be able to refer to data of any type. And this iswhat our loop looks like now using a dynamic assignment to the different components of the work area:

    LOOPAT itab_flight INTO wa_flight.

    DO.

    ASSIGNCOMPONENT sy-indexOFSTRUCTURE wa_flight TO .

    IF sy-subrc 0.

    SKIP.EXIT.

    ENDIF.

    WRITE .

    ENDDO.

    ENDLOOP.

    The most complex activity is contained in the third line. The rest is simple and straight forward: The systemvariable sy-index contains the loop counter that is counted up with every processing of the loop. The n-thcomponent of the structure is assigned to the field symbol. If this is successful (if sy-subrc =0) the contentof the field symbol is output to the list using the write-statement. If there is no more component to beassigned to the field symbol, the assign is not successful (sy-subrc 0) and the we leave the DO-loop(the inner loop) and go on with the outer loop.

    To check if our new lines yield the same result we outcomment the original loop. You mark the relevant linesand press CRT and "

  • 8/4/2019 Develop ABAP

    34/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    The class method factory of the class cl_salv_table needs the internal table it should show, createsan instance of this very class, and exports a reference to this instance. In the second statement the methoddisplay of this instance outputs the table to the screen. Before we run the program, we should, of course,outcomment, the dynamic assign plus the loop:

    The Whole Code of the Three Alternatives An Overview

    Now let us have a look at the whole code of our program in one listing. I have outcommented alternative twoand three to output the internal table on the screen. So if you use this code as it is, you run alternative one.To change this just outcomment other parts of the code (press Shift + CRT + ">" to uncomment and CRT +">" to outcomment some lines):

  • 8/4/2019 Develop ABAP

    35/94

    How to Develop in ABAP

    SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

    2010 SAP AG

    REPORT read_table_flights.DATA: itab_flight TYPESTANDARDTABLEOF sflight,

    wa_flight TYPE sflight,alv TYPEREFTO cl_salv_table.

    FIELD-SYMBOLS: TYPEany.

    SELECT *

    FROM sflight INTOTABLE itab_flightWHERE carrid = 'LH'AND connid = '402'.

    * Alternative one: Loop at table and write the different components of work areaLOOPAT itab_flight INTO wa_flight.WRITE: wa_flight-carrid,

    wa_flight-connid,wa_flight-fldate,wa_flight-price,wa_flight-currency,wa_flight-planetype,wa_flight-seat