Do you Know ?

SAP ABAP Datatypes with Examples

Data typeNumeric

Example : 1

Report  ZTest.
Data N1(10) type n.” (documentation) Numeric data type declaration
N1 = 5000.
Write:/ n1.


Output:
0000005000

Example : 2

Inserting characters in numeric to see how it works :D

Report  ZTest.
Data N1(10) type n.
N1 = ‘hello’. ” Inserting characters
Write:/ n1.

Output:
0000000000

: Displays 10 zeros here.

Understanding:  If you are trying to insert characters into a numeric it will displays numeric only.

_______________________________________________________________________________________

DataType : Integer

Integer doesn’t require length specification , i.e. length specification not allowed (data a1(10) type I ,Syntax error) in integer data type.

Example : 1

REPORT  ZPROG3.

parameter week type i.

if week > 0 and week < 8.
case week.
when 1.
write:/ 'sunday'.
when 2.
write:/ 'monday'.
when 3.
write:/ 'tuesday'.
when 4.
write:/ 'wednesday'.
when others.
write:/ 'some other day'.
endcase.
else.
write:/ 'invalid entry'.
endif.

Input : 1
Output : Sunday

Input : 8
Output : invalid entry
________________________________________________________________________________________

DataType : Character


Longest form of declaring character.
Ex:  Data mychar(10) type c.

As because sap system takes any data by default as ‘char’.

Ex: Data mychar(10).

Example : 1

ZReport 1
data c1(10) .
c1 = 'Helloworld'.
write:/ c1.

Output:
Helloworld 
_________________________________________________________________________________________

DataType : Date


Date is not a KeyWord  “DATS” it is.

Syntax: data d1 type dats.

Example : 1

REPORT  ZPROG7.

date d1 type dats. 
date = '19981202'.
write:/ date.

Output: 
02.12.1988
_____________________________________________________________________________________