You are on page 1of 36

DATA TYPES

14-Sep-09 Kaavian Systems


Data in ABAP

 DATA TYPES
Types are descriptions that do not occupy memory.

 DATA OBJECTS
Objects are instances of types, and do occupy their own
memory space.

14-Sep-09 Kaavian Systems 2


Defining Data Types

 Predefined ABAP types

 Local Data types

 Data types in ABAP Dictionary

14-Sep-09 Kaavian Systems 3


Predefined Data Types

 Elementary types

 Complex types

 Reference types

14-Sep-09 Kaavian Systems 4


Elementary Types

 Fixed Length

 Variable Length

14-Sep-09 Kaavian Systems 5


Predefined Data Types

14-Sep-09 Kaavian Systems 6


Fixed Length

Character Type
– Character C
– Numeric N
– Date(8) D
– Time(6) T
– Hexadecimal X

14-Sep-09 Kaavian Systems 7


Numeric Type

 Integer I
Range -2**31 to 2**31-1 only whole numbers.

 Float F
 Packed P
P allows digits after the decimal point up to 14 digit.

14-Sep-09 Kaavian Systems 8


Variable Length

 String
A string is a sequence of characters with variable length.

 XString
A byte string is a hexadecimal type with variable length.

14-Sep-09 Kaavian Systems 9


Complex Types

 ABAP contains no predefined complex data types

 STRUCTURE
A structure is a sequence of any elementary types, reference
types, or complex data types.

 INTERNAL TABLE
Internal tables consists of a series of lines that all have the
same data type.

14-Sep-09 Kaavian Systems 10


Local Data Types

TYPES <t>[(<length>)] [TYPE <type>|LIKE <obj>]


[DECIMALS <dec>]

Eg:

TYPES NAME(20) TYPE C

14-Sep-09 Kaavian Systems 11


Example for Data Types

REPORT demo_types_statement.

TYPES mytext(10) TYPE c.


TYPES myamount TYPE p DECIMALS 2.

DATA text TYPE mytext.


DATA amount TYPE myamount.

text = ' 4 / 3 = '.


amount = 4 / 3 .

WRITE: text, amount.

This program produces the following output on the screen:

4 / 3 = 1.33
14-Sep-09 Kaavian Systems 12
Data Objects

 Data objects contain the data with which ABAP programs work at
runtime.

 ABAP contains the following kinds of data objects

– Literals

– Named Data Objects

– Predefined Data Objects

– Dynamic Data Objects

14-Sep-09 Kaavian Systems 13


Literals

Literals are unnamed data objects

Types of Literals:
− Number literals
− Character Literals

Examples For literals


− Number literals

DATA number TYPE i VALUE -1234.


