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

Problem with the WHERE condition

Former Member
0 Likes
1,248

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
Read only

Former Member
0 Likes
1,223

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
Read only

Former Member
0 Likes
1,224

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

Read only

Former Member
0 Likes
1,220

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

Read only

Former Member
0 Likes
1,220

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.

Read only

Former Member
0 Likes
1,220

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

Read only

former_member772790
Participant
0 Likes
1,220

hi Narayana,

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

-Pesi.

Read only

Former Member
0 Likes
1,220

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.

Read only

Former Member
0 Likes
1,220

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