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: 

Query about date comparison

Former Member
0 Kudos

Hi,

I have a database table with a date field called 'ENDDAT'

How do I write a select query that selects all records whose difference between sy-datum and 'ENDDAT' is greater than 7.

If I do the normal date comparison for eg.

select * from <databasetable> where enddat - sy-datum > 7

or

select * from <databasetable> where (enddat - sy-datum) > 7

It throws error that '-' is not a valid comparison operator.

Can anyone help????

5 REPLIES 5

Former Member
0 Kudos

data cdate type d.

cdate = sy-datum + 7.

select * from <databasetable> where enddat > cdate

Message was edited by: Svetlin Rusev

Sorry, I made a little mistake

0 Kudos

Hi,

try that:

data hdate type sy-datum.
hdate = sy-datum + 7.

SELECT        * FROM  bkpf into table itab
       WHERE  bukrs  = 1000
       AND    belnr  in belnr
       AND    gjahr  = sy-datum(4)
       AND    bldat > hdate.

Andreas

Former Member
0 Kudos

i don't think it's possible.

do the select. put the record in internal table and then loop to do the comparaison.

0 Kudos

I've never seen that done before. You can do as joseph has suggested. If you can do it in the select statement, I'm not really sure that you'd want to put that kind of processing on the database.



data: begin of itab occurs 0,
      enddat type sy-datum,
      end of itab.

select * into corresponding fields of table itab
       from <databasetable> .
data: cdatum type sy-datum.
Loop at itab.
cdatum = enddat - sy-datum
* if <= 7, then delete from itab.
if cdatum <= 7.
delete itab.
endif.
endloop.


Regard,

Rich Heilman

Former Member
0 Kudos

I think you have the solution already.

But just to clarify further,

It seems you have some oracle / other database background.

This kind of use in where condition is not possible in ABAP. You can only have one database column in left side of where condition. also in the right side you should use one varible.

Cheers,

Ram