Monday, August 25, 2014

ABAP Null Value vs Initial Value

ABAP Null Value vs Initial Value

Null & initial Value is totally different.
In sap, we can say that there is no concept of null value.
First of all, let's define the meaning of null and initial value.

 NULL doesn't have any value
-    NULL doesn't have any value
therefore, NULL doesn't occupy memory space
-    NULL cant' be replace with the below value
: 0, ‘’, ‘ ‘, SPACE
-    NULL is an object that can't be compared and calculated.
It's allowed to use command 'IS NULL, IS NOT NULL' in ABAP OPEN SQL.

 Initial Value has a value
-    Initial Value has a value
therefore, Initial value occupy memory space
-    Initial Value can be replaced with the below value
: 0, ‘’, ‘ ‘, SPACE,
-    Initial Value is an object that can be compared and calculated in all ABAP commands.

All ABAP type has an individual initial value as be seen in below tabluar.
ABAP TYPE
Initial Length
Initial Value
meaning
I
4
0
Integer (whole number)
F
8
0
Floating point number
P
8
0
Packed number
C
1
' '
Text Field
(alphanumeric characters)
D
8
'00000000'
Date field
(Format: YYYYMMDD)
N
1
'0 0'
Numeric text field
(numeric characters)
T
6
'000000'
(format: HHMMSS)
X
1
X'0 0'
Hexadecimal field
If you declare the TYPE C data in abap program,  the data has a 'space'( = '') initially without assigning any value. While If you declare the TYPE i data in abap program, the data has a 0 initially.

In ABAP dictionary table, there is an option regarding initial value. if you set this field selected, the column can have a initial value.



In the future, let's assume that there would be a demand from business side that adds a new column for further information.
In this case,  you can adjust initial value for this additional column.
 - 'X' : the new column of currently existing data has a initial value
 - ''  : the new column of currently existing data has a null value.

if you set initial value option as  'X' for this additional column, you can select the pre-existing data by using initial value.
- SELECT * FROM Table WHERE F1 = SPACE

if you set initial value option as '' for this additional column, you can select the pre-existing data by using NULL command.

- SELECT * FROM table WHERE F1 = NULL.


No comments:

Post a Comment