Sei sulla pagina 1di 38

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

Defining Data Types

Predefined ABAP types

Local Data types

Data types in ABAP Dictionary

14-Sep-09

Kaavian Systems

Predefined Data Types

Elementary types

Complex types

Reference types

14-Sep-09

Kaavian Systems

Elementary Types

Fixed Length

Variable Length

14-Sep-09

Kaavian Systems

Predefined Data Types

14-Sep-09

Kaavian Systems

Fixed Length
Character Type

14-Sep-09

Character

Numeric

Date(8)

Time(6)

Hexadecimal X

D
T

Kaavian Systems

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

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

Complex Types

ABAP contains no predefined complex data


types

STRUCTURE
A

structure

is

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:
14-Sep-09

Kaavian Systems

4 / 3 = 1.33

12

Data Objects

Data objects contain the data with which ABAP


programs work at runtime.

ABAP contains the following kinds of data


objects

14-Sep-09

Literals

Named Data Objects

Predefined Data Objects

Dynamic Data Objects

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.

14-Sep-09

WRITE 6789.
Character Literals
`Anton Schmitt
`69190 Walldorf
`
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:

14-Sep-09

Text Symbols
Variables

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:

14-Sep-09

Kaavian Systems

TEXT-<idt>

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

14-Sep-09

PARAMETERS: To declare elementary data


objects that are also linked to an input field
on a selectionKaavian
screen
18
Systems

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 SELECTOPTIONS, 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

14-Sep-09

internal table

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

14-Sep-09

Kaavian Systems
error or runtime error
occurs.

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'.
14-Sep-09

Kaavian Systems

ref_c1 TYPE REF TO C1 VALUE IS

21

Predefined Data Object

ystem Fields From Structure SY


SY

is

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:
14-Sep-09

Kaavian Systems
The number 100 is an
integer.

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>

14-Sep-09

DEFAULT <wa>].

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

14-Sep-09

clear <f>

Kaavian Systems

35

Scenario
Maintain a record with the fields

NAME
AGE
SEX
QUALIFICATION
DOB
DESIGNATION
COMMENTS to the code.

14-Sep-09

Kaavian Systems

36

Scenario
(Specify appropriate DATA TYPES). Get the values
from the user (using PARAMETER) MOVE it to the
RECORD. Use FIELD-SYMBOL for designation and print
the record using WRITE statement and all the possible
options, Give appropriate COMMENTS to the code.

14-Sep-09

Kaavian Systems

37

Reference

The
learning
material
contained
in
this
PowerPoint
Presentation is prepared with the help of http://help.sap.com/
and sap press book. All rights reserved by SAP AG.
Unless otherwise specifically stated, this learning material is
intended for the sole purpose of class room session, internal use
and for knowledge transfer to the Consultants.
However, for detailed information on this learning material,
http://help.sap.com / sap press book may be referred.
Kaavian is not liable for any legal liability or responsibility for
the accuracy, completeness or usefulness of any information
disclosed in these learning materials.
No portion of the learning materials
shall be modified,
reproduced or transmitted in any form by any means, whether
by electronic, photocopier or otherwise without the written
permission of Kaavian. In no event shall Kaavian be liable for
any damage whatsoever resulting in any action arising in
connection with the use of learning material.
02-Sep-09

Kaavian Systems

Potrebbero piacerti anche