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

WHERE clause in SELECT statement

Former Member
0 Likes
1,034

hi experts..

i want to give 'OR' condition in the 'where' clause of 'SELECT' statement.

is it possible?

for examlpe..

IF EXIDV2 IS NOT INITIAL.

SELECT * FROM YSDT_SHIPLOAD

INTO TABLE IG_SHIPLOAD

WHERE EXIDV2 = EXIDV2 AND

VHILM = PC1 OR PC2 OR PC3.

ENDIF.

i want that VHILM should be one of those three.

how can i do this?

thanks..

9 REPLIES 9
Read only

Former Member
0 Likes
989


IF EXIDV2 IS NOT INITIAL.
  SELECT * FROM YSDT_SHIPLOAD
  INTO TABLE IG_SHIPLOAD
  WHERE EXIDV2 = EXIDV2 AND
  ( VHILM = PC1 OR VHILM =  PC2 OR VHILM =  PC3 )
ENDIF.

Read only

siddhesh_pathak4
Contributor
0 Likes
989

Yes it is possible,

[https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes/sdn_oss_bc_db/~form/handler%7b5f4150503d3030323030363832353030303030303031393732265f4556454e543d444953504c4159265f4e4e554d3d393531343136%7d]

[http://help.sap.com/saphelp_nw04s/helpdata/en/b6/1bfb3f8c040d5fe10000000a155106/frameset.htm]

Read only

Former Member
0 Likes
989

use the IN condition

eg:

SELECT * FROM YSDT_SHIPLOAD

INTO TABLE IG_SHIPLOAD

WHERE EXIDV2 = EXIDV2 AND

VHILM in ( 'PC1','PC2','PC3' ).

or if you want to use OR

eg:

SELECT * FROM YSDT_SHIPLOAD

INTO TABLE IG_SHIPLOAD

WHERE EXIDV2 = EXIDV2 AND

( VHILM eq PC1 or VHILM eq PC2 or VHILM eq PC3 ).

Read only

Former Member
0 Likes
989

Hi,

First create range for VHILM as:

ranges: rg_vhilm for vhilm.

rg_vhilm-sign = 'I'.

rg_vhilm-option = 'EQ'.

rg_vhilm-low = 'PC1'.

append rg_vhilm.

rg_vhilm-low = 'PC2'.

append rg_vhilm.

rg_vhilm-low = 'PC3.

append rg_vhilm.

IF EXIDV2 IS NOT INITIAL.

SELECT * FROM YSDT_SHIPLOAD

INTO TABLE IG_SHIPLOAD

WHERE EXIDV2 = EXIDV2 AND

VHILM in rg_vhilm

ENDIF.

Thanks & Regards,

Anagha Deshmukh

Read only

former_member222860
Active Contributor
0 Likes
989

Tried it

SELECT * FROM YSDT_SHIPLOAD
INTO TABLE IG_SHIPLOAD
WHERE EXIDV2 = EXIDV2 AND
VHILM = PC1 OR 
VHILM = PC2 OR
VHILM = PC3.

Read only

Former Member
0 Likes
989

use 'in' like


IF EXIDV2 IS NOT INITIAL.
SELECT * FROM YSDT_SHIPLOAD
INTO TABLE IG_SHIPLOAD
WHERE EXIDV2 = EXIDV2 AND
VHILM in( PC1 ,PC2 ,PC3)
ENDIF.

that works same as or

and better in perfomance vise,\

Regards,

Alpesh

Read only

Former Member
0 Likes
989

Hi,

Check this from F1 help.

DATA spfli_tab TYPE TABLE OF spfli.

SELECT *

FROM spfli

INTO TABLE spfli_tab

WHERE cityfrom = 'FRANKFURT' AND

( cityto = 'LOS ANGELES' OR

cityto = 'SAN FRANCISCO' ).

Try to code like this:

IF EXIDV2 IS NOT INITIAL.

SELECT * FROM YSDT_SHIPLOAD

INTO TABLE IG_SHIPLOAD

WHERE EXIDV2 = EXIDV2 AND

( VHILM = PC1 OR VHILM = PC2 OR VHILM = PC3 ).

ENDIF.

Cheers,

Rudhir

Read only

Former Member
0 Likes
989

Hi -

Try this :

IF EXIDV2 IS NOT INITIAL.

SELECT * FROM YSDT_SHIPLOAD

INTO TABLE IG_SHIPLOAD

WHERE EXIDV2 = EXIDV2 AND

( VHILM = PC1 OR VHILM = PC2 OR VHILM = PC3 ).

ENDIF.

Read only

Former Member
0 Likes
989

Hi ,

its possible,

Select * from ysdt_shipload int table ig_shipload where exidv2 = exidv2

AND vhilm = pc1

OR vhilm = pc2

OR vhilm = pc3.

OR

Select * from ysdt_shipload int table ig_shipload where exidv2 = exidv2

AND (vhilm = pc1 or vhilm = pc2 or vhilm = pc3).

Regards

Arani Bhaskar

Edited by: arani bhaskar on Mar 16, 2009 5:14 PM