Application Development and Automation 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: 
Read only

Checking for Empty string in WHERE condition

Former Member
0 Likes
11,526

Hi All,

I have a field with type sting in my database table, i need to get the records from database table where this string field is empty. I tried to use this string field in here condition and check if it is NULL or not. But it is not working because "Long string or text cannot be used in WHERE condition".

My Idea is to Copy this DB table into an Internal table, Loop through the internal table with where condition that string field is empty and append those records to another internal table.

Its working but i would like to know if there is any other way to do it.

My Code:


DATA: itab1 TYPE STANDARD TABLE OF DBtable,

          itab2 TYPE STANDARD TABLE OF DBtable,

          wa TYPE DBtable.

   

    SELECT * FROM DBtable INTO CORRESPONDING FIELDS OF TABLE itab1.

     

    LOOP AT itab1 INTO wa WHERE strfld is NOT INITIAL"strfld is string field.

     APPEND wa to itab2.

    ENDLOOP.

Thanks & regards,

NarsiReddy.

1 ACCEPTED SOLUTION
Read only

former_member206394
Active Participant
0 Likes
3,526

Dear NarsiReddy,

Greetings!

I feel using of 'Loop' on the itab might be at the cost of performance.  So, better use 'DELETE' statement after 'SELECT' statement.

SELECT * FROM <dbtable> INTO TABLE <itab1>.

DELETE TABLE <itab1> WHERE strfld is initial.

with this statement execution, <itab1> will have the entries for which String Field is not blank.

Regards,

Shankar

4 REPLIES 4
Read only

former_member206394
Active Participant
0 Likes
3,527

Dear NarsiReddy,

Greetings!

I feel using of 'Loop' on the itab might be at the cost of performance.  So, better use 'DELETE' statement after 'SELECT' statement.

SELECT * FROM <dbtable> INTO TABLE <itab1>.

DELETE TABLE <itab1> WHERE strfld is initial.

with this statement execution, <itab1> will have the entries for which String Field is not blank.

Regards,

Shankar

Read only

0 Likes
3,526

Hi Shankar,

Thank you, Perfect!

But a small correction, syntax is:


DELETE itab1 WHERE strfld IS INITIAL.

Kind regards,

NarsiReddy.

Read only

former_member206394
Active Participant
0 Likes
3,526

Dear NarsiReddy,

Greetings!

I feel using of 'Loop' on the itab might be at the cost of performance.  So, better use 'DELETE' statement after 'SELECT' statement.

SELECT * FROM <dbtable> INTO TABLE <itab1>.

DELETE TABLE <itab1> WHERE strfld is initial.

with this statement execution, <itab1> will have the entries for which String Field is not blank.

Regards,

Shankar

Read only

Former Member
0 Likes
3,526

Hi Naris,


Hope the below condition is helpful,


LOOP AT itab1 INTO wa WHERE strfld = '  '.




Regards,


Karthik