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: 

CLEAR STATEMENT

former_member630092
Participant
0 Kudos

HI EXPERTS

I AM BEGINNER TO ABAP. I HAVE ONE DOUBT IN CLEAR STATEMENT

CLEAR V1 [WITH V2 | WITH 'A' | WITH NULL].

PARTICULARLY THIS LINE

USING THE ADDITION WITH 'A', THE ENTIRE LENGTH OF V1 IS FILLED USING THE FIRST BYTE FROM LITERAL 'A'.

PLEASE EXPLAIN IT WITH SOME EXAMPLE .

AND HOW TO REWARD THE POINTS ?

THANKS

1 ACCEPTED SOLUTION

Former Member
0 Kudos

CLEAR dobj [ {WITH val [IN {BYTE|CHARACTER} MODE] }

| {WITH NULL} ].

Extras:

1. ... WITH val [IN {BYTE|CHARACTER} MODE]

2. ... WITH NULL

Effect

Without the optional additions, the data object dobj is assigned the type-specific initial value. The following applies:

The initial values are assigned to elementary data types according to the table of built-in ABAP types.

Reference variables are assigned null references.

Structures are set to their initial values component by component.

All rows in an internal table are deleted. All the memory required for the table, except for the initial memory requirement, is released (see Declaring Internal Tables). The FREE statement is used to release the memory space occupied by the rows of internal tables.

The optional additions allow you to fill the spaces of a data object with other values than the initial value.

Note

If dobj is an internal table with a header line, you must specify dobj[] to delete the rows, otherwise only the header line will be deleted.

Addition 1

... WITH val [IN {BYTE|CHARACTER} MODE]

Effect

If you use the WITH val addition and specify BYTE or CHARACTER MODE, all spaces are replaced either with the first byte or the first character in val. If dobj is of the type string or xstring (as of Release 6.10), the string is processed in its current length.

The IN BYTE and CHARACTER MODE additions can be used as of Release 6.10 (see also Processing Byte Strings and Character Strings). Without specification and before Release 6.10 the IN CHARACTER MODE addition applies. Depending on the addition, the data object dobj must be either byte-type or character-type and the data object val must be either byte-type or character type and have the length 1. Before Release 6.10, dobj and val must be flat. If dobj and val do not have the correct type and correct length in a non- Unicode program, they are still handled as if they do, independently of the actual type. In Unicode programs, this will cause a Syntax error or an exception that cannot be handled.

Example

The byte string hexstring as assigned a specific byte value over the entire current length.

DATA: hexstring TYPE xstring,

hex TYPE x LENGTH 1 VALUE 'FF'.

...

hexstring = '00000000'.

...

CLEAR hexstring WITH hex IN BYTE MODE.

Addition 2

... WITH NULL

Effect

This addition, which is not allowed in ABAP Objects, replaces all bytes of dobj with the value hexadecimal 0. In this case, the data object dobj must be flat.

Note

The WITH NULL addition should only be used for byte-type data objects and therefore be replaced with the CLEAR WITH val addition, which - in this context - at least ensures a higher level of security in Unicode programs.

5 REPLIES 5

Former Member
0 Kudos

CLEAR dobj [ {WITH val [IN {BYTE|CHARACTER} MODE] }

| {WITH NULL} ].

Extras:

1. ... WITH val [IN {BYTE|CHARACTER} MODE]

2. ... WITH NULL

Effect

Without the optional additions, the data object dobj is assigned the type-specific initial value. The following applies:

The initial values are assigned to elementary data types according to the table of built-in ABAP types.

Reference variables are assigned null references.

Structures are set to their initial values component by component.

All rows in an internal table are deleted. All the memory required for the table, except for the initial memory requirement, is released (see Declaring Internal Tables). The FREE statement is used to release the memory space occupied by the rows of internal tables.

The optional additions allow you to fill the spaces of a data object with other values than the initial value.

Note

If dobj is an internal table with a header line, you must specify dobj[] to delete the rows, otherwise only the header line will be deleted.

Addition 1

... WITH val [IN {BYTE|CHARACTER} MODE]

Effect

If you use the WITH val addition and specify BYTE or CHARACTER MODE, all spaces are replaced either with the first byte or the first character in val. If dobj is of the type string or xstring (as of Release 6.10), the string is processed in its current length.

The IN BYTE and CHARACTER MODE additions can be used as of Release 6.10 (see also Processing Byte Strings and Character Strings). Without specification and before Release 6.10 the IN CHARACTER MODE addition applies. Depending on the addition, the data object dobj must be either byte-type or character-type and the data object val must be either byte-type or character type and have the length 1. Before Release 6.10, dobj and val must be flat. If dobj and val do not have the correct type and correct length in a non- Unicode program, they are still handled as if they do, independently of the actual type. In Unicode programs, this will cause a Syntax error or an exception that cannot be handled.

Example

The byte string hexstring as assigned a specific byte value over the entire current length.

DATA: hexstring TYPE xstring,

hex TYPE x LENGTH 1 VALUE 'FF'.

...

hexstring = '00000000'.

...

CLEAR hexstring WITH hex IN BYTE MODE.

Addition 2

... WITH NULL

Effect

This addition, which is not allowed in ABAP Objects, replaces all bytes of dobj with the value hexadecimal 0. In this case, the data object dobj must be flat.

Note

The WITH NULL addition should only be used for byte-type data objects and therefore be replaced with the CLEAR WITH val addition, which - in this context - at least ensures a higher level of security in Unicode programs.

Former Member
0 Kudos

HI

refer this one.

clear <local variable.

you can reward points left side of this answer like 1.Sloved proble,2.vey helpfull answer 3.helpfull answer.chosse anyone as your sloved.

Reward all helpfull answers.

Regards.

Jay

Former Member
0 Kudos

Hi ravi,

Check out this:

DATA: hexstring TYPE xstring,

hex TYPE x LENGTH 1 VALUE 'FF'.

...

hexstring = '00000000'.

...

CLEAR hexstring WITH hex IN BYTE MODE.

Clear will intial value by FFFFFFFF

Reward can be given on left hand side radio button option under my name.

Reward if useful!

Former Member
0 Kudos

hi,

clear statement is generally used to clear the contents of workarea [header line] and also internal table body.

in your case clear statement will replace the existing content with 'A' as u gave WITH clause.

ex:

clear itab. -> clears the header line.

clear itab[] -> clears the records available in internal table body.

if useful reward some points.

with regards,

Suresh.A

former_member630092
Participant
0 Kudos

Answered