• No results found

bc401-P-1-50

N/A
N/A
Protected

Academic year: 2021

Share "bc401-P-1-50"

Copied!
50
0
0

Loading.... (view fulltext now)

Full text

(1)

BC401 ABAP Objects

BC401

(2)

BC401 ABAP Objects...1 Copyright...2 Course Prerequisites...4 Target Group...5 Course Overview...1 Course Goal...2 Course Objectives...3 Course Content (1)...4 Course Content (2)...5

Course Overview: Integration in Course Content...6

Main Business Scenario...7

Technical Names...8

Data Types and Data Objects in Detail...1

Data Types and Data Objects in Detail: Unit Objectives...2

Data Types and Data Objects in Detail: Integration in Course Content...3

Data Types and Data Objects in Detail (1)...4

Revision: Defining Data Objects...5

Predefined ABAP Types...6

Type Groups in the ABAP Dictionary...7

Data Types and Data Objects in Detail (2)...8

Integers and Integer Arithmetic...9

Packed Numbers and Fixed Point Arithmetic...10

Floating Point Arithmetic...11

Summary: Recommendations for Using Numeric Data Types...12

Arithmetic and Mixed Expressions...13

Predefined ABAP Types for Character Strings...14

Overview: Character String Processing...15

Accessing Parts of Fields...16

Data Types and Data Objects in Detail (3)...17

Defining Structures with Local Types...18

Defining Nested Structures with Local Types...19

Using Named Includes...20

Data Types and Data Objects in Detail (4)...21

Unicode: Overview...22

Character-Type and Byte-Type Types...23

Functions and Comparison Operators...24

Compatibility and Conversion...25

Conversion Under Unicode (1)...26

(3)

Example of Using the Conversion Rules...28

Offset and Length Accesses and Elementary Data Objects...29

Offset and Length Accesses and Structures...30

Data Types and Data Objects in Detail: Summary...31

Data Types and Data Objects in Detail Exercise 1...32

Data Types and Data Objects in Detail Solution 1...34

Using Internal Tables...1

Using Internal Tables: Unit Objectives...2

Using Internal Tables: Integration in Course Content...3

Using Internal Tables (1)...4

The Internal Table - a Data Object of Variable Length...5

Attributes of Internal Tables...6

Link Between Table Kind and Access Type...7

Using Internal Tables (2)...8

Overview: Types of Definitions for Internal Tables...9

The Data Type of an Internal Table...10

Table Attribute: Line Type...11

Table Attribute: Table Kind and Key...12

Example: Standard Table with Local Type...13

Example: Sorted and Hashed Table...14

The Standard Table Type...15

Internal Tables with an Unstructured Line Type...16

Using Internal Tables (3)...17

Overview: Types of Operation...18

Limiting the Scope of Line Operations: Target Records and Access Type...19

Preview: Field SymboIs (1)...20

Preview: Field SymboIs (2)...21

Insert...22

Reading a Single Record into a Work Area Using the Line Number...23

Reading a Single Record into a Work Area Using the Field Contents...24

Reading a Single Record Using a Field Symbol...25

Changing the Table Using a Work Area...26

Changing a Single Record Using a Field Symbol...27

Delete...28

Loop Processing...29

Overview of Operations...30

Using Internal Tables (4)...31

Internal Tables with a Header Line...32

(4)

Using Internal Tables (5)...34

Single Record Access: Completely and Partially Qualified Key...35

Loop Processing and Table Kinds...36

Partial Sequential Loop Through Standard Tables...37

Access Using Field Symbols...38

Using Internal Tables: Unit Summary...40

Using Internal Tables Exercise 1...41

Using Internal Tables Solution 1...48

Calling Programs and Passing Data...1

Calling Programs and Passing Data: Unit Objectives...2

Calling Programs and Passing Data: Integration in Course Content...3

Calling Programs and Passing Data (1)...4

Calling Programs...5

Calling an Executable Program...6

Calling a Transaction...7

Calling Programs and Passing Data (2)...8

Logical Memory Model...9

Inserting a Program (1)...10

Inserting a Program (2)...11

Terminating the Inserted Program...12

Restarting an Executable Program (1)...13

Restarting an Executable Program (2)...14

Restarting a Transaction (1)...15

Restarting a Transaction (2)...16

Calling Programs and Passing Data (3)...17

Overview: Passing Data Between Programs...18

Passing Data Using the Program Interface...19

Preassigning Values for Input Fields...20

ABAP Memory and SAP Memory...21

Passing Data Using the ABAP Memory...22

Passing Parameters Using the SAP Memory...23

Preview: Passing Data Using an Internal Table...24

Fields of the Global Type bdcdata...26

Example: Passing Data Using an Internal Table...27

Calling Programs and Passing Data: Unit Summary...28

Introduction to Object-Oriented Programming...1

Introduction to Object-Oriented Programming: Unit Objectives...2

Introduction to Object-Oriented Programming: Integration in Course Content...3

(5)

Introduction: Programming Models (1)...5

Characteristics of Procedural Programming...6

Typical ABAP Program...7

ABAP Main Memory and Function Groups...8

Function Group Example...9

Use of Function Group...10

Several Instances of One Function Group...11

Instantiation and Object-Oriented Languages...12

Introduction: Programming Models (2)...13

Programming Models...14

Characteristics of the Object-Oriented Approach...15

Technical Implementation of the Object-Oriented Approach...16

Client/Server Behavior...17

Compatibility and Design Aims...18

ABAP Main Memory and Encapsulation...19

The Software Development Process...20

Introduction to Object-Oriented Programming: Summary...21

Analysis and Design...1

Analysis and Design: Unit Objectives...2

Analysis and Design: Integration in Course Content...3

Analysis and Design (1)...4

Classification of Objects...5

Different Abstractions of a Class...6

Representation of a Class...7

Classes and Objects...8

Analysis and Design (2)...9

Modeling with UML...10

Example of a Class Diagram...11

Association...12

Aggregation and Composition...13

Generalization and Specialization...14

Sequence Diagrams: Example...15

Sequence Diagram: Delegation...16

Analysis and Design: Summary...17

