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: 

selct stmt with changing where condition

Former Member
0 Kudos

Hello All,

I got a req where i have to get records from a Single table where the where clause changes every time

how can i acheive this with a single hit on the table?

please help.

i.e,

select *

from (Table name)

where (Fieldname) = 1

select *

from (Table name)

where (Fieldname) = 2

6 REPLIES 6

naveen_inuganti2
Active Contributor
0 Kudos

Hi....

Declare one parameter...!!

Data: p_var like <table-field>.
select ....... where field = p_var.

you can give 1 or 2 or any.... in slection screen.... !

Thanks,

Naveen.I

Former Member
0 Kudos

Hi ,

You should use FIELD SYMBOLS in the place of fieldnames.

(Or)

If your intention is to relate several values for same field,

then yu can use SELECT-OPTIONS or RANGES and use

Select-options: s_var for table-field

Select ........... INTO TABLE ITAB FROM XTABLE

WHERE field IN S_VAR.

Bhupal

Former Member
0 Kudos

hi.

check this query

select * from mara into CORRESPONDING FIELDS OF table itab where matnr = '000000000000000007' or matnr = '000000000000000060'.

Former Member
0 Kudos

Hi,

Please go through the following link, this is covered as part of Dynamic Open SQL,

[http://www.susanto.id.au/papers/DynOpenSQL.asp]

This is even covered in SAP online help,

[http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3a1f358411d1829f0000e829fbfe/content.htm]

Former Member
0 Kudos

Please refer:

Former Member
0 Kudos

Firslty select the relative data from that table based on that field in an internal table now put a read to read your required result from that internal table as shown in example

Pass your whole data in range

Data : R type range .

move your data in a range

select *

from (Table name) into table itab

where (Fieldname) in r

(Tjhis gives you good performance)

Now Read itab based on your requirement

~hitesh