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: 

Problem with the WHERE condition

Former Member
0 Kudos

Hello Friends,

I have some problem with the where condition.

Within the method of my Class, I have written a select query.

select * from table TAB1 into table lt_TAB1 where FIELD1 = ls_STRUCTURE-FIELD1.

Here ls_STRUCTURE is getting filled in the method based on the screen fields. The User enters * in the screen field FIELD1, then this query doesnt work. How to modify the query so that this works?

Thanks & Regards,

Raju

1 ACCEPTED SOLUTION

Former Member
0 Kudos

id do a ranges table.

if you leave a value blank in a where condition you will always get zero records.

if you have 0 entires in a ranges table your select will get you ALL records.

if you are using ranges tables (same as Select options) you have to use the WHERE IN statement

7 REPLIES 7

Former Member
0 Kudos

id do a ranges table.

if you leave a value blank in a where condition you will always get zero records.

if you have 0 entires in a ranges table your select will get you ALL records.

if you are using ranges tables (same as Select options) you have to use the WHERE IN statement

Former Member
0 Kudos

Hi,

Is TAB1 is Internal table or Database table. If the TAB1 is internal table then you should not use Select * then you need to use either Read table or the Loop at TAB1 statements. And in where condition pass a variable instead of giving strucutre field. decalare a varialbl then assign the value of ls_STRUCTURE-FIELD1 to varaible & pass it. e.g.:

variable = ls_STRUCTURE-FIELD1.

Read table TAB1 into table lt_TAB1 where FIELD1 = varaible.

OR

Loop at TAB1 where FIELD1 = varaible.

endlloop.

Reward points if helpful answer.

Ashvender

Former Member
0 Kudos

if ls_STRUCTURE-FIELD1 eq '*'.

concatenate ls_STRUCTURE-FIELD1 '%' into ls_STRUCTURE-FIELD1.

select * from table TAB1 into table lt_TAB1 where FIELD1 <b>like</b> ls_STRUCTURE-FIELD1.

else.

select * from table TAB1 into table lt_TAB1 where FIELD1 = ls_STRUCTURE-FIELD1.

endif.

Former Member
0 Kudos

do like this..

ranges : rfield1 for ls_STRUCTURE-FIELD1.

rfield1-low = ls_STRUCTURE-FIELD1.

rfield1-sign = 'I'.

if ls_STRUCTURE-FIELD1 ca '*'.

rfield1-option = 'CP'.

else.

rfield1-option = 'EQ'.

endif.

select * from table TAB1 into table lt_TAB1 where FIELD1 in rfield1.

regards

shiba dutta

former_member772790
Participant
0 Kudos

hi Narayana,

plz check the table with that entry (*). if it is existing then it will true.otherwise it is false.

-Pesi.

Former Member
0 Kudos

Hi Narayana,

view this code and use like instead of IN.

DATA: T_SFLIGHT LIKE SFLIGHT OCCURS 0 WITH HEADER LINE.

SELECT * FROM SFLIGHT INTO TABLE T_SFLIGHT WHERE CARRID = 'AZ' AND

CONNID IN ('0555', '0790') AND FLDATE LIKE '2004%'.

LOOP AT T_SFLIGHT.

WRITE: /,T_SFLIGHT-CARRID,T_SFLIGHT-CONNID.

ENDLOOP.

If useful rewrad me with points.

Thanks.

Sanket.

Former Member
0 Kudos

Hi Thanks all for the reply.

The problem is solved. I used the following code:

data: lt_search2 type

comt_prsearch_sel_option_tab,

ls_search2 type

comt_prsearch_sel_option.

ls_search2-low = ls_structure-FIELD1.

ls_search2-sign = 'I'.

if ls_structure-FIELD1 ca '*'.

ls_search2-option = 'CP'.

else.

ls_search2-option = 'EQ'.

endif.

append ls_search2 to lt_search2.

Thanks & regards,

Raju