Analysis and Design Exercises...18

Analysis and Design Solutions...19

Principles of Object-Oriented Programming...1

Principles of Object-Oriented Programming: Unit Objectives...2

(6)

Principles (1)...4

Example of a Class...5

Defining Classes...6

Attributes...7

Attributes, Types, and Constants: Syntax...8

Attributes and Visibility...9

Accessing Private Attributes...10

Instance Attributes and Static Attributes (1)...11

Instance Attributes and Static Attributes (2)...12

Methods: Syntax...13

Accessing Private Methods...14

Methods and Visibility...15

Instance Methods and Static Methods...16

Instance Methods and Static Methods: Example...17

Summary and UML Notation...18

Principles (2)...19

Creating Objects...20

Reference Variables...21

Creating Objects: Syntax...22

Garbage Collector...23

Garbage Collector: Procedure...24

Buffering References...25

Aggregation Example...26

Principles (3)...27

Calling Methods...28

Calling Instance Methods: Syntax...29

Calling Static Methods: Syntax...30

Functional Methods...31

Functional Methods: Example...32

External Access to Public Attributes...33

Principles (4)...34

Constructor...35

Constructor: Example...36

Preview: Static Constructor...37

Principles (5)...38

Namespace Within a Class...39

The Reference Variable ME...40

Principles of Object-Oriented Programming: Unit Summary...41

(7)

Principles of Object-Oriented Programming Solutions...48

Inheritance...1

Inheritance: Unit Objectives...2

Inheritance: Integration in Course Content...3

Inheritance: UML Example...4

Multiple Inheritance?...5

Relationships Between Superclasses and Subclasses...6

Inheritance: Syntax...7

Redefining Methods...8

Inheritance and Redefining the Constructor...9

Rules for Calling the Constructor...10

Inheritance and Visibility...11

Visibility of Protected Components...12

Rules for Redefining Methods...13

Redefining Methods: Example...14

Inheritance: Unit Summary...15

Inheritance Exercises...16

Inheritance Solutions...18

Casting...1

Casting: Unit Objectives...2

Casting: Integration in Course Content...3

Casting (1)...4

Principle of Narrowing Cast...5

Compatibility and Narrowing Cast...6

Generic Access?...7

Preparations for Generic Access (1)...8

Preparations for Generic Access (2)...9

Polymorphism - Generic Access...10

Static and Dynamic Types of References...11

Comparison to Procedural Programming...12

Casting (2)...13

Use of Widening Cast...14

Widening Cast: Example...15

Casting (3)...16

Semantics and Use with Inheritance...17

Incorrect Use of Inheritance...18

Casting: Unit Summary...19

Casting Exercises...20

(8)

Interfaces...1

Interfaces: Unit Objectives...2

Interfaces: Integration in Course Content...3

Interfaces (1)...4

Interfaces: Use...5

Interfaces: Services...6

Interface: UML Example...7

Defining and Implementing an Interface...8

Interfaces: Features...9

Interfaces (2)...10

Working with Interface Components...11

Interface References: Narrowing Cast...12

Using the Interface...13

Polymorphism and Interfaces...14

Interface References: Widening Cast...15

Interfaces (3)...16

Compound Interfaces...17

Compound Interfaces: Example...18

Interfaces: Unit Summary...19

Interfaces Exercises...20

Interfaces Solutions...25

Events...1

Events: Unit Objectives...2

Events: Integration in Course Content...3

Events: Overview...4

Features...5

Triggering and Handling Events: Overview...6

Defining and Triggering Events: Syntax...7

Handling and Registering Events...8

Event Handler Methods...9

Registering for an Event: Syntax...10

Registration/Deregistration: Handler Tables...11

Event Handling: Features...12

Events: Unit Summary...13

Events Exercises...14

Solutions...16

Global Classes and Interfaces...1

Global Classes and Interfaces: Unit Objectives...2

(9)

Global Classes and Interfaces (1)...4

Review: Local Classes and Interfaces...5

Global Classes and Interfaces...6

Creating Global Classes in the Object Navigator...7

Class Builder: Attributes...8

Class Builder: Methods...9

Class Builder: Interface Methods...10

Class Builder: Method Interface...11

Class Builder: Method Implementation...12

Class Builder: Inheritance...13

Class Builder: Test Environment...14

Global Classes and Interfaces (2)...15

Global Classes in the Object Navigator...16

Class Builder: CREATE OBJECT...17

Class Builder: CALL METHOD...18

Global Classes and Interfaces (3)...19

SAP Grid Control...20

Including a Grid Control Instance in a Dialog Program...21

Displaying Data with a Grid Control Instance...22

Global Classes and Interfaces: Unit Summary...23

Exercises...24

Solutions...26

Special Techniques...1

Special Techniques: Unit Objectives...2

Special Techniques: Integration in Course Content...3

Special Techniques (1)...4

Abstract Classes...5

Final Classes...6

Special Techniques (2)...7

Who Can Instantiate Classes?...8

Special Techniques (3)...9

Friends...10

Special Techniques (4)...11

Persistence Service...12

Features of the Persistence Service...13

Class Agent...14

Special Techniques: Unit Summary...16

Exercises - optional...17

(10)

Exception Handling...1

Exception Handling: Unit Objectives...2

Exception Handling: Integration in Course Content...3

Class-Based Exceptions: Overview...4

Exception Classes: The Inheritance Hierarchy...5

Handling Exceptions...6

Example: Handling a Predefined Exception...7

Example: Using Your Own Exceptions...8

Creating Your Own Exception Classes...9

Maintaining Your Own Attributes and Exception Texts...10

Raising and Handling Exceptions You Have Written...11

Passing Exceptions Along...12

Example: Passing Exceptions Along...13

Exceptions That Must Be Declared...14

Exception Handling: Unit Summary...15

Exception Handling Exercise 1...16

Exception Handling Solution 1...18

Dynamic Programming...1

Dynamic Programming: Unit Objectives...2

Dynamic Programming: Integration in Course Content...3

Dynamic Programming (1)...4

Field Symbols...5

The CASTING Addition...7

Dynamic Programming (2)...9

