Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

NULL Value in OO Context

Former Member
0 Kudos

Hi ,

I want to set NULL Value in OO Context.

I cannot use clear with NuLL, SInce it is not allowed in OO Context.

Do anybody know Class xyz => NULL_Constant ?

Eg cl_abap_char_utilities=>NEWLINE

Regards

Prasath

12 REPLIES 12

Former Member
0 Kudos

Hi.

I dont really understand what you wanna do. If you want to set a variable back to its initial value (in some languages called NULL) then you use 'CLEAR'. You can use 'CLEAR' within classes etc so I think its allowed within the OO Context.

I dont think however that you can find a constant containing the value NULL.

Best Regards

Niklas

Former Member
0 Kudos

Hi Nikolas,

There is diffrence between initial/space with NULL in ABAP Also.

If you check the Hexadecimal value you can find the difference between this.

By the way you cannot use Clear statement to set NULL Value.

IN OO Context Clear with NULL Command generates EPC Error.

Eventhough I can use that with or without supressing the EPC Error.

I want to provide a better solution in OO Context using the class's constant.

Thanks for your feedback

Regards

Prasath

0 Kudos

Hi.

Hmm, since I am from Java world these things gets confusing in ABAP. If you see the following example then the report will print both 1 and 2. So the variable is both "initial" as well as "space".



DATA: lv_test TYPE flag.
lv_test = '0'.
CLEAR lv_test.

IF lv_test EQ space.
  WRITE '1'.
ENDIF.
IF lv_test IS INITIAL.
  WRITE '2'.
ENDIF.

Best Regards

Niklas

0 Kudos

Hi,

i hope you have understood my requirement. NULL Value is different from INITIAL and SPACE. You can set NULL Value to a ABAP Variable using a special Clear Syntax. "Clear xyz WITH NULL"

After doing this if you execute your code it will NOT return either 1 or 2.

Hope you understand.

If you anyone can help me in finding Class's NULL Constant,

It will be helpful.

Regards

Prasath

Message was edited by:

Prasath Kumar R

0 Kudos

I think this addition of NULL vlaue in the CLEAR statement will do the same thing but in different way, byte mode.

Regards,

Naimesh Patel

0 Kudos

Hi Patel,

But, I cannot use this in OO Context, I want to use some other class constant

or variable to achive this. Hope you understand my requirement.

Regards

Prasath

0 Kudos

hi prashant

May be by destoying the object using its detroy method you can create a null refrence

matt
Active Contributor
0 Kudos

CLEAR WITH NULL is totally irrelevant. You don't need a null constant, and, to my knowledge, no such constant exists.

DATA: myobjref TYPE REF TO myclass.

CREATE myobjref.
CLEAR myobjref.

As it says in the ABAP help for CLEAR: "<b>Reference variables are assigned null references</b>."

I.e. you create a null reference by using CLEAR.

matt

matt
Active Contributor
0 Kudos

> Hi.

>

> Hmm, since I am from Java world these things gets

> confusing in ABAP. If you see the following example

> then the report will print both 1 and 2. So the

> variable is both "initial" as well as "space".

>

>


> 
> DATA: lv_test TYPE flag.
> lv_test = '0'.
> CLEAR lv_test.
> 
> IF lv_test EQ space.
>   WRITE '1'.
> DIF.
> IF lv_test IS INITIAL.
>   WRITE '2'.
> DIF.

>

> Best Regards

> Niklas

That's because the initial value of a character field is SPACE. In the same way, the initial value of an integer field is 0. Again, looking at the ABAP help:

Type    Initial Value 
b       0 
c       " " for every position 
d       "00000000" 
f       0 
i       0 
n       "0" for every position. 
p       0 
string  empty string of length 0 
s       0 
t       "000000" 
x       hexadecimal 0 
xstring empty string of length 0. 

matt

0 Kudos

No you are wrong. The initial value of an integer is also SPACE (as well as initial and in fact '0').

Isn't that confusing? Because I totally agree with you, SPACE should only be possible with characters...

My only point was that for the terms SAP use it is not always obvious what they do.

Best Regards

Niklas

matt
Active Contributor
0 Kudos

> No you are wrong. The initial value of an integer is

> also SPACE (as well as initial and in fact '0').

DATA: i TYPE i.

WRITE: i.

Result: 0. Also in debug, value of i is 0.

When you do

i = space.

, or you do a comparison of i with space, you get a conversion of space to 0. But that does not mean the initial value of i is space.

matt

Former Member
0 Kudos

Hi,

since I found no answer I was happy with, here's my take.

I was looking for a way to pass null reference argument into a method parameter without needing to declare separate variable. I like languages like Scala that use quite complex language constructs, so you can write comples function calls inline. Since ABAP 7.40, this can be done inline. Introduction of constructor expressions made it possible.

Before ABAP 7.40:

DATA null TYPE REF TO some_class.

CALL METHOD class->method EXPORTING parameter = null.

With ABAP 7.40:

method( VALUE #( ) ).

That's it. VALUE #( ) creates a "null reference" in places of object references - {O:INITIAL}. # means to use type inference. More here: .

David