WRITE 6789.
− Character Literals
`Anton Schmitt
`69190 Walldorf `

14-Sep-09 Kaavian Systems 14


Named Data Objects
 You declare these data objects either statically or dynamically at runtime.

 Their technical attributes - field length, number of decimal places, and data type -
are always fixed.

 We address data objects using its name that we gave.

 ABAP contains the following kinds of named data objects:


− Text Symbols
− Variables
− Constants
− Interface Work Areas

14-Sep-09 Kaavian Systems 15


Text Symbols

 A text symbol is a named data object that is generated when you start the
program from the texts in the text pool of the ABAP program. It always
has the data type C.

 Text symbols, along with the program title, list headings, and selection
texts, belong to the text elements of a program.

 In the program, you can address text symbols using the following form:
TEXT-<idt>

14-Sep-09 Kaavian Systems 16


Variables

Variables are named data objects that you can declare


statically using declarative statements, or dynamically while a
program is running. They allow you to store changeable data under
a particular name within the memory area of a program.

14-Sep-09 Kaavian Systems 17


Variables

You can declare variables statically using the following statements:


 DATA: To declare variables whose lifetime is linked to the
context of the declaration
 STATICS: To declare variables with static validity in
procedures
 CLASS-DATA: To declare static variables within classes
 PARAMETERS: To declare elementary data objects that
are also linked to an input field on a selection screen

14-Sep-09 Kaavian Systems 18


Variables

 SELECT-OPTIONS: To declare an internal table that is


also linked to input fields on a selection screen
 RANGES: To declare an internal table with the same
structure as in SELECT-OPTIONS, but without linking it
to a selection screen.

Variables are declared dynamically when you add characters


or bytes to a string, or lines to an internal table

14-Sep-09 Kaavian Systems 19


Constants

 Constants are named data objects that you create statically using a
declarative statement. They allow you to store data under a
particular name within the memory area of a program.

 The value of a constant must be defined when you declare it. It


cannot subsequently be changed.

 The value of a constant cannot be changed during the execution of


the program. If you try to change the value of a constant, a syntax
error or runtime error occurs.

14-Sep-09 Kaavian Systems 20


Constants

CONSTANTS statement is exactly the same as that of the DATA


statement, but with the following exceptions:

You must use the VALUE addition in the CONSTANTS statement.


The start value specified in the VALUE addition cannot be changed
during the execution of the program.

Example:

CONSTANTS: pi TYPE P DECIMALS 10 VALUE '3.1415926536'.

ref_c1 TYPE REF TO C1 VALUE IS INITIAL.

14-Sep-09 Kaavian Systems 21


Predefined Data Object

 System Fields From Structure SY

SY is a structure with the ABAP Dictionary


data type SYST. The components of SY are known as system
fields. System fields contain values that provide information
about the current state of the system. They are automatically
filled and updated by the ABAP runtime environment.

14-Sep-09 Kaavian Systems 22


Example for Data Objects

PROGRAM demo_elementary_data_objects.

DATA text1(20) TYPE c.


DATA text2 TYPE string.
DATA number TYPE i.

text1 = 'The number'.


number = 100.
text2 = 'is an integer.'.

WRITE: text1, number, text2.

This program produces the following output on the screen:

The number 100 is an integer.


14-Sep-09 Kaavian Systems 23
Type Additions

TYPE Addition – Used for defining a new data type


 You use the TYPE addition in various ABAP statements
for defining data types and specifying the types of
interface parameters or field symbols.
 TYPE addition can have various meanings depending on
the syntax and context.

14-Sep-09 Kaavian Systems 24


Like Additions

LIKE Addition – Used for defining data object

You use the LIKE addition in various ABAP statements


for defining data types and specifying the types of interface
parameters or field symbols.

The addition LIKE <obj> can be used in the same ABAP


statements as the TYPE addition to refer to any data object
<obj> that is already visible at that point in the program.

14-Sep-09 Kaavian Systems 25


Report

The statement REPORT must be the first statement of an independent


program

Syntax

REPORT rep [list_options]


           [MESSAGE-ID mid]
           [DEFINING DATABASE ldb].

REPORT - list_options

[NO STANDARD PAGE HEADING]


[LINE-SIZE width]
[LINE-COUNT page_lines[(footer_lines)]]

14-Sep-09 Kaavian Systems 26


Comments

 Comments are texts that you can write between the statements of
your ABAP program to explain their purpose to a reader.

 Comments are distinguished by the preceding signs * (at the


beginning of a line) and " (at any position in a line).

 If you want the entire line to be a comment, enter an asterisk (*)


at the beginning of the line.

14-Sep-09 Kaavian Systems 27


Structure

 Example

DATA : BEGIN OF structure,


                 Name(20) type c,
age type I,
        END OF structure.

 Types of Structure
Nested, Flat, Deep

14-Sep-09 Kaavian Systems 28


Parameters

 ABAP/4 includes some data objects with special features, namely


Parameters.

 Parameters are variables which are linked to a selection screen.


They can accept values after a program is started.

Syntax
PARAMETERS <p>[(<length>)] [TYPE <type>|LIKE <obj>]
[DECIMALS <d>].

14-Sep-09 Kaavian Systems 29


Write

The basic ABAP/4 statement for outputting on the screen is WRITE.

Syntax: WRITE<f>.

The field <f> can be

− Any Data Object

− A Field Symbol

− A Text Symbol

14-Sep-09 Kaavian Systems 30


Select-Options

The SELECT-OPTIONS statement is used to declare selection


tables and create corresponding input fields on the associated
selection screen.

Syntax

SELECT-OPTIONS <seltab> FOR <f>.

14-Sep-09 Kaavian Systems 31


Field symbols

 Field symbols are placeholders or symbolic names for other fields.

 They do not physically reserve space for a field, but point to its
contents.

Syntax
FIELD-SYMBOLS <FS> [<type>|STRUCTURE <s>
DEFAULT <wa>].

14-Sep-09 Kaavian Systems 32


Processing data

 Assigning Values

 Numeric Operations

 Processing Character String

14-Sep-09 Kaavian Systems 33


Assigning values

 MOVE

 WRITE TO

 CLEAR

 Value Addition in data

14-Sep-09 Kaavian Systems 34


Move

 Move data into or between variables is done using the move statement.
There are two forms of the move statement

move <f1> to <f2>

or

f2 = f1
 WRITE TO

write <f1> to <f2>


 CLEAR

clear <f>

14-Sep-09 Kaavian Systems 35


Thank You

14-Sep-09 Kaavian Systems 36

You might also like