Using Dynamic Attributes in Statements...10

Calling Methods Dynamically...11

Dynamic Programming (3)...12

Data Reference Variables...13

Example: Using Data Reference Variables in Dynamic Method Calls...14

Generating Data Objects at Runtime...15

Dereferencing Data References...16

Example: Generating Data Objects at Runtime...17

Dynamic Programming (4)...18

Ascertaining Internal Table Attributes...19

Dynamic Type Descriptions for RTTI Classes...20

Declaring Types Dynamically: Example...21

Dynamic Programming: Unit Summary...22

Exercise 1 – Optional...23

(11)

0

SAP AG 2002

BC401 ABAP Objects

BC401

BC401

ABAP Objects

ABAP Objects

System: SAP R/3

System requirements: SAP R/3, Basis Release 6.10 or later

2002/Q3

(12)

0.2

SAP AG 2002

Copyright 2002 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in

any form or for any purpose without the express permission of

SAP AG. The information contained herein may be changed

without prior notice.

Copyright

Notes on Trademarks:

Some software products marketed by SAP AG and its distributors contain proprietary software

components of other software vendors.

Microsoft

®

, WINDOWS

®

, NT

®

, EXCEL

®

, Word

®

, PowerPoint

®

, and SQL Server

®

are registered

trademarks of Microsoft Corporation.

IBM

®

, DB2

®

, OS/2

®

, DB2/6000

®

, Parallel Sysplex

®

, MVS/ESA

®

, RS/6000

®

, AIX

®

, S/390

®

, AS/400

®

,

OS/390

®,

and OS/400

®

are registered trademarks of IBM Corporation.

ORACLE

®

is a registered trademark of ORACLE Corporation.

INFORMIX

®

-OnLine for SAP and INFORMIX

®

Dynamic Server

TM

are registered trademarks

of Informix Software Incorporated.

UNIX

®

, X/Open

®

, OSF/1

®,

and Motif

®

are registered trademarks of the Open Group.

HTML, DHTML, XML, and XHTML are trademarks or registered trademarks of W3C

®

, World Wide

Web Consortium, Massachusetts Institute of Technology.

JAVA

®

is a registered trademark of Sun Microsystems, Inc.

JAVASCRIPT

®

is a registered trademark of Sun Microsystems, Inc., used under license for technology

developed and implemented by Netscape.

SAP, SAP Logo, R/2, RIVA, R/3, ABAP, SAP ArchiveLink, SAP Business Workflow, WebFlow, SAP

EarlyWatch, BAPI, SAPPHIRE, Management Cockpit, mySAP.com Logo, and mySAP.com are

trademarks or registered trademarks of SAP AG in Germany and several other countries all over the

(13)

world. All other products mentioned are trademarks or registered trademarks of their respective

companies.

(14)

0.3

SAP AG 2002

Course Prerequisites

Programming experience

SAPTEC

(mySAP Technology Solution Overview)

BC400

(ABAP Workbench: Foundations and Concepts)

Programming experience in ABAP

(15)

0.4

SAP AG 2002

Participants: Developers, consultants

Duration: 5 days

Target Group

Notes to the user

The training materials are not appropriate for self-study. They complement the course instructor's

explanations. There is space for you to write down additional information on the sheets.

There may not be enough time during the course to complete all the exercises. The exercises are

intended as additional examples of the topics discussed during the course. Participants can also use them

as an aid to enhancing their knowledge after the course has finished.

(16)
(17)

1

SAP AG 2002

Course goal

Course objectives

Course content

Course overview diagram

Main business scenario

Contents:

Course Overview

(18)

1.2

SAP AG 2002

This course will enable you to:

Learn the principles of object-oriented

programming

Learn the structure and application of

ABAP Objects

Course Goal

(19)

1.3

SAP AG 2002

At the conclusion of this course, you will be able to:

Describe and use the most important principles:

Internal tables

Classes/inheritance/interfaces

Polymorphism, inheritance, and interfaces

Events

Exception handling

Dynamic programming

Develop programs in ABAP Objects

Course Objectives

(20)

1.4

SAP AG 2002

Unit 1

Course Overview

Unit 2

Data Types and Data Objects in Detail

Unit 3

Using Internal Tables

Unit 4

Calling Programs and Passing Data

Unit 5

Introduction to Object-Oriented Programming

Unit 6

Analysis and Design

Unit 7

Principles of Object-Oriented Programming

Unit 8

Inheritance

Unit 9

Casting

Unit 10

Interfaces

Preface

Course Content (1)

(C) SAP AG BC401 4

(21)

1.5

SAP AG 2002

Unit 11

Events

Unit 12

Global Classes and Interfaces

Unit 13

Special Techniques

Unit 14

Exception Handling

Unit 15

Dynamic Programming

Appendix

Course Content (2)

(22)

1.6

SAP AG 2002

Course Overview: Integration in Course Content

Course Overview

Course Overview

(23)

1.7

SAP AG 2002

A travel agent maintains its connections to

business partners - such as airlines, car hire

companies, and hotels

Main Business Scenario

(24)

1.8

SAP AG 2002

Technical Names

Package: BC401

Naming conventions for program objects:

Demonstrations:

SAPBC401_xxxD_...

Copy templates:

SAPBC401_xxxT_...

Model solutions:

SAPBC401_xxxS_...

xxx is the individual unit code

Unit codes:

Unit 2:

DTO

Unit 3:

TAB

Unit 4:

CAL

Unit 7:

AIR

Unit 8:

INH

Unit 9:

CAS

Unit 10: INT

Unit 11: EVE

Unit 12: CLS

Unit 13: SPC

Unit 14: EXC

Unit 15: DYN

(C) SAP AG BC401 8

(25)

2

SAP AG 2002

Data objects in programs

Elementary data objects

Structures

Character string processing in Unicode

Contents:

Data Types and Data Objects in Detail

(26)

2.2

SAP AG 2002

Use elementary data objects and structures

appropriately

Use numeric data types appropriately

Use automatic type conversions appropriately

Take the special features of character string

processing in Unicode into account

At the conclusion of this unit, you will be able to:

Data Types and Data Objects in Detail: Unit Objectives

(27)

2.3

SAP AG 2002

Data Types and Data Objects in Detail:

Integration in Course Content

Data Types and Data Objects in

Detail

Data Types and Data Objects in

Detail Course Overview

(28)

2.4

SAP AG 2002

Special Features in Unicode

Special Features in Unicode

Elementary Data Objects

Elementary Data Objects

Structures

Structures

Data Types and Data Objects in Detail (1)

Introduction

Introduction

(29)

2.5

SAP AG 2002

Revision: Defining Data Objects

Predefined ABAP types x Local types i f string xstring t d Global types c n p TYPES type_name TYPE ...

DATA do_name TYPE type_name. DATA

DATA

DATA do_name_new LIKE do_name. DATA

DATA

Data objects are usually defined with the

DATA

statement as follows. After the name of the data object, a

a fully-specified type is assigned to it using the

TYPE

addition.

The type is linked to the data object

statically and cannot be changed at runtime.

There are other syntax variants available (for historical reasons).

Note however, that some of these

historical variants are no longer supported in ABAP Objects.

For further information, refer to the

keyword documentation for the

DATA

statement.

All types are based on predefined ABAP types, which will be discussed in greater detail in the following

slide.

Some of these ABAP types are fully specified and can be used to type data objects directly. Other

types need to be modified to include the length, and in some cases the number of decimal places so that

they are fully specified. These are the simplest examples of user-defined types.

You can create complex structured types of any level of complexity, based on elementary types.

You can also define types centrally in the ABAP Dictionary. You can then use these global types in all

appropriate Repository objects in the system.

(30)

2.6

SAP AG 2002

string

Predefined ABAP Types

p

i

f

n

c

d

t

x

xstring

Data type Numeric 4 8 1 .. 16 Integer

Float. point number Packed number

Character string type / hexadecimal

F

ix

e

d

l

e

n

g

th

Description Length in bytes

Number sequence Character sequence Date Time Hexadecimal code Character sequence Hexadecimal code 1 .. 65535 1 .. 65535 8 6 1 .. 65535 Differ in:

• Rules for storage • Value range • Arithmetic used

Bit operations

Character string type

Hexadecimal

Runtime system adjusts length dynamically

Character string operations (allowed for all types) + date calculations + time calculations Attributes

V

a

ri

a

b

le

le

n

g

th

The following ABAP types are fully specified and can be used directly to type data objects:

d

, t, i, f,

string, and xstring.

A special feature of the

string

and

xstring

types is that their length is

adjusted dynamically at runtime.

Thus, for these two types, length is not a component of the type.

The following ABAP types are not fully specified, so you must include additional information before

you use them to define data objects:

c, n,

and

x

Length needs to be added. Permitted values: 1 to 65535 characters.

If you do not declare a length when you define a data object, the system assigns the default length of

1.

p

You must extend the type to include the length, and number of decimal places, Permitted length: 1 to

16 bytes. If you do not declare a length when you define a data object, the system assigns the default

length of 8 bytes (that is, 15 digits) and 0 decimal places.

The type also contains information on how the data is stored, what range of values is allowed, what

operations can be performed on the data, and what sort of arithmetic is used (if the data object is suitable

for use in calculations). We will deal with this topic in greater detail later in this unit.

(31)

2.7

SAP AG 2002

Type Groups in the ABAP Dictionary

Type group zmytp

TYPE-POOL zmytp. CONSTANTS zmytp_const_name ... [ TYPES zmytp_type_name1 ... ] [ TYPES zmytp_type_name2 ... ] ... Using a constant: TYPE-POOLS: zmytp.

[ DATA var TYPE zmytp_type1. ]

IF var = zmytp_const_name. ... ENDIF. zmytp zmytp zmytp zmytp zmytp zmytp zmytp zmytp zmytp zmytp zmytp zmytp

Name of type group: Up to 5 characters; each type name and

constant name starts with the name of

the type group.

TYPE

TYPE--POOLSPOOLS

Each type group, whose types and constants you want to use, must be specified

in the ABAP program

ABAP program

zmytp

zmytp

You must use a type group to define global constants.

The name of the type group can contain up to 5

characters.

You define constants in the type group using the

CONSTANTS

statement, just as in an ABAP program.

You only have to adhere to the following namespace convention:

All constants (and type names) must have the name of the type group as a prefix.

You can use either a global Dictionary type or a predefined ABAP type as a valid type.

To be able to use the types of a type group in a program, you must refer to the type group using the

TYPE-POOLS

statement.

After this line in the program, you can then use all the constants in the type group.

You can also define global data types in a type group. Before SAP R/3 Basis Release 4.5, this was the

only way to define complex global data types.

(32)

2.8

SAP AG 2002

Data Types and Data Objects in Detail (2)

Special Features in Unicode

Special Features in Unicode

Elementary Data Objects

Elementary Data Objects

Structures

Structures

Introduction

Introduction

(33)

2.9

SAP AG 2002

Integer auxiliary variable

1

int2 = 4 int3 = 3 int4 = 2 2 4 3 + = / 2 + 3 = = int1

Integers and Integer Arithmetic

+ -* / DIV MOD ** Addition Subtraction Multiplication Division Integer division

Remainder integer div. Power

Arithmetic operations for integers:

int1 = int2 / int3 + int4.

DATA: counter TYPE i VALUE 1. Length: 4 bytes

Value range [-2147483648; 2147483647] Integer Arithmetic

All internal auxiliary fields are integers Interim results are rounded

In integer arithmetic, the system always rounds to the appropriate decimal place. So, for example:

DATA int TYPE i. int = 4 / 10. " result: 0

int = 5 / 10. " result: 1

Calculations performed using integer arithmetic are faster than calculations using fixed point or floating

point arithmetic.

For further information on calculations performed on integers, refer to the keyword documentation for

the

COMPUTE

statement.

(34)

2.10

SAP AG 2002

Packed Numbers and Fixed Point Arithmetic

0 1 2 3 4 +

1 digit per half-byte

Sign

