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: 

Select statement

Former Member
0 Kudos
96

Hello,

I have a problem with a select statement. I don't really know how to write it.

I wrote it like this:

SELECT DISTINCT marc~matnr

FROM marc

JOIN mara ON marcmatnr = maramatnr

...

where marc~mmsta NOT IN ('01','02','03')

<b>AND marc~mmstd >= sy-datum</b>

The problem is on the last line. That field may be empty and, in that case, this select should return the corresponding records. But, as I wrote the select, it doesn't work. Any ideea?

2 REPLIES 2

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos
58

If you need the records, that the MMSTD is initial as well you can try this.

.....
where marc~mmsta NOT IN ('01','02','03')
   AND (  marc~mmstd = '00000000'
       or marc~mmstd >= sy-datum ).

Regards,

Rich Heilman

Former Member
0 Kudos
58

Hi George,

You are checking the date in WHERE claus, so you have to pass the date..without that you wont get the result.

Still if you want the values eventhough you are passing date as empty. Then write separate select statement without where clause-Date checking.

<b>if p_date is initial.</b>

SELECT DISTINCT marc~matnr

FROM marc

JOIN mara ON marcmatnr = maramatnr.

where marc~mmsta NOT IN ('01','02','03')

<b>else.</b>

SELECT DISTINCT marc~matnr

FROM marc

JOIN mara ON marcmatnr = maramatnr

...

where marc~mmsta NOT IN ('01','02','03')

AND marc~mmstd >= <b>p_date.</b>

<b>endif.</b>

pls reward if it helps.

Thanks

Eswar