Wednesday 6 September 2017

ABAP: Data Types

Data type is used to specify the type of data that a variable can hold. ABAP offers both fixed and variable length data types.

Below table summarizes the basic data types in ABAP.

Keyword
Description
Default Length
Default Value
C
Character
1 character
''
N
Numeric text field
1 character
0
D
Character like Date
8 characters
00000000
T
Character like Time
6 characters
000000
X
Hexa Decimal
1 byte
X'0'
I
Integer
4 bytes
0
P
Packed
8 bytes
0
F
Float
8 bytes
0
STRING
Alpha numeric string
Variable length

XSTRING
Represents byte string
Variable length


Z_HELLO_WORLD
*&---------------------------------------------------------------------*
*& Report Z_HELLO_WORLD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_HELLO_WORLD.

* Defining Variables
DATA char_var TYPE C.
char_var = 'a'.

DATA numeric_var TYPE N.
numeric_var = 5.

DATA date_var TYPE D.
date_var = SY-DATUM.

DATA hexa_var TYPE x.
hexa_var = '5'.

DATA int_var TYPE I.
int_var = 12345.

DATA packed_var TYPE P.
packed_var = 12345.

DATA float_var TYPE F.
float_var = 1200.

DATA string_var TYPE STRING.
string_var = 'Hello World'.

DATA xstring_var TYPE XSTRING.
xstring_var = 'Hello World'.

Write char_var.
Write / numeric_var.
Write / date_var.
Write / hexa_var.
Write / int_var.
Write / packed_var.
Write / float_var.
Write / string_var.
Write / xstring_var.


Output

Write / numeric_var.
/ is used to print the output in next line.

Previous                                                 Next                                                 Home

No comments:

Post a Comment