DATA: percentage(3) TYPE p DECIMALS 2 VALUE '12.34'.(3)(3) DECIMALS 2DECIMALS 2

Length in bytes: n bytes correspond to 2n - 1 digits Number of decimal places 12,34 Number

Fixed point arithmetic: "like using paper and pencil"

Permitted length: 1 to 16 bytes (= 1 to 31 digits) Number of decimal places < number of digits, max. 15 Example: Length 3 bytes, 2 decimal places

Þ Value range: [-999.99,+999.99]

Internal representation

1234,56 + 78,5

1313,06

The length of packed numbers is given in bytes. The connection between value range and length is

derived from the internal representation: Each decimal digit is represented by a half-byte. The last byte is

reserved for the plus or minus sign.

The number of decimal places is defined using the

DECIMALS

addition. The maximum number of

decimal places is either 15 or the length of the number minus 1 (that is, there must be at least one digit

before the comma).

In user dialogs, decimal numbers are formatted according to the settings in the user master record.

Decimal point-aligned fixed point arithmetic is used as default for calculations. Packed numbers are thus

well-suited to business calculations, where the correct rounding for the specified number of decimal

places is very important. The algorithm for this arithmetic is similar to using "pencil and paper".

The system always uses packed numbers of maximum length for interim results.

You can switch off fixed point arithmetic in the program attributes. If you do, the

DECIMALS

addition

when defining a packed number only affects the output of the number. Internally, all numbers are

interpreted as integers, regardless of the position of the decimal point. The fixed point arithmetic option

is always selected by default. You should always accept this value and use packed numbers for business

calculations.

(35)

2.11

SAP AG 2002 Λ Λ Λ Λ Λ

Λ

Λ

1499023437 , 0 1494140625 , 0 1484375 , 0 140625 , 0 125 , 0

2048

1

1024

1

128

1

64

1

8

1

2

1

2

1

2

1

2

1

2

1

15

,

0

2

1

2

1

2

1

5

,

1

11 10 7 6 3 1 0

1

= + = + = + = + =

+

+

+

+

+

=

+

×

+

×

+

×

+

×

+

×

=

+

=

×

+

×

=

-Floating Point Arithmetic

|

|

|

0 0

|

|

0 0

|

|

. . .

Only 53 bits available

≈≈≈≈

Only for approximations

Unlike packed numbers, floating point numbers are represented using sums of binary fractions. Floating

point numbers are also normalized, and both the exponent and the mantissa are stored in binary form.

This representation complies with the IEEE norm for double precision floating point numbers. The

floating point operations of the relevant processors are used for calculations.

Since algorithms are converted to binary, inaccuracies can occur. Therefore, floating point numbers are

not suitable for business calculations.

Example:

You want to calculate 7.72% of 73050 and display the result accurate to two decimal places. The answer

should be 5310.74 (73050 * 0.0727 = 5310.7735). The program, however:

DATA: float TYPE f, pack TYPE p DECIMALS 2.

float = 73050 * '0.0727'. " result: 5.3107349999999997E+03

pack = float. WRITE pack. " result: 5310.73

You should therefore only use floating point numbers for approximations. When you compare

numbers, always use intervals, and always round at the end of your calculations.

The advantage of floating point numbers is the large value range: It comprises numbers from is, from

2,2250738585072014E-308 to 1,7976931348623157E+308 including both positive and negative

numbers as well as zero. In addition, you must use floating point numbers for special aggregation

functions of the

SELECT

statement.

(36)

2.12

SAP AG 2002

Summary: Recommendations for Using Numeric

Data Types

Required:

Required: Recommended predefined ABAP data type:Recommended predefined ABAP data type:

Integers only Type i,

since calculations using integer arithmetic are fastest

Decimal numbers for

business calculations Type p

Decimal numbers for rough calculations performed on very small or very large numbers

Type F

Note:

The results of the following functions have the data type f:

Trigonometric functions:

cos

,

acos

,

sin

,

asin

,

tan

,

atan

Hyperbolic functions:

tanh

,

sinh

,

cosh

Exponential functions (base e):

exp

Natural logarithms (base e):

log

Logarithms (base 10):

log10

Square root:

sqrt

(37)

2.13

SAP AG 2002

Arithmetic and Mixed Expressions

c a b r = / + p DECIMALS 3 i i f 0.0000...E+000 201 / 200 + → →→

Float. point arithmetic

↓↓↓↓ Conversion after f and calculation 0.0000...E+000 1.004999...E+000 Interim result: + = 1.004999...E+000 ↓↓↓↓ Conversion after p DECIMALS 3 1.005

Fixed point arithmetic is the default

Integer arithmetic is only used if all the components are integers

Floating point arithmetic is used if at least one component is a floating point number All components are converted to the relevant data type

After the calculation, all are converted to the result type

Example:

An arithmetic expression may contain any data types that are convertible into each other and into the

type of the result field.

The system converts all the values into one of the three numeric data types (

i

,

p

, or

f

), depending on the

data types of the operands. The ABAP runtime system contains an arithmetic for each of the three data

types. The system then performs the calculation and converts it into the data type of the result field.

This may mean that the same arithmetic expression leads to different results when performed on

different combinations of data types.

It is also possible for an arithmetic expression to have only character string type data objects, as long

as their contents are appropriate. The values are converted to numeric type objects. Bear in mind that

conversions affect performance. Wherever possible, choose a data type that does not require runtime

conversion.

If an arithmetic expression contains numeric literals, the choice of arithmetic depends on the size of the

number: If the number is within the value range for the data type

i

, the numeric literal is interpreted as

an integer. If the value of the literal is greater than 2147483647, it is interpreted as a packed number.

Example:

DATA int TYPE i. int = 1000000000 / 300000000 * 3. "result: 9

int = 10000000000 / 3000000000 * 3. "result: 10

(38)

2.14

SAP AG 2002

Predefined ABAP Types for Character Strings

Description Length Value range Calculations Formatting options 1 .. 1 .. 65535 65535 characters characters 1 .. 65535 characters 8 digits YYYYMMDD 6 digits HHMMSS Depends on

Depends oncodepagecodepage By Gregorian calendar By clock Type Type cc Type n Type d Type t

