cancel
Showing results for 
Search instead for 
Did you mean: 

How to search in a table according to search criteria for many fields ??

simadri_sekhar
Participant
0 Kudos

Hello all,

I required any suggestion regarding easy method for searching a table according to search criteria.

I have 7 dropdown list in the userinterface and user can select 1 dropdown or many according to his choice. After selecting 1 or many dropdown list when he clicks SEARCH button the related records for filled dropdown list should be displayed if present in table. But the problem is that its getting complecated as I have to code for 7 dropdown list. many combinations comes in the way.

So can anybody tell me that how to getrid of this complicated process and is there any easy method for this...??

thanks,

Simadri

Accepted Solutions (1)

Accepted Solutions (1)

former_member184578
Active Contributor
0 Kudos

Hi.,

It wont get complicated., try this.,

Let us say you have 3 drop down lists., for ID, Name , Priority., now in OnActionSearch.,

DATA:RT_RANGES_ID TYPE RANGE OF ZDE_ID,  " Data Element for ID
          RS_RANGES_ID LIKE LINE OF RT_RANGES_ID,

          RT_RANGES_NAME TYPE RANGE OF ZDE_NAME, " Data Element for Name
          RS_RANGES_NAME LIKE LINE OF RT_RANGES_NAME,

          RT_RANGES_PRI TYPE RANGE OF ZDE_PRIORITY, " Data Element for Priority
          RS_RANGES_PRI LIKE LINE OF RT_RANGES_PRI.


*Read the Values in Drop down List using get_attribute( ).

now., 
*Appending ID to Range Table
if  lv_id is not initial.                              " here lv_id is the drop down value in Drop Down List for ID
   RS_RANGES_ID-OPTION = 'EQ'.
    RS_RANGES_ID-LOW    =  lv_id.    " appending ID
    RS_RANGES_ID-SIGN   = 'I'.
    APPEND RS_RANGES_ID TO RT_RANGES_ID.
endif.

if  lv_name is not initial.
   RS_RANGES_Name-OPTION = 'EQ'.
    RS_RANGES_NAME-LOW    =  lv_name.    " appending Name
    RS_RANGES_NAME-SIGN   = 'I'.
    APPEND RS_RANGES_NAME TO RT_RANGES_NAME.
endif.

if  lv_priority is not initial.
  RS_RANGES_PRI-OPTION = 'EQ'. 
    RS_RANGES_PRI-LOW    =  lv_priority.   " appending Priority
    RS_RANGES_PRI-SIGN   = 'I'.
    APPEND RS_RANGES_PRI TO RT_RANGES_PRI.
endif.


* Fetching Values for Selction Criteria
Select  * from <TABLE> into lt_int_tab where ID IN RT_RANGES_ID
                                                                 AND NAME IN RT_RANGES_NAME
                                                                 AND PRIORITY IN RT_RANGES_PRI.

similarly You do for your 7 Drop Downs..

hope this helps u.,

Thanks & Regards,

Kiran

simadri_sekhar
Participant
0 Kudos

hello kiran ,

thanks for ur reply. I used your suggestion and I successfully get the result but the thing is that when we used AND in the select query the user has to select that many values in the user screen. But if user want 1 or 2 or 3 selections then also the result should be displayed.

this is the main concern . so whether i have to write idividual conditions for each possible combination ?? please suggest something..

thanks,

simadri

simadri_sekhar
Participant
0 Kudos

hi kiran,

sorry for the question ur method solve my problem... thanks a lot.

points are on the way to your account

thanks,

simadri

simadri_sekhar
Participant
0 Kudos

Hi kiran,

I solved the [problem. but I cant understand that evenif the select statement uses AND operator it never failed .. means when out of two conditions 1 is correct and other is incorrect this should not be executed. but how it is excuted successfully.

please make me understand.

waiting for your reply.

thanks,

simadri

Former Member
0 Kudos

Hi,

AND means both should be true. Try by using OR condition.

Cheers,

Kris.

former_member184578
Active Contributor
0 Kudos

Hi.,

IN Operator in Select Query Works if the value in Range Table Exists it will Fetch that satisfying Condition., Please Debug and check you will understand the process..

hope this helps u.,

Thanks & Regards,

Kiran

simadri_sekhar
Participant
0 Kudos

thanks a lot kiran for ur valuable help..

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Sutar,

I think you have two ways to do this..

1. Create one internal table and fill this table with all 7 tables data( which you want to display ). And seggregate this data

based on dropdown in relevent tables and display. you have to read based on some key values.

2. You have to write 7 querys to get data based on dropdowns.

cheers,

Kris.

simadri_sekhar
Participant
0 Kudos

hi kissnas,

thanks for ur reply . Actually I fetched the datas from single table and not 7 tables... how to achieve this ,I knew but only thing is that its getting very complicated so is there any easy method to do this..??

thanks,

simadri

Former Member
0 Kudos

Hi Sutar,

You are fetching data from 1 database table and you wnat to display based on dropdowns in 7 tables right?

No need to display 7 tables. Display all your data in one table(in view ). Based on drope down values make INVISIBLE some

columns. What i eman to say is..

For example you have total 10 fields in databased table( main table ), and you want to display this data in 7 tables based on

dropdowns selection. suppose for 1st dropdown you want to display 3 fields visible those 3 fields only like that.

Create one attribute of type WDUI_VISIBILITY and bind this to all visible property of table columns.

Based on your dropdown selection VISIBLE your required columns using SET_ATTRIBUTE.

Hope it helps.

Cheers,

Kris.