20
www.LearnSAP.com SAP R/3 ABAP/4 Training Manual 5101 Camden Lane, Pearland, TX 77584

Sap r3 Abap4

Embed Size (px)

Citation preview

Page 1: Sap r3 Abap4

www.LearnSAP.com

SAP R/3 ABAP/4 Training Manual

5101 Camden Lane, Pearland, TX 77584

Page 2: Sap r3 Abap4

www.LearnSAP.com

Course Outline Section – A 1. Introduction to ABAP

1.1. What is SAP R/3 1.2. SAP R/3 architecture and where ABAP fits in

2. ABAP Development Workbench Tools

2.1. Object Navigator 2.2. Workbench Organizer 2.3. Data Dictionary 2.4. Menu Painter 2.5. Screen Painter

Section – B 3. Reports Statement

3.1. Line Size 3.2. Line-count 3.3. Message 3.4. Page Heading 3.5. Report Comment Section

4. Declarations

4.1. Tables 4.2. Includes 4.3. Variables (Data Types and Data Objects) 4.4. Structures 4.5. Internal Tables 4.6. Constants

5. Selection Screen / Input Fields

5.1. Parameters 5.2. Select – Options 5.3. Section Screen Formatting

6. 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 – Command

7. 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 Operations

8. 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

Page 3: Sap r3 Abap4

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 Reports

9. Formatting and Displaying Data

9.1. Event for Page Headers and Footers 9.2. Display Options

Section – C 10. Types of Program Analysis

10.1. Static Checks 10.2. Dynamic Checks and Short Dump Analysis

11. Debugger

11.1. Breakpoints in Programs 11.2. Breakpoints in the Debugger 11.3. Watchpoints

12. Performance Tools

12.1. Runtime Errors 12.2. SQL Trace

Section – D 13. 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 program

14. Data Transfer Methods

14.1. Understand the Transaction 14.2. Standard data transfer program 14.3. DBC program 14.4. Call transaction Program

Section – E 15. Dialog Application

15.1. Create a Module Pool 15.2. Create a Transaction

16. 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-CODE

17. Menu Painter

17.1. Create GUI Status 17.2. Create a Menu Bar for a Screen

Page 4: Sap r3 Abap4

www.LearnSAP.com

17.3. Define function Keys 17.4. Create Application Tool Bar for a Screen 17.5. Create window titles

18. 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 transaction

Section – F 19. 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.

Page 5: Sap r3 Abap4

www.LearnSAP.com

Section – A ABAP Workbench Overview

Objectives • 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 – A

1. 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/4

2. 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.

Page 6: Sap r3 Abap4

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 domains

3.0 Project A

Page 7: Sap r3 Abap4

www.LearnSAP.com

1. Introduction to ABAP 1.1 What is SAP R/3? SAP stands for Systems, Applications and Products in Data Processing. It is the name of the company and also the name of the software. R/3 stands for Runtime System Three. It is one of the ERP (Enterprise Resource Planning) systems around. Similar products are Oracle and Peoplesoft. ERP is used by companies to plan, organize, integrate and manage their various operations like accounting, finance, manufacturing and human resources. The main aim is to improve efficiency and accuracy. 1.2 SAP R/3 Architecture and

Where ABAP fits in R/3 is based on client/server architecture and uses a relational database to track all information related to a company. It is made up of small programs called transactions. A transaction is a program and set of system; and change functionality in the R/3 system. R/3 gathers related transactions together into groups and call them modules. Thus a module is a set of transactions that deal with the same area of business functionality. R/3 modeled in a three-tier hierarchy is shown below.

Presentation level – User Interface Application level – business logic layer that runs on a server Database level – stores data managed by SAP ABAP (Advanced Business Application Programming) is the programming language used by SAP developers to build transactions that make up the R/3 application. Its also used by companies to customize the R/3 application i.e. providing additional business functionality. It is a fourth-generation programming language with some features similar to some modern programming languages such as C, Visual Basic and Power Builder. It allows variables to be defined, modulation of programs via subroutines and function calls, access to the database via open 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

Page 8: Sap r3 Abap4

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 Tools The 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 are classified 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 is organized according to application. Each application is further divided into logical subdivisions called 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 Syntax Whichever 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 line

Naming Standards The company you work for is a customer of SAP. Therefore, programs that you create at your company are called customer programs. For programs, the customer name range is two to forty characters long and the program name must start with the letter Y or Z. SAP reserves the letters A through X for their own programs. 2.1 Object Navigator The object navigator is also called in previous releases Object Browser (Rel 3x), Repository Browser (Rel 4.x) Object Navigator automatically calls other tools when actions require them. For example, creating a new program from the Object Navigator screen. The Object Navigator calls the ABAP Editor and, 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 the other tools. In fact, the recommended method for creating an application is from the Object

Page 9: Sap r3 Abap4

www.LearnSAP.com

Navigator because you can see what you build. The Object navigator provides an overview of all the elements in an application and access to all necessary administration tools from one single interface.

Page 10: Sap r3 Abap4

www.LearnSAP.com

Object 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 transaction SE80 into the transaction field and press Enter

Either 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: Local Objects, Application Hierarchy Program, Development Class, Function Group, Class/Interface, Internet Service. Select Local Objects in this field.

Page 11: Sap r3 Abap4

www.LearnSAP.com

If you select the down-arrow key in the second input field, object group selected in the first field will 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 box pops open, click the YES pushbutton for SAP to create the program.

