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

need help for sql query

Former Member
0 Likes
903

Dear all,

i have an input from selection-screen where user can choose a period of data,then the date is trigger by the below criteria

1. bwart ( movement type ) = 901,902,101,102,106,105 and lgort ( recieve location ) = L002

2. bwart ( movement type )= 311,312 and lgort = L001 or umlgo = L001

how should i code the above ? thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
804

Create a RANGES variable and append the data to that.

R_MVMT-SIGN = 'I'.

R_MVMT-OPTION = 'EQ'.

R_MVMT-LOW = '901'.

APPEND R_MVMT.

Do the same thing for the rest of the data as well.

SELECT * FROM TABLE

WHERE BWART IN R_MVMT AND LGORT =

L002'.

This select can be the other one, so append the other movement type values here.

SELECT * FROM TABLE

WHERE BWART IN R_MVMT AND ( LGORT = L002' or UMLGO = 'L001' ).

However I am not sure how are you planning to differentiate between those two statements and how exactly you want the data.

Regards,

Ravi

Note - Please mark all the helpful answers

7 REPLIES 7
Read only

Former Member
0 Likes
805

Create a RANGES variable and append the data to that.

R_MVMT-SIGN = 'I'.

R_MVMT-OPTION = 'EQ'.

R_MVMT-LOW = '901'.

APPEND R_MVMT.

Do the same thing for the rest of the data as well.

SELECT * FROM TABLE

WHERE BWART IN R_MVMT AND LGORT =

L002'.

This select can be the other one, so append the other movement type values here.

SELECT * FROM TABLE

WHERE BWART IN R_MVMT AND ( LGORT = L002' or UMLGO = 'L001' ).

However I am not sure how are you planning to differentiate between those two statements and how exactly you want the data.

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

gopi_narendra
Active Contributor
0 Likes
804

select EBELN EBELP MATNR WESBS BWART

from EKBE

into table IT_EKBE

where BWART in ('901,902,101,102,106,105')

and LGORT = 'L002'.

select EBELN EBELP MATNR WESBS BWART

from EKBE

into table IT_EKBE

where BWART in ('311,312')

and (LGORT = 'L002' or UMLGO = 'L001').

U can either do this way or create ranges for the BWART

R_BWART-SIGN = 'I'.

R_BWART-OPTION = 'EQ'.

R_BWART-LOW = 901.

append R_BWART.

R_BWART-SIGN = 'I'.

R_BWART-OPTION = 'EQ'.

R_BWART-LOW = 902.

append R_BWART.

R_BWART-SIGN = 'I'.

R_BWART-OPTION = 'EQ'.

R_BWART-LOW = 101.

append R_BWART.

R_BWART-SIGN = 'I'.

R_BWART-OPTION = 'EQ'.

R_BWART-LOW = 102.

append R_BWART.

and so on.......

select EBELN EBELP MATNR WESBS BWART

from EKBE

into table IT_EKBE

where BWART in R_BWART

and LGORT = 'L002'.

Regards

- Gopi

Read only

Former Member
0 Likes
804

Hi Joan

Not really sure of your requirement, whether the requirement is extract data w.r.t criteria 1 & 2 or only one basing on certaing condition???

Assuming you need only one w.r.t a certain date:

if p_date < l_date.

select .... from <table> into <itab> where bwart in ('901', '902', '101', '102', '106', '105') and lgort = 'L002'.

else.

select .... from <table> into <itab> where bwart in ('311', '312') and ( lgort = 'L001' or umlgo = 'L001').

endif.

Kind Regards

Eswar

Read only

0 Likes
804

thx ravi n gopi.

eswar, i need to extract data according to the 1 & 2 criteria..who shd i combine the two sql syntax together? thanks

Read only

0 Likes
804

If that is the case you can fire two different SQL statements to maintain the readability.

However, in the second select make sure you use the appending key word so that you don't over write the existing data.

1. SELECT ... into tab where ...

2. SELECT ... appending tab where ....

If you still want to combine both the selects

Have two ranges for the movement types and try the below statement.

SELECT * FROM TAB

WHERE ( (BWART IN R_MVMT1 AND LGORT = 'L002') OR

(BWART IN R_MVMT2 AND ( LGORT = 'L001' AND UWLOG = 'XXX' ) ) ).

Regards,

Ravi

Read only

0 Likes
804

thanks Ravi ^^

Read only

former_member186741
Active Contributor
0 Likes
804

where ( bwart in ( '901', '902', '101', '102' , '106' ,'105') and lgort = 'L002' )

or ( bwart in ('311', '312') and ( lgort = 'L001 or umlgo = 'L001' ) )