Sie sind auf Seite 1von 114

ABAP Reports

June 25, 2013 1

Agenda
ABAP Runtime Environment Data types and Data objects Creating & executing an ABAP Program Statements List Output Selection -Screen

Database access

June 25, 2013 2

Agenda
Events and Flow Control Interactive Lists Passing Data Between Programs Macros Debugging

June 25, 2013 3

ABAP Runtime Environment

June 25, 2013 4

Components

June 25, 2013 5

Structure

June 25, 2013 6

General Program Execution

June 25, 2013 7

Non-Executable Programs

June 25, 2013 8

Data Types and Data Objects

June 25, 2013 9

Data Types

June 25, 2013 10

Data types
Data types are pure descriptions.

They do not occupy memory.


They describe the technical attributes of data objects. The data type is an attribute of a data object and is closely connected with it.

June 25, 2013 11

Data Types

June 25, 2013 12

Data types Predefined Elementary

June 25, 2013 13

Data types User Defined

June 25, 2013 14

Data types Example Elementary Types

June 25, 2013 15

Data types Example Structured Types

June 25, 2013 16

Table Types in Program

June 25, 2013 17

Declaring Fields and Structure

June 25, 2013 18

Declaring Internal Tables

June 25, 2013 19

Selection Screen Fields

June 25, 2013 20

Constants and Literals

June 25, 2013 21

Data types
Type Groups
define standalone types in the ABAP Dictionary.

are based on the include technique, and allows to store any type definitions globally in the Dictionary.
are defined as ABAP code.
The first statement for the type group <pool> is always:
TYPE-POOL <pool>.

must be declared in an ABAP program, as follows, before it can be used:


TYPE-POOLS <pool>.
This statement allows use of all the data types and constants defined in the type group <pool> in the program.

June 25, 2013 22

Data types: Type groups


Example :

The type group HKTST is created as follows in the ABAP Dictionary:


TYPE-POOL hktst. TYPES: BEGIN OF hktst_typ1, col1(10) TYPE c, col2 TYPE i, END OF hktst_typ1. TYPES hktst_typ2 TYPE p DECIMALS 2. CONSTANTS hktst_eleven TYPE i VALUE 11.

This type group defines


- two data types
HKTST_TYP1 HKTST_TYP2

- a constant
HKTST_ELEVEN with the value 11

June 25, 2013 23

Data types: Type groups


Any ABAP program can use this definition by including a TYPE-POOLS statement: TYPE-POOLS hktst. DATA: dat1 TYPE hktst_typ1, dat2 TYPE hktst_typ2 VALUE '1.23'. WRITE: dat2, / hktst_eleven. The output is: -1,23 -11 The data types defined in the type group are used to declare data objects with the DATA statement and the value of the constant is, available in the program. Several type groups can be used in the same program.

June 25, 2013 24

Data objects
Data objects are the physical units a program uses at runtime. Each data object has a specific data type assigned to it. Each data object occupies some space in memory.

ABAP processes a data object according to its data type.

June 25, 2013 25

Data objects
Internal data objects:- Created within a program.
Literals Variables Constants

External data objects:- Exist independently of programs.


TABLES statement

June 25, 2013 26

Data objects
System-defined data objects:- Defined automatically by the system.
SPACE System fields

Special data objects:- Data objects with special features.


PARAMETERS SELECT-OPTIONS

June 25, 2013 27

Field Symbols

June 25, 2013 28

Field Symbols - Reference

June 25, 2013 29

Field Symbols Dynamic Type Casting

June 25, 2013 30

Declaring Data Objects Dynamically

June 25, 2013 31

Creating And Executing ABAP Programs

June 25, 2013 32

Creating & executing an ABAP Program


