Abap sample


Published on


Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Abap sample

  1. 1. www.LearnSAP.com SAP R/3 ABAP/4 Training Manual 5101 Camden Lane, Pearland, TX 77584
  2. 2. www.LearnSAP.com Course OutlineSection – A1. Introduction to ABAP 1.1. What is SAP R/3 1.2. SAP R/3 architecture and where ABAP fits in2. ABAP Development Workbench Tools 2.1. Object Navigator 2.2. Workbench Organizer 2.3. Data Dictionary 2.4. Menu Painter 2.5. Screen PainterSection – B3. Reports Statement 3.1. Line Size 3.2. Line-count 3.3. Message 3.4. Page Heading 3.5. Report Comment Section4. Declarations 4.1. Tables 4.2. Includes 4.3. Variables (Data Types and Data Objects) 4.4. Structures 4.5. Internal Tables 4.6. Constants5. Selection Screen / Input Fields 5.1. Parameters 5.2. Select – Options 5.3. Section Screen Formatting6. Program Events 6.1. Initialization 6.2. Start of Selection and End of Selection 6.3. At Selection Screen 6.4. At Line Selection 6.5. At User – Command7. Data Retrieval 7.1. Select Statement 7.2. Using the Select Statement for Single Line 7.3. Using the Select Statement for Several Lines 7.4. Using the Select Statement for Internal Table 7.5. Tables / Internal Table Operations8. Processing Data 8.1. Assignment Statements 8.2. Arithmetic Expressions and Mathematical Functions 8.3. String Processing 8.4. Type Conversions 8.5. Logical Expressions
  3. 3. www.LearnSAP.com 8.6. Control Level Processing 8.7. Subroutines 8.8. Function Modules 8.9. Logical Database 8.10. Variants 8.11. Create Transactions for Reports9. Formatting and Displaying Data 9.1. Event for Page Headers and Footers 9.2. Display OptionsSection – C10. Types of Program Analysis 10.1. Static Checks 10.2. Dynamic Checks and Short Dump Analysis11. Debugger 11.1. Breakpoints in Programs 11.2. Breakpoints in the Debugger 11.3. Watchpoints12. Performance Tools 12.1. Runtime Errors 12.2. SQL TraceSection – D13. External Data Access 13.1. Upload and download data from / to presentation server 13.2. Upload and download data from / to application server 13.3. Write a data extract program14. Data Transfer Methods 14.1. Understand the Transaction 14.2. Standard data transfer program 14.3. DBC program 14.4. Call transaction ProgramSection – E15. Dialog Application 15.1. Create a Module Pool 15.2. Create a Transaction16. Screen Painter 16.1. Use Screen painter to design a Screen 16.2. Arrange Data Dictionary elements of the screen 16.3. Set the OK-CODE17. Menu Painter 17.1. Create GUI Status 17.2. Create a Menu Bar for a Screen
  4. 4. www.LearnSAP.com 17.3. Define function Keys 17.4. Create Application Tool Bar for a Screen 17.5. Create window titles18. Screen Flow Logic 18.1. Understand screen flow logic 18.2. Create Process after Input and Process before Output modules 18.3. Use message for error processing 18.4. Call list processing within a transactionSection – F19. ABAP Query 19.1. Understand core functionality of SAP R/3 ABAP Query. 19.2. Explain the relationship between a user group, info set and query report. 19.3. Utilize the appropriate user groups and Info Sets to develop Queries. 19.4. Create all three types of SAP query. Basic List, Statistic and ranked list.
  5. 5. www.LearnSAP.com Section – A ABAP Workbench OverviewObjectives• Understand the use of ABAP/4 in developing SAP Application• Become familiar with the ABAP Workbench Tools• Become Familiar with the features of Object Navigator ABAP Editor Change and Transport System Data Dictionary Menu Painter Screen Painter Table of Contents Section – A1. Introduction to ABAP 1.1. What is SAP R/3? 1.2. SAP R/3 Architecture and where ABAP fits in 1.3. The Major Common Uses of ABAP/42. ABAP Development Workbench Tools 2.1. Object Navigator Exercise A211 – Create an ABAP Program using the Object Navigator 2.2. ABAP Editor 2.2.1. Editor Mode 2.2.2. Uploading and Downloading Source Code 2.2.3. ABAP/4 Attributes Screen 2.3. Change and Transport System 2.3.1. Development Class Exercise A2311 – Create a Development Class 2.3.2. Transport / Workbench Organizer Exercise A2321 – Assign Program to development class and display T.O.
  6. 6. www.LearnSAP.com 2.4. Data Dictionary 2.4.1. Tables, Domains and Data Elements Exercise A2411 – Create a Transparent Table Exercise A2412 – Specify Table Fields Exercise A2413 – Defining Data Elements and Domains Exercise A2414 – Define a value list Exercise A2415 – Specifying Technical Settings Exercise A2416 – Enter values into the table 2.4.2. Structure 2.4.3. Views 2.5. Menu Painter Exercise A251 – Create Menu and Push Button Using Menu Painter Exercise A252 – Create Title Bar using the Menu Painter 2.6. Screen Painter Exercise A261 – Design User Interface using the Screen Painter Lab Exercises • Exercise AL1 – Standard Toolbar Controls • Exercise AL2 – Application Toolbar Controls • Exercise AL21 – Changing the editor mode – Front-end editor • Exercise AL22 – Changing the editor mode – Back-end editor 1 • Exercise AL23 – Changing the editor mode – Back-end editor 2 • Exercise AL24 – Upload Code from text file • Exercise AL25 – Download code from ABAP editor to a local file • Exercise AL26 – Create Development class ZDEVC12 • Exercise AL27 – Assign a task to a main change request • Exercise AL28 – Create table ZTJTAB3 re-using domains3.0 Project A
  7. 7. www.LearnSAP.com1. Introduction to ABAP1.1 What is SAP R/3?SAP stands for Systems, Applications and Products in Data Processing. It is the name of thecompany and also the name of the software. R/3 stands for Runtime System Three. It is one ofthe ERP (Enterprise Resource Planning) systems around. Similar products are Oracle andPeoplesoft. ERP is used by companies to plan, organize, integrate and manage their variousoperations like accounting, finance, manufacturing and human resources. The main aim is toimprove efficiency and accuracy.1.2 SAP R/3 Architecture and Where ABAP fits inR/3 is based on client/serverarchitecture and uses arelational database to track allinformation related to acompany. It is made up of smallprograms called transactions. Atransaction is a program and setof system; and changefunctionality in the R/3 system.R/3 gathers related transactionstogether into groups and callthem modules. Thus a moduleis a set of transactions that dealwith the same area of businessfunctionality. R/3 modeled in athree-tier hierarchy is shownbelow.Presentation level – User InterfaceApplication level – business logic layer that runs on a serverDatabase level – stores data managed by SAPABAP (Advanced Business Application Programming) is the programming language used by SAPdevelopers to build transactions that make up the R/3 application. Its also used by companies tocustomize the R/3 application i.e. providing additional business functionality.It is a fourth-generation programming language with some features similar to some modernprogramming languages such as C, Visual Basic and Power Builder. It allows variables to bedefined, modulation of programs via subroutines and function calls, access to the database viaopen SQL and some event-oriented programming.1.3 The Major Common Uses of ABAP/4 a. Custom reports – a program that reads specific data from the database and then displays the data via the computer screen or printer. The purpose of a report is to read data from the database and write it out. It consists of mainly two screens. The first screen is called the selection screen. It contains input fields allowing the user to enter criteria for the report. For example, the report may produce a list of sales for a given date range, so the date range input fields would appear on the report’s selection screen. The second screen is the output screen. It contains the list. The list is the output from the report, and usually
  8. 8. www.LearnSAP.com does not have any input fields. In our example, it would contain a list of the sales that occurred within the specified date range. The selection screen is optional. Not all reports have one. However, all reports generate a list. b. Interface – a program that moves data into SAP – BDC, Call Transaction or reads data from SAP and writes it to a system file to be transferred to an external computer system e.g. a legacy mainframe – DATA EXTRACT c. Custom Transaction – a program similar to SAP transactions to fulfill some business function not provided by SAP – Dialog Programming.2. ABAP Development Workbench ToolsThe most important tools are: a. ABAP Editor for writing and editing program code. b. ABAP Dictionary for editing tables and other ABAP Dictionary Objects. c. Menu Painter for designing the user interface (menu bar, standard toolbar, application toolbar) d. Screen Painter for designing screens for user dialogs e. Function Builder for programming function modules (subroutines with a fixed interface that are available system wide)All development objects created with the development tools found in the ABAP Workbench areclassified as Repository Objects and are stored centrally in the R/3 Repository.The R/3 Repository is a special part of the SAP system’s central database. The Repository isorganized according to application. Each application is further divided into logical subdivisionscalled development classes.Repository objects are often made up of sub-objects that are themselves Repository objects.Each Repository object must be assigned a development class when it is created.ABAP Programming SyntaxWhichever type of program, ABAP syntax includes the following: • ABAP programs are made up of individual statements • Each statement ends with a period. • The first word in a statement is called a key word. • Words must always be separated by at least one space. • Statements can be indented. • Statements can take up more than one lineNaming StandardsThe company you work for is a customer of SAP. Therefore, programs that you create at yourcompany are called customer programs. For programs, the customer name range is two to fortycharacters long and the program name must start with the letter Y or Z. SAP reserves the lettersA through X for their own programs.2.1 Object NavigatorThe object navigator is also called in previous releases Object Browser (Rel 3x), RepositoryBrowser (Rel 4.x)Object Navigator automatically calls other tools when actions require them. For example, creatinga new program from the Object Navigator screen. The Object Navigator calls the ABAP Editorand, after creating the program, returns back to the Object Navigator screen.An entire application can be created using the Object Navigator without directly calling any of theother tools. In fact, the recommended method for creating an application is from the Object
  9. 9. www.LearnSAP.comNavigator because you can see what you build. The Object navigator provides an overview of allthe elements in an application and access to all necessary administration tools from one singleinterface.
  10. 10. www.LearnSAP.comObject Navigator can be accessed in 2 ways.Menu Path:SAP Main Screen > Tools > ABAP Workbench > Overview > Object Navigator (Double Click)Another way to reach the Object Navigator is to from the SAP Main Screen enter the transactionSE80 into the transaction field and press EnterEither way the Object Navigator is displayed. There are two input fields on this screen.Object List Group – This contains a list of the objects contained within this environment: LocalObjects, Application Hierarchy Program, Development Class, Function Group, Class/Interface,Internet Service. Select Local Objects in this field.
  11. 11. www.LearnSAP.comIf you select the down-arrow key in the second input field, object group selected in the first fieldwill be displayed. Click on the Display input field.Exercise A211 – Create an ABAP program using the object navigator 1. Start the object navigator by typing se80 in the command field from the SAP Main screen. 2. Select Programs in the first input field. 3. Type in the desired name of the new program, e.g. ZKKPROG1 in the second input field. Click on display button. NOTE: All third-party program names can only begin with Y or Z. This way customer program can clearly be distinguished from SAP programs.If the program already exists, it will be display under the object list. If it doesn’t exist, a dialog boxpops open, click the YES pushbutton for SAP to create the program.
  12. 12. www.LearnSAP.comAs soon as you click on YES another dialog box pops open querying about the program structureeither as an individual file or a framework program for includes. Large programs can be split upinto several sub programs (includes).For now deselect the “With TOP INCL” flag. Click on Enter to continueIf this is the first time ever you are creating an ABAP program, another dialog window will popopen requesting you to enter the Access Key so this user can be added as a Developer. Enteryour 20 Character access key here and click on continue. ( Note: this dialog only pops up once. ) Deliberately Hidden Field
  13. 13. www.LearnSAP.comA new template pops up where you will define the important attributes of the new application.There are three important fields that must be maintained. And these are;Title: Short description of the program. The program name comes up as default in this field. Youcan add more text to it. For example Khans First ABAP ProgramProgram Type: Chose Executable program. Reports are usually this type.Application: Which the program will be assigned to. Select Cross-application.Other fields are optional: status, authorization groups, logical database. After entering all thevalues, click on SAVE.When you save a new object for the first time, the system displays a correction and transportdialog box. Here the Development Class field needs to be maintained. See section 2.2.5 andsection 2.2.4 on Workbench. For now click the local object pushbutton.
  14. 14. www.LearnSAP.comYou will be returned to the opening screen of the object navigator. Go to the course code screenby double clicking on the object name.Source code appears in display mode with just one line of code “report” and “report name”. Toswitch from display mode to change mode click on the pencil markPlace cursor after the period at the end of first sentence and press enter to get you to the nextline. Type WRITE ‘Hello World!’.
  15. 15. www.LearnSAP.comActivate the program by going to Programs > ActivateOr click on the magic wand which is a shortcut for activate.A message “Object Activated” appears at the bottom of the screen.Press F8 or to test the program
  16. 16. www.LearnSAP.comA list is produced. To go back to the editor from the report output window, click on the back arrowor F3 function key.2.2 ABAP EditorThe ABAP Editor is a tool that you use to write ABAP programs, class methods, functionmodules, screen flow logic, type groups and logical databases.ABAP Editor can be accessed in two ways.Menu Path:SAP Main Screen > Tools > ABAP Workbench > Development > ABAP Editor (Double Click)Or simply use transaction code SE38 to start ABAP Editor
  17. 17. www.LearnSAP.comABAP/4 programs consist of five components 1. Source Code 2. Attributes 3. Text Elements 4. Documentation 5. VariantsOnly the source code and program attributes components are required. The rest of thecomponents are optional, they will be looked at in another section.All development objects and their components are stored in the R/3 Database. ABAP/4 programsare interpreted; they are not compiled. The first time you execute a program, the systemautomatically generates a runtime object. The runtime object is a pre-processed for of the sourcecode. However, it is not an executable that you can run at the operating system level. Instead, itrequires the R/3 system to interpret it. The runtime object is also known as the generated form ofthe program. If you change the source code, the runtime object is automatically regenerated thetime you execute the program.2.2.1 Editor ModeThe ABAP Editor has two different modes: 1. Front-end Editor 2. Back-end EditorFront-end EditorThe front-end editor uses the SAP Textedit Control from the SAP Control Framework. It loadsyour source code onto the front-end and allows you to perform many tasks without anycommunication with the application server.In the front-end editor, the ABAP source code is loaded onto the front-end and edited locally. Theadvantage of this is that all editing functions that do not require communication with the backendcan be performed very quickly.Back-end EditorThe back-end editor allows you to use the traditional back-end editor for editing your ABAP code.The editor is line-based, and to use normal editor functions such as cut, copy and paste, youmust first select a block of lines. If is often useful to use the clipboards in this mode. If you have avery long program (and specially if you are working in a WAN environment), the back-end editorcan produce better performance than the front-end editor. Furthermore, back-end editor allowsyou to edit any development object that is based on the ABAP Editor.You can change the mode from front-end to back-end by doing the following steps. To changethe editor mode from anywhere in the ABAP workbench: Chose utilities > settings.
  18. 18. www.LearnSAP.comThe User Specific Settings dialog box appears. Choose ABAP Editor. Set the editor mode toback-end editor.2.2.2 Uploading and Downloading Source CodeTo upload a file into the ABAP Editor 1. Chose utilities from the ABAP Editor screen 2. Click more utilities 3. Click on Upload/download 4. Click Upload
  19. 19. www.LearnSAP.com 5. Enter the path and filename of the file you want to read in the dialog box, then choose copy.2.2.3 ABAP/4 Attributes ScreenThe following section provides information about program attributes. Note that some of theseattributes only apply to executable programs (reports), and not to other ABAP program types.VersionThese fields are used for version administration. The system fills them.TitleIn the required entry field “TITLE” enter a program description that describes the function of theprogram. Thus, you can edit the title when maintaining the text elements.Maintenance LanguageThe maintenance language is the logon language of the user who creates the program. Thesystem fills this field automatically. You can change the maintenance language. If you maintainthe program or its components in another logon language.TypeIn the Type Field you must specify the execution mode of your program. Use Type 1 (report) to declare your program as executable. This means that program can run on its own, and that you can start it in the R/3 system without a transaction code. You can also run executable programs (reports) in the background. Use Type M to declare your program as a module pool. This means that your program cannot run on its own, but serves as a frame for program modules used for dialog programming. User Type I for include program. An include program is an independent program with two main functions: On one hand, it contains program code that can be used by different programs. On the other hand, it modularizes source code, which consists of several
  20. 20. www.LearnSAP.com different, logically related parts. Each of these part is stored in different include program. Include programs make your source code easier to read and maintain.StatusThis entry describes the status of the program development, for example, T for test program.ApplicationThis field contains the short form of your application, for example, F for Financial accounting. Thisrequired entry enables the system to allocate the program to the correct business area.Authorization GroupIn this field, you can enter the name of a program group. This allows you to group differentprograms together for authorization checks. The group name is a field of the two authorizationobjects S_DEVELOP (program development and program execution) and S_PROGRAM(program maintenance). Thus you can assign authorization to users according to programgroups. For more information about creating function modules, refer to the Users andAuthorization documentation.Development ClassThe development class is important for transports between systems. You combine all Workbenchobjects assigned to one development class in one transportation request. If you are working in ateam you may have to assign your program to an existing development class, or you may be freeto create a new class – section 2.3.1 on Workbench Organizer covers this. All programs assignedto the development class $TMP are private objects and cannot be transported into other systems.You can enter the development class directly into this field. Otherwise, the system prompts for itwhen you save the attributes.Choosing Local Objects is equivalent to entering $TMP in the field Development Class. You canchange the development class of a program later on by choosing Object Directory Entry from theGOTO menu, click change, type in the desired development class.Logical Database From Application(Only for Executable Programs – Reports)These attributes determine the logical database used by the executable program (report) to readdata, and the application to which it belongs. Logical databases have unique names within theirapplication. However, system wide, you can have more than one logical database with the samename. This is why you also need to specify the application. If you read data directly in yourprogram instead of using a logical database, you should enter an application, but leave the logicaldatabase field empty.Selection Screen Version(Only for Executable Programs – Reports)If you do not specify a selection screen version, the system automatically creates a selectionscreen based on the selection criteria of the logical database and the parameters and select –options statement in the program.If you want to use a different selection screen, enter the number here (not 1000, since this isreserved for the standard selection screen). The number must be smaller than 1000 andcorrespond to an additional selection screen of the logical database. The possible values helpdisplays a list of available selection screens. You can also look in the selection include of thelogical database (Program DBxxxSEL, where xxx is the name of the logical database).