Time Date Sequence

of digits

Fixed

Fixed--length length char. string char. string Date arithmetic Time arithmetic Based on user default values HH:MM:SS Digits Variable Variable Type

Type stringstring

Char. string Char. string of variable of variable length length

Conversion Conversion ConversionConversion

The value range of each string depends on the code page, which contains all the supported characters in

form of a table. Internally, each character is represented by a code number. When the system outputs the

character, it uses the code page to convert this number. To find the code page valid in a given system,

choose Tools

CCMS

Spool Administration

Full Administration

Character Sets.

The initial value of each character string with fixed length is a space character.

Numeric strings are represented internally as character strings. Note, however, that only digits are

permissible as characters. When character strings are assigned to numeric strings, the system ignores

letters and only copies the digits (right-aligned). Missing characters are filled with zeros.

The initial value of each character in a numeric string is a zero.

Only sequences of digits are valid for values of type

d

. These digits form a meaningful date, which

complies with the Gregorian calendar. The first four digits represent the year, the next two the month

and the last two the date. For performance reasons however, the object is only checked if it is an input

field on a screen or selection screen.

The initial value of a date is

'000000'

. The formatting options are determined by the user settings.

For values of type t, a sequence of digits is only valid if it can be interpreted as a time on the 24-hour

clock. The rules for interpreting the value are analogous to those used for dates.

The initial value of a time is

'000000'

.

(39)

2.15

SAP AG 2002

Overview: Character String Processing

REPLACE REPLACE TRANSLATE TRANSLATE SHIFT SHIFT CONDENSE CONDENSE FIND FIND SPLIT SPLIT CONCATENATE CONCATENATE

+

OVERLAY OVERLAY

Description and notes

Search in a character string

Replace

Move

Remove space characters

Overwrite : Spaces are overwritten by characters from the second character string

Concatenate several character strings Split a character string

A B A P

A B A P

a b a p

A B A P

B A P

B B A P

A P

A P

A B

A P

A B A P

A B P

A B A P

A B

A P

A A A A

Search in a character string

Search in a character string

Replace first occurrence

Replace first occurrence

Move Move Remove Remove Overwrite Overwrite Concatenate Concatenate Split Split

Replace all occurrences

Replace all occurrences

A B C A P

A B A P

B

?

Found: sy-subrc = 0

Position of search string

using MATCH OFFSET offaddition

Note for

FIND

statement (search in a character string):

There are special comparison operators for strings, which you can use in logical expressions in a query

(

IF

) to search more flexibly for character sequences in a character string. For more information, see the

keyword documentation for

IF

.

For every statement, the operands are treated like type

c

fields, regardless of their actual field type. No

internal type conversions take place.

All of the statements apart from

TRANSLATE

and

CONDENSE

set the system field

sy-subrc

.

(

SEARCH

also sets the system field

sy-fdpos

with the offset of the character string found.)

All of the statements apart from

SEARCH

are case-sensitive.

To find out the occupied length of a string, use the standard function

STRLEN()

.

For the

SPLIT

statement there is the variant

SPLIT ... INTO TABLE <itab>

, which you can

use to split the character string dynamically. You do not need to specify the number of parts into which

the string should be split.

(40)

2.16

SAP AG 2002

Accessing Parts of Fields

<statement> <field>+<off>(<len>) ...

REPORT ...

PARAMETERS:

pa_str(40) LOWER CASE,

pa_pos TYPE i,

pa_len TYPE i.

WRITE pa_str

+pa_pos(pa_len)

.

19991231ttA235959

000000

Possible with any character-type field

+

+

pa

pa

_

_

pos

pos

(

(

pa

pa

_

_

len

len

)

)

In any statement that operates on a character-type field, you can address part of the field or structure by

specifying a starting position and a number of characters. If the field lengths are different, the system

either truncates the target or fills it with initial values. The source and target fields must have the type

x

,

c

,

n

,

d

,

t

, or

STRING.

You can also use structures.

Example

MOVE <field1>+<off1>(<len1>) TO <field2>+<off2>(<len2>).

This statements assigns

<len1>

characters of field

<field1>

starting at offset

<off1>

to

<len2>

characters of

<field2>

starting at offset

<off2>

.

(41)

2.17

SAP AG 2002

Special Features in Unicode

Special Features in Unicode

Elementary Data Objects

Elementary Data Objects

Structures

Structures

Data Types and Data Objects in Detail (3)

Introduction

Introduction

(42)

2.18

SAP AG 2002

Defining Structures with Local Types

TYPES:

BEGIN OF s_name_type,

prename(25) TYPE c,

surname(25) TYPE c,

title(5) TYPE c,

END OF s_name_type.

DATA:

s_name TYPE s_name_type .

DATA:

BEGIN OF s_name,

prename(25) TYPE c,

surname(25) TYPE c,

title(5) TYPE c,

END OF s_name.

DATA:

DATA:

TYPES:

TYPES:

BEGIN OF

BEGIN OF

END OF

END OF

BEGIN OF

BEGIN OF

END OF

END OF

DATA:

DATA:

START-OF-SELECTION.

s_name-prename = 'Smith'.

s_name-surname = 'John'.

s_name

s_name

s_name

s_name

Alternatives

s_name_type

s_name_type

s_name

-Definition of a structure type

Definition of a structure with reference to a user-defined type

Definition of a structure with implicit type construction

As with elementary data objects, you can define structures in two ways:

First, define a structure type explicitly using the

TYPES

statement.

To do this, enter the name of the structure after

BEGIN OF

and then list the definitions of all the

components. End the definition of the structure type using

END OF

.

You then define the structured data object with the

DATA

statement, using your own user-defined

structure type.

Define the data object directly using the

DATA

statement. The syntax is similar to the definition of a

structure type. If you use this option, the corresponding structure type is defined implicitly at the same

time.

In both cases, the type is defined locally. Bear in mind that you can also use globally defined types

instead.

You address components of structures using:

structure_name-comp_name.

For this reason, you should avoid using hyphens in variable names.

(43)

2.19

SAP AG 2002

Defining Nested Structures with Local Types

