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

Comparing dates in select query.

Former Member
0 Likes
4,364

Hi Experts,

I need to select data from one table such that the date field of the table should be either today's date or earlier date.

How can I write such comparison statement in select query.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,197

Try with a query similar as below:

SELECT <fld1> <fld2> ...
  INTO TABLE <itab>
  FROM <TAB>
  WHERE <date> <= sy-datum
  ....

7 REPLIES 7
Read only

Former Member
0 Likes
2,198

Try with a query similar as below:

SELECT <fld1> <fld2> ...
  INTO TABLE <itab>
  FROM <TAB>
  WHERE <date> <= sy-datum
  ....

Read only

0 Likes
2,197

Thanks a lot Eswar . it's working.. Can u tell me how i can write "" for all entries in <itab>""" in the same. I

Edited by: Shridhar Patil on May 7, 2008 8:46 AM

Read only

0 Likes
2,197

Something like below???

SELECT <fld1> <fld2> ...
  INTO TABLE <itab>
  FROM <TAB>
  FOR ALL ENTRIES OF <itab1>
  WHERE <fld1> = <itab1>-fld1
  AND   <date> <= sy-datum
  ....

Read only

0 Likes
2,197

Hi Sridhar,

"For all entries" key word is used to interact with the more than one internal table.

Example program:

My requirement is to get the sales order numbers from given range of dates. For each sales order number

i need to get the available item numbers.

Program:

select-options: s_date for sy-datum.

Data: it_vbak type table of vbak with header line.(sales order header data),

it_vbap type table of vbap with header line.(sales order item infomration).

  • getting the sales order header data with in given range of dates

select * from vbak

into table it_vbak

where erdat in s_date.

  • getting the item data for each record in it_vbak using the "for all entries"

If not it_vbak[] is initial.

Select * from vbap

into table it_vbap

for all entries in it_vbak

where vbeln = it_vbak-vbeln.

endif.

when using for all entries we need to remember some condiitons:

1) We must check if the first internal table is empty or not. If we are we are not checking this

conditons: "If not it_vbak[] is initial".If first internal table is empty it extract all the data from the

database. It is very dangerous.

2) U make sure to poulate all the key fields in first internal table.

If it is helpful rewards points

Regards.

Eshwar.

Read only

0 Likes
2,197

Thanks Gurus....Problem is solved.

Read only

Former Member
0 Likes
2,197
select * from ur_table into i_table
where date_frm_table LE sy-datum

I hope it helps.

Let me know if any doubts.

Best Regards,

Vibha

Please mark all the helpful answers

Read only

Former Member
0 Likes
2,197

Hi,

today_date = sy-datum.

yesterday-date = sy-datum - 1.

select * from table

into table i_tab

where date = today_date

or date = yesterday_date.

Regards,

Shiva