Data statement is used for defining variables in our ABAP programming.
The syntax of data statement:
- data variable name[length] [data type] [decimals] [default value].
- data variable name like previous defined variable name [default value].
After watching different data types used in ABAP we can see the usage of data statement with some examples.
Character data types used in ABAP
- Type c: ( Used for character , maximum length between 1- 65535 and default value will blank)
- Type n: ( Used for numeric text , maximum length between 1- 65535, valid values will be 1 – 9 and default value will 0)
- Type d: ( Used for date , fixed length 8, valid values will be 1 – 9 and default value will 00000000)
- Type t: ( Used for time , fixed length 6, valid values will be 1 – 9 and default value will 000000)
- Type x: ( Used for hexadecimal and maximum length between 1- 65535)
Numeric data types used in ABAP
- Type I : ( Used for integer , fixed length 4, maximum decimals is 0,valid values between-231 to +231 and default value will be 0)
- Type p: ( Used for packed decimal , maximum length between 8- 15, maximum decimals is 14, valid values between 0-9 and default value will be 0)
- Type f: ( Used for floating point , maximum length 8, valid values between -1E-307 to 1E308 and default value will be 0.0)
Sample data statement declarations
Data x .
(Here variable x will be treated as character, because character is the default data type)
data x(2) type c .
(Here variable x will be treated as character with length 2)
data x type i value 100 .
(Here variable x will be treated as integer with default value 100)
data x type d value 20110112 .
(Here variable x will be treated as date with the specified default value)
By using like addition with data statement all the properties like data type , length of the previously defined variable will be assigned to the new variable. You will get a clear picture after seeing the following example.
Data x1(2) type c.
Data x2 like x1 .
(In this example variable x2 will get all the properties of variable x1. Means it will be treated as a character with length two)
In our ABAP program we need to use this statement several times and it’s a basic thing also.
Also Read : ABAP Tutorial Home page -> Steps to create ABAP program -> ABAP Transaction codes