Page 12: Sap r3 Abap4

www.LearnSAP.com

As soon as you click on YES another dialog box pops open querying about the program structure either as an individual file or a framework program for includes. Large programs can be split up into several sub programs (includes).

For now deselect the “With TOP INCL” flag. Click on Enter to continue

If this is the first time ever you are creating an ABAP program, another dialog window will pop open requesting you to enter the Access Key so this user can be added as a Developer. Enter your 20 Character access key here and click on continue. ( Note: this dialog only pops up once. )

Deliberately Hidden Field

Page 13: Sap r3 Abap4

www.LearnSAP.com

A 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. You can add more text to it. For example Khans First ABAP Program Program 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 the

values, click on SAVE.

When you save a new object for the first time, the system displays a correction and transport dialog box. Here the Development Class field needs to be maintained. See section 2.2.5 and section 2.2.4 on Workbench. For now click the local object pushbutton.

Page 14: Sap r3 Abap4

www.LearnSAP.com

You will be returned to the opening screen of the object navigator. Go to the course code screen by double clicking on the object name.

Source code appears in display mode with just one line of code “report” and “report name”. To

switch from display mode to change mode click on the pencil mark

Place cursor after the period at the end of first sentence and press enter to get you to the next line. Type WRITE ‘Hello World!’.

Page 15: Sap r3 Abap4

www.LearnSAP.com

Activate the program by going to Programs > Activate

Or 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

Page 16: Sap r3 Abap4

www.LearnSAP.com

A list is produced. To go back to the editor from the report output window, click on the back arrow or F3 function key.

2.2 ABAP Editor The ABAP Editor is a tool that you use to write ABAP programs, class methods, function modules, 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

Page 17: Sap r3 Abap4

www.LearnSAP.com

ABAP/4 programs consist of five components

1. Source Code 2. Attributes 3. Text Elements 4. Documentation 5. Variants

Only the source code and program attributes components are required. The rest of the components 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 programs are interpreted; they are not compiled. The first time you execute a program, the system automatically generates a runtime object. The runtime object is a pre-processed for of the source code. However, it is not an executable that you can run at the operating system level. Instead, it requires the R/3 system to interpret it. The runtime object is also known as the generated form of the program. If you change the source code, the runtime object is automatically regenerated the time you execute the program. 2.2.1 Editor Mode The ABAP Editor has two different modes:

1. Front-end Editor 2. Back-end Editor

Front-end Editor The front-end editor uses the SAP Textedit Control from the SAP Control Framework. It loads your source code onto the front-end and allows you to perform many tasks without any communication with the application server. In the front-end editor, the ABAP source code is loaded onto the front-end and edited locally. The advantage of this is that all editing functions that do not require communication with the backend can be performed very quickly. Back-end Editor The 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, you must first select a block of lines. If is often useful to use the clipboards in this mode. If you have a very long program (and specially if you are working in a WAN environment), the back-end editor can produce better performance than the front-end editor. Furthermore, back-end editor allows you 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 change the editor mode from anywhere in the ABAP workbench: Chose utilities > settings.

Page 18: Sap r3 Abap4

www.LearnSAP.com

The User Specific Settings dialog box appears. Choose ABAP Editor. Set the editor mode to back-end editor.

2.2.2 Uploading and Downloading Source Code To 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

Page 19: Sap r3 Abap4

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 Screen The following section provides information about program attributes. Note that some of these attributes only apply to executable programs (reports), and not to other ABAP program types. Version These fields are used for version administration. The system fills them. Title In the required entry field “TITLE” enter a program description that describes the function of the program. Thus, you can edit the title when maintaining the text elements. Maintenance Language The maintenance language is the logon language of the user who creates the program. The system fills this field automatically. You can change the maintenance language. If you maintain the program or its components in another logon language. Type In 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

Page 20: Sap r3 Abap4

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.

Status This entry describes the status of the program development, for example, T for test program. Application This field contains the short form of your application, for example, F for Financial accounting. This required entry enables the system to allocate the program to the correct business area. Authorization Group In this field, you can enter the name of a program group. This allows you to group different programs together for authorization checks. The group name is a field of the two authorization objects S_DEVELOP (program development and program execution) and S_PROGRAM (program maintenance). Thus you can assign authorization to users according to program groups. For more information about creating function modules, refer to the Users and Authorization documentation. Development Class The development class is important for transports between systems. You combine all Workbench objects assigned to one development class in one transportation request. If you are working in a team you may have to assign your program to an existing development class, or you may be free to create a new class – section 2.3.1 on Workbench Organizer covers this. All programs assigned to 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 it when you save the attributes. Choosing Local Objects is equivalent to entering $TMP in the field Development Class. You can change the development class of a program later on by choosing Object Directory Entry from the GOTO 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 read data, and the application to which it belongs. Logical databases have unique names within their application. However, system wide, you can have more than one logical database with the same name. This is why you also need to specify the application. If you read data directly in your program instead of using a logical database, you should enter an application, but leave the logical database field empty. Selection Screen Version (Only for Executable Programs – Reports) If you do not specify a selection screen version, the system automatically creates a selection screen 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 is reserved for the standard selection screen). The number must be smaller than 1000 and correspond to an additional selection screen of the logical database. The possible values help displays a list of available selection screens. You can also look in the selection include of the logical database (Program DBxxxSEL, where xxx is the name of the logical database).