07-27-2005 2:38 PM
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????
07-27-2005 2:43 PM
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
07-27-2005 3:16 PM
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
07-27-2005 2:44 PM
i don't think it's possible.
do the select. put the record in internal table and then loop to do the comparaison.
07-27-2005 2:59 PM
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
07-27-2005 4:06 PM
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