Start the ABAP Editor. (Transaction -> SE38) Enter a program name and choose Create. The name of an ABAP program can be between 1 and 30 characters long. It cannot contain any of the following characters: Period (.), comma (,), space ( ), parentheses (), apostrophe (), inverted commas ("), equals sign (=), asterisk (*),etc.

June 25, 2013 33

Creating & executing an ABAP Program


Enter the program attributes applicable to reports.
Title Type = Executable Program Application = Cross-Application

Choose Save.

Enter the development class.


$TMP for local objects.

Choose Save.

June 25, 2013 34

Creating & executing an ABAP Program


Save & activate the program.
-- Program Activate

Generate the program. -- Program Generate.

When the program is generated, the system creates a runtime object for it.
Execute the program. -- Program Execute.

June 25, 2013 35

Activating a Program
When a program is activated, the system generates an active version from the inactive version.

The activation process checks for syntax errors in the program, then generates the active version. Finally, it generates a load version and deletes the corresponding entry from your list of inactive objects.

June 25, 2013 36

Generating & Executing a Program


Generating a Program
When you generate a program, the system creates a new load version from the active version. Unlike activation, this operation only generates a new load version.

Executing a Program
Users can run executable programs either in the foreground, by entering the program name in Transaction SA38 (System Services Reporting), or as a background job.

June 25, 2013 37

Standardize the layout of code

Pretty Printer can be used to standardize the layout of a

program to one of the following display variants:


Entire program in uppercase letters Entire program in lowercase letters

ABAP keywords in uppercase

June 25, 2013 38

ABAP STATEMENTS

June 25, 2013 39

ABAP Language structure


Several ABAP statements. Statement begins with a keyword & ends with a period.
E.g.:-

REPORT ZTEST01.

WRITE 'First Program'.

June 25, 2013 40

Keywords
Declarative keywords

TYPES, DATA, TABLES


Modularization keywords Event keywords:

INITIALIZATION AT SELECTION SCREEN START-OF-SELECTION END-OF-SELECTION AT USER-COMMAND

June 25, 2013 41

Keywords
Defining keywords:
FORM .. ENDFORM FUNCTION .. ENDFUNCTION MODULE .. ENDMODULE

Control keywords
IF, WHILE, CASE

Calling keywords
PERFORM, CALL, SUBMIT, LEAVE TO

Operational keywords
WRITE, MOVE, ADD

June 25, 2013 42

Chain statements
Chain statements:
WRITE SPFLI-CITYFROM. WRITE SPFLI-CITYTO. WRITE SPFLI-AIRPTO.

can be written as
WRITE: SPFLI-CITYFROM, SPFLI-CITYTO, SPFLI-AIRPTO.

June 25, 2013 43

Comments
Two ways to indicate comments:
Entire line to be commented
* at the beginning * WRITE 'First Program'.

Part of a line to be commented

before the comment


WRITE 'First Program'. " Output on List

June 25, 2013 44

WRITE Statement
The basic ABAP statement for outputting data on the

screen.
WRITE <f>.

To position the output of a WRITE statement


WRITE AT [/][<pos>][(<len>)] <f>.

Various formatting options with the WRITE statement.


WRITE.... <f> <option>.

June 25, 2013 45

Initializing

June 25, 2013 46

Assigning Values

June 25, 2013 47

Compatibility

June 25, 2013 48

String Processing

June 25, 2013 49

Searching In a String

June 25, 2013 50

Changing Strings

June 25, 2013 51

Splitting and Joining

June 25, 2013 52

Accessing Parts of Fields

June 25, 2013 53

Calculations- Syntax

June 25, 2013 54

Calculations Integer , Packed Number

June 25, 2013 55

Calculations Floating Point Numbers and Run Time error

June 25, 2013 56

Calculations Date Field

June 25, 2013 57

Logical Expressions

June 25, 2013 58

Comparing Strings

June 25, 2013 59

Conditional Branching

June 25, 2013 60

Loops

June 25, 2013 61

Leaving Processing Blocks

June 25, 2013 62

Catching Runtime Errors

June 25, 2013 63

Example Catching Errors

June 25, 2013 64

List Output

June 25, 2013 65

List

June 25, 2013 66

Generating A List

June 25, 2013 67

Setting The Size

June 25, 2013 68

Page and Column Heading

June 25, 2013 69

Line and Field Formats

June 25, 2013 70

WRITE Statement

June 25, 2013 71

Outputting Icons etc

June 25, 2013 72

Scrolling

June 25, 2013 73

Additional Statements

June 25, 2013 74

Multi Lingual

June 25, 2013 75

System Fields

June 25, 2013 76

Exercise

June 25, 2013 77

Selection - Screen

June 25, 2013 78

Selection Screen

June 25, 2013 79

Overview

June 25, 2013 80

PARAMETERS

June 25, 2013 81

SELECT-OPTIONS

June 25, 2013 82

Multiple Selections

June 25, 2013 83

SELECT-OPTIONS Syntax

June 25, 2013 84

Designing The Selection Screen 1

June 25, 2013 85

Designing The Selection Screen 2

June 25, 2013 86

Initializing Selection Screen

June 25, 2013 87

Input checks

June 25, 2013 88

User Defined Selection Screens

June 25, 2013 89

Variants

June 25, 2013 90

Exercise

June 25, 2013 91

Database Access

June 25, 2013 92

SELECT Statement

June 25, 2013 93

Process

June 25, 2013 94

Selecting Single Record

June 25, 2013 95

Selecting Multiple Records

June 25, 2013 96

Array Fetch

June 25, 2013 97

INTO Clause

June 25, 2013 98

INTO-Corresponding

June 25, 2013 99

Reading data from database tables Aggregrate Expression


MAX (<a>): returns the maximum value of the column <a> MIN (<a>): returns the minimum value of the column <a> AVG (<a>): returns the average value of the column <a> SUM (<a>): returns the sum value of the column <a> COUNT : COUNT( DISTINCT <a>) returns the number of distinct values for the column <a>.

COUNT( *) returns the total number of lines in the selection.

June 25, 2013 100

Database Updates

June 25, 2013 101

Open SQL Portability and Buffering

June 25, 2013 102

Open SQL CLIENT field

June 25, 2013 103

Creating Single Record

June 25, 2013 104

Creating A Set Of Records

June 25, 2013 105

Changing Single record

June 25, 2013 106

Changing Record Sets Via Conditions

June 25, 2013 107

Changing Record Sets Via Internal Tables

June 25, 2013 108

Modifying Single Record

June 25, 2013 109

Deleting A Single Record

June 25, 2013 110

Deleting Record Sets Using Condition

June 25, 2013 111

Deleting Records Via Internal Tables

June 25, 2013 112

Database Roll Back

June 25, 2013 113

Exercise

June 25, 2013 114

Das könnte Ihnen auch gefallen