You are on page 1of 24

Proprietary Information. DCDM Consulting. Not to be disclosed without express written consent.

Types and Data Types

Prepared by : Gokhool Nasreen

Proprietary Information. DCDM Consulting. Not to be disclosed without express written consent.

Agenda Abap type Hieararchy

Definition

Syntax Example
Copyright 2012 DCDMC All Rights Reserved.

Abap type hierarchy

CONSULTING TECHNOLOGY OUTSOURCING

Abap type hierarchy (contd)

CONSULTING TECHNOLOGY OUTSOURCING

1. Data Types

CONSULTING TECHNOLOGY OUTSOURCING

1. Data Types
Templates used to describe data objects. Data objects are instances of data types. Further divided into elementary, reference and complex types. There are predefined (built-in) data types or can be defined locally in the program. Do not use any memory space for work data.

CONSULTING TECHNOLOGY OUTSOURCING

1.1 Elementary Data Types

CONSULTING TECHNOLOGY OUTSOURCING

1.1 Elementary Types (contd)


They are atomic (not composed of other types). Further classified into elementary types of fixed length and variable length.

CONSULTING TECHNOLOGY OUTSOURCING

Elementary Data Types- Predefined:

1.1.1 Predefined Abap Types

Predefined elementary types are the smallest indivisible unit of types. They are data types which are predefined in the R/3 System Kernel. They can be grouped as fixed length variable length

Syntax Forms TYPES { {dtype[(len)] TYPE abap_type [DECIMALS dec]} | {dtype TYPE abap_type [LENGTH len] [DECIMALS dec]} }. Example TYPES: text10 TYPE c LENGTH 10, text20 TYPE c LENGTH 20, result TYPE p LENGTH 8 DECIMALS 2.
9 CONSULTING TECHNOLOGY OUTSOURCING

1.1.1.1 Predefined ABAP Data Types


Type Description Initial Value Length

C
D F I N P T X String xstring

Character Date

Space 00000000 0.0 0 0 0 000000 00 Space Blank string

1 65535 8 characters 8 bytes 4 bytes 1 65535

Floating Point
Integer Numeric Text

Packed Decimal
Time Hexadecimal Variable-length Variable-length Hexadecimal

1 16 bytes
6 characters 1 65535

Variable
Variable
CONSULTING TECHNOLOGY OUTSOURCING

1.1.1.1 Predefined Abap Types Fixed length Elementary Type

1. Fixed-Length Elementary Types: There are eight predefined types in ABAP with fixed length: A. Predefined Character-like types: 1. 2. 3. 4. Character (C), Numeric character (N), Date (D), Time (T).

B. Predefined Byte-like types: 1. Byte field (X).

C. Predefined Numeric types: 1. 2. 3. Integer (I), Floating-point number (F) Packed number (P).
11 CONSULTING TECHNOLOGY OUTSOURCING

1.1.1. 2 Predefined Abap Types - Variable-Length Elementary Types:

There are two predefined types in ABAP with variable length:

A. STRING for character strings

B. XSTRING for byte strings

CONSULTING TECHNOLOGY OUTSOURCING

1.1.2 User-defined Types


To define your own user-defined elementary data types, you use the TYPES statement

Syntax: Types<t>[<length>]<<type>[<decimals>]

Example: TYPES: NUMBER TYPE I. DATA: NO_FLIGHTS TYPE NUMBER You use the TYPES statement to create elementary data types and structured data types. You can use data types defined by the TYPES statement in the same way you use predefined data types for declaring data objects.

13 CONSULTING TECHNOLOGY OUTSOURCING

1.2 Complex Data types

CONSULTING TECHNOLOGY OUTSOURCING

1.2 Complex Data Types


Composed of other types. Data object of a complex type can be accessed overall or by component. Only one predefined complex types : structure sy (system fields). Must be defined in the Abap program or in Abap Dictionary. 2 types : Structured and Table types.

CONSULTING TECHNOLOGY OUTSOURCING

1.2.1 Structured type


Sequence of any elementary reference or complex data types.

Used for grouping together work areas that logically belong together.
Example TYPES: BEGIN OF street_type, name TYPE c LENGTH 40, no TYPE c LENGTH 4, END OF street_type. TYPES: BEGIN OF address_type, name TYPE c LENGTH 30, street TYPE street_type, BEGIN OF city, zipcode TYPE n LENGTH 5, name TYPE c LENGTH 40, END OF city, END OF address_type. TYPES zipcode_type TYPE address_type-cityzipcode.

Syntax: TYPES BEGIN OF struc_type. ... TYPES comp ... TYPES comp TYPE struc_type BOXED. INCLUDE {TYPE|STRUCTURE} ... ... TYPES END OF struc_type.

CONSULTING TECHNOLOGY OUTSOURCING

1.2.2 Table types


Consist of a sequence of any number of lines of the same data type. Table types are characterised by a row type. Row type can be any elementary data type, a reference data type or a complex data type.

Syntax: TYPES dtype { {TYPE tabkind OF [REF TO] type} | {LIKE tabkind OF dobj} } [tabkeys] [INITIAL SIZE n].

CONSULTING TECHNOLOGY OUTSOURCING

1.3 Reference Type

CONSULTING TECHNOLOGY OUTSOURCING

1.3 Reference Types


Describes data objects that contain references to other objects ( data objects and instances of classes). No predefined reference types. Must either be defined in Abap program or in Abap Dictionary. Form a hierarchy which represents the hierarchy of the objects to which the references can point.

Syntax TYPES dtype { {TYPE REF TO type} | {LIKE REF TO dobj} }. Example INTERFACE i1. ... ENDINTERFACE. CLASS c1 DEFINITION. PUBLIC SECTION. INTERFACES i1. ENDCLASS. TYPES: iref TYPE REF TO i1, cref TYPE REF TO c1, dref TYPE REF TO iref.

CONSULTING TECHNOLOGY OUTSOURCING

2. Object types

CONSULTING TECHNOLOGY OUTSOURCING

2. Object Types
Instances of types. Take up memory space Divided into Classes and Interfaces. Contain the above data types and functions. Define which data types and which functions an object contains. Not predefined, instead must be defined in the program or in the class library.

CONSULTING TECHNOLOGY OUTSOURCING

Chained Statements
Successive statements that have the same string segment can be combined to form a single chained statement To do so, you specify the identical starting segment once and conclude it with a colon (:), the remaining segments are then listed, separated by commas (,) and concluded with a period (.) At runtime, a chained statement is treated like an equivalent sequence of individual ABAP statements
Example
TYPE C, TYPE I, TYPE P DECIMALS 2 VALUE 1.50. TYPE N,

DATA: tmp(10) tmp1 tmp2(8) DATA: tmp3(5) tmp4.

CONSULTING TECHNOLOGY OUTSOURCING

Reference
Sap Library

CONSULTING TECHNOLOGY OUTSOURCING

Thank You.

CONSULTING TECHNOLOGY OUTSOURCING

You might also like