Nested structure Nested structure Structure type Structure type name street city prename surname title s_address s_name_type prename surname title

TYPES:

BEGIN OF s_name_type,

prename(25) TYPE c,

surname(25) TYPE c,

title(5) TYPE c,

END OF s_name_type.

DATA:

BEGIN OF s_address,

name TYPE s_name_type,

street(15) TYPE c,

city(25) TYPE c,

END OF s_address.

s_address-name-surname = 'Smith'.

s_address-city = 'London'.

s_name_type

-- -

-s_name_type

Application: Logical subgrouping of data

You can define nested structures by assigning a structure type to a component within a structure type.

You can address this substructure as a whole using the component name:

structure_name-substructure_name.

You can also address individual components in the substructure:

structure_name-substructure_name-comp_name.

Structures can be nested to any level you wish.

You can also integrate components of a dynamic type in a structure. This can either be an elementary

data object of variable length (

string

or

xstring

),an internal table, or a reference. These structures

are known as deep structures.

There are constraints on how such deep structures can be used. For instance, a deep structure cannot be

used as a whole in the

INTO

clause of the

SELECT

statement. (Instead, each component must be listed

separately). Offset operations are also not appropriate. For more information, refer to SAP Note 176336.

(44)

2.20

SAP AG 2002

Using Named Includes

DATA:

BEGIN OF t_linetype,

prename(25) TYPE c,

surname(25) TYPE c,

title(5) TYPE c,

END OF s_name_type.

DATA

BEGIN OF s_address.

INCLUDE STRUCTURE s_name_type

AS name.

DATA:

street(15) TYPE c,

city(25) TYPE c,

END OF s_address.

s_address-name-surname = 'Smith'.

* or:

s_address-surname = 'Smith'.

s_name_type

s_name_type

INCLUDE STRUCTURE

INCLUDE STRUCTURE

AS

AS

Structure with named include

Structure with named include

Structure type Structure type street city prename surname title s_address s_name_type prename surname title name -- -

-- Logical subgroup desired, but nested Use:

structures not technically possible

In some cases, you cannot use nested structures, for example:

Because you can only define database tables with flat line types

In situations where user dialogs with a table-type display can only contain simple structures (such as in

the SAP List Viewer or Table Control)

In situations like these, you may still want to group parts of the structure and address it as a whole. You

do this using named includes:

You can include a substructure in another structure, and give this substructure a name:

DATA: BEGIN OF structure_name,

... .

INCLUDE STRUCTURE substructure_type AS name.

DATA: ... ,

END OF structure_name.

You can address this substructure using

structure_name-name

. You can address the fields in the

substructure using

structure_name-name-comp_name

or directly using

structure_name-comp_name

. Technically, however, this structure is not nested.

If naming conflicts occur - for example, if you want to include the same substructure twice - you can

append another name to the component names using

RENAMING

. For further information, refer to the

keyword documentation for the

INCLUDE STRUCTURE

statement.

(45)

2.21

SAP AG 2002

Special Features in Unicode

Special Features in Unicode

Elementary Data Objects

Elementary Data Objects

Structures

Structures

Data Types and Data Objects in Detail (4)

Introduction

Introduction

(46)

2.22

SAP AG 2002

Unicode: Overview

Solution: Unicode

ONE codepage that

comprises all known

characters

Every character is generally

displayed by two bytes

a

ю

ق

й

S

a

Unicode

Unicode

Previous problems

Mixture of different incompatible character sets in one central

system

Data exchange between systems with incompatible character sets

To be able to work with Unicode, you must have a Unicode-compatible SAP System installed that itself

has a corresponding operating system and database. The ABAP programs must also be

Unicode-compatible.

In Unicode programs, other syntax rules apply than in non-Unicode programs. This is due to the

difference between the length in bytes and the number of characters in a character set in Unicode.

Existing programs are affected by a conversion to Unicode if an explicit or implicit assumption is made

about the internal length of a character. To execute the relevant syntax checks, you must check Unicode

Checks Active under program attributes.

In a Unicode system, you can only execute programs that have the Unicode flag set. If the Unicode flag

is set for a program, the syntax check and program are executed in accordance with the rules described

in the Unicode online help (irrespective of whether it is a Unicode or a non-Unicode system).

If the Unicode flag is not set, the program can only be executed in a non-Unicode system. For such

programs, the Unicode-specific changes of syntax and semantics do not apply. However, you can use all

language enhancements introduced in connection with the conversion to Unicode.

(47)

2.23

SAP AG 2002

Character-Type and Byte-Type Types

Character-type types in Unicode programs

d t string xstring

x

c n Character-type structure types

Difference between byte processing and character processing

DATA: c_field(4) TYPE c VALUE 'HUGO', x_field(4) TYPE x VALUE 'E391B9A2'.

SHIFT c_field BY 2 PLACES [IN CHARACTER MODE]. SHIFT x_field BY 2 PLACES IN BYTE MODE.

c_field x_field H U G O E391B9A2 B9A20000 G O _ _ Only components with the types

c, n, d, and t

byte-type byte-type

In Unicode programs, the following data types are interpreted as character-type:

c

,

n

,

d

,

t

,

string

as well as structure types, that directly or in substructures only contain components

with types

c

,

n

,

d

and

t

. In non-Unicode systems, a character of this type is one byte and in Unicode

systems, it is as long as corresponds with the length of a character on the relevant platform. Variables of

the types

x

and

xstring

are described as byte-type.

The character string processing (for which, previously, all arguments were implicitly interpreted as type

c

fields) is separated into string processing for character-type and byte-type arguments.

In the case of the string processing for character-type arguments, the single fields must be type

c

,

n

,

d

,

t

, or

string

; character-type structures are also permitted. If arguments of another type are transferred,

this triggers a syntax or runtime error.

The

X

variants of the string statement are distinguished from the character string commands by the

IN

BYTE MODE

addition. For the character string variants,

IN CHARACTER MODE

is an optional

addition. If the

IN BYTE MODE

addition is specified, only

X

fields and

X

strings are permitted as

arguments. If arguments of another type are transferred, this triggers a syntax or runtime error.

(48)

2.24

SAP AG 2002

Functions and Comparison Operators

Functions Character-type type XSTRLEN Byte-type type Comparison operators Functions STRLEN CO, CA, CS, CP, CN, NA, NS, NP BYTE-CO, BYTE-CA, BYTE-CS, BYTE-CN, BYTE-NA, BYTE-NS STRLEN

DATA: c_fld1(4) TYPE c VALUE 'HUGO', c_fld2(1) TYPE c VALUE 'G'.

IF c_fld1 CA c_fld2. ...

ENDIF.

DATA: x_field(4) TYPE x

VALUE 'E391B9A2', len TYPE i.

len = XSTRLEN( x_field ).

Length in bytes

Examples:

Length in characters

The operators

CO

,

CN

,

CA

,

NA

,

CS

,

NS

,

CP

,

NP

are available for comparing the contents of character

string type data objects (for syntax and semantics, see keyword documentation).

As with the statements

for string processing, these operators require single fields of type

c

,

n

,

d

,

t

, or

string

as arguments.

Again, character-type structures are also permitted.

The

X

variants of the string comparison operators are distinguished from the character string variants by

the

BYTE

- prefix. For this operation, only

X

fields and fields of the type

xstring

are allowed as

arguments.

The

STRLEN

function only works with character-type fields and returns the length in characters. With

c

fields, only the so-called occupied length is relevant, that is, unlike with strings, trailing blanks are not

counted.

The

XSTRLEN

function is available for the length of byte sequences. For

X

strings,

XSTRLEN

returns

the current length and for

X

fields, the defined length in bytes, where null bytes at the end of fields are

counted.

(49)

2.25

SAP AG 2002

Compatibility and Conversion

No conversion takes place if type-compatible data objects are assigned If non-type-compatible data objects are assigned, conversion does take place if a conversion rule is defined

When are two types compatible?

Two elementary types are compatible when they have exactly the same type and length(and, in the case of packed numbers, the same number of

decimal places ).

Two structure types are compatible when they have the

same structureand their components are .

Two table types are compatible if their row typesare

compatibleand their key definitions and table types

are the same.

type

type lengthlength decimal places

decimal places

same structure

same structure components are compatiblecomponents are compatible

row types

row types

key definitions

key definitions table typestable types are the same.

are the same.

MOVE a TO b. b = a.

compatible

compatiblecompatiblecompatible

If two data types are not compatible but there is a conversion rule, the system converts the source object

into the type of the target object when you assign values, perform calculations, or compare values.

For a full list of all conversion rules, refer to the ABAP syntax documentation for the

MOVE

statement.

If there is no conversion rule defined for a particular assignment, the way in which the system reacts

depends on the program context.

If the types of the objects involved are defined statically, a syntax error occurs.

Example:

DATA: date TYPE d VALUE '19991231', time TYPE t.

FIELD-SYMBOLS: <fs_date> TYPE d, <fs_time> TYPE t.

ASSIGN: date TO <fs_date>, time TO <fs_time>.

<fs_time> = <fs_date>.

In the case of dynamic typing a runtime error occurs, because the field symbols are not assigned types

until the assignment of the data objects at runtime.

Example:

...

FIELD-SYMBOLS: <fs_date> TYPE ANY, <fs_time> TYPE ANY.

...

(Rest as above)

(50)

2.26

SAP AG 2002

Conversion Under Unicode (1)

Conversion between flat structures

struc2

MOVE struc1 TO struc2.

Decisive criterion: Fragment view I X(3) C(3) C(4) C(3) C(4) struc1 C(6) N(4) X(3) N(4) I P(8) struc1 struc2 P(8) I C(4) X(3) C(10)

Conversion between flat structures is possible if the fragments of the source and target structures match both in type and length in the length of the shorter structure.

Under what condition is this assignment possible?

Assignment is possible

For some data types there are, for technical reasons, specific alignment requirements that depend on the

individual platforms. (In the memory, fields of this type must begin and end on specific addresses - for

example, a memory address divisible by four.)

Within a structure, the runtime system, if necessary, inserts bytes before or after these components with

alignment requirements to achieve the alignment needed. These bytes are known as Alignment.

To check whether the conversion is even permitted, the system first creates the Unicode fragment view

of the structures by grouping adjacent components and alignment gaps (one group each for

character-type character-types [

c

,

n

,

d

,

t

], byte-type types, and types

i

,

f

, and

p

).

Adjacent character-type components of a structure are therefore only grouped together if there are no

alignment gaps between these components. Adjacent byte-type components are grouped in the same

way.

If the fragments of the source and initial structures match the type and length in the length of the shorter

structure, the conversion is allowed.

If the target structure is longer than the source structure, the character-type components of the

remainder are filled with space characters. All other components in the remainder are filled with the

type-specific initial value, alignment gaps are filled with null bytes.

References

Related documents

4.2.12.5 Temperature Rise Tests of Three-Phase Transformers or Three Single-Phase Transformers by The Impedance kVA Method A single three-phase transformer shall be permitted to

This current literature review attempts to focus on some themes related to children living with HIV/Aids. For review purposes themes include the definition of children living

The observations presented here for the case-3 show that (a) F layer height did not rise to higher al- titudes during the time of radar echoes, (b) the irregularity power law

(2007) noted that post-disaster reconstruction is quite similar to that of low-cost community housing projects in developing countries, but with added challenges.

If no Stock Length is indicated, this is a non-stocked but standard product that will be manufactured to your finish and length requirements in about 4 weeks. Inventory Codes: STK

AFTER THIS EVENT THERE IS NEED OF MIGRATION DRIVE .IT MEANS WHEN THERE IS SOME CHANGES IN SITE DISTRIBUTION OF BSC NEED OF ZONAL DRIVE.. WHAT PRECACATION NEED TO TAKE DURING

For example, the command alias D represents the command sequence &#34;DISPLAY Document&#34; (see Default Command Aliases for a description of all command aliases that are supplied

The Back-to-Work Accelerator allows users to define different types of data objects such as sensors, users, and buildings.. These data objects correlate to VANTIQ Types and can