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

How to select data within two dates..?

Former Member
0 Likes
2,465

Hi All

The scenario...

I am having two dates.. date1 = 20060105 and date2=20063105.

Now i need to select few fields from VBRK within these dates.

As per requirement, i should not use selection screen, so that user can easily input the above dates to get the data.

Can anybody provde me the SELECT code..???

How to write WHERE condition for this requirement..???

1 ACCEPTED SOLUTION
Read only

vinod_gunaware2
Active Contributor
0 Likes
2,361

Check sy-date format and use BETWEEN with Select query.

Regards

vinod

12 REPLIES 12
Read only

Former Member
0 Likes
2,361

Hi

Create a Ranage and Fetch the data based on the range.

Regards,

Baburaj

Read only

vinod_gunaware2
Active Contributor
0 Likes
2,362

Check sy-date format and use BETWEEN with Select query.

Regards

vinod

Read only

dani_mn
Active Contributor
0 Likes
2,361

HI,

SELECT * FROM VBRK

INTO TABLE itab

WHERE FKDAT GE date1 AND

FDDAT LE date2.

Regards,

WAsim Ahmed

Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
2,361

Hi,

RANGES : r_prodno FOR sy-datum.

MOVE: 'I' TO r_prodno-sign.

MOVE: 'EQ' TO r_prodno-option.

MOVE: 'BT' TO r_prodno-option.

APPEND r_prodno.

U can define the ranges as above.

And use the same in ur select statement.

Cheers,

Simha.

Read only

Former Member
0 Likes
2,361

Hi,

Use the foll code .

DATA : i_vbrk type vbrk occurs 0.

<b>

select * from VBRK into table i_vbrk where

ERDAT GE date1 and

ERDAT LE date2 .

</b>

Rgds,

Jothi.

Mark useful answers.

Read only

0 Likes
2,361

syntex is...

<b>Select * from test

where date between date1 and date2.</b>

Read only

0 Likes
2,361

2 options:

use erdat ge l_date1

and erdate le l_date2.

or

erdat between l_date1 and l_date2.

Reward points if it helps

Regards

Gunjan

Read only

Former Member
0 Likes
2,361

ranges : r_range like vbrk-FKDAT.

r_date-sign = 'I'.

r_date-option = 'EQ'.

r_date-low = '20060105'.

r_date-high = '20063105'.

select field1 field2

into itab

from VBRK

where datefieldname in r_date.

Read only

Former Member
0 Likes
2,361

use ranges ,

is the user enters atlest one data on screen..? or not..

plz let us know clearly..pls!!

Ramesh.

Read only

Former Member
0 Likes
2,361

Hi,

If u want to restrict the dates for current month,

then use this code..

data : lv_date(8) type c,

lv_month(2) type c,

lv_year(4) type c,

date1 type dats,

date2 type dats.

lv_month = sy-datum+3(2).

lv_year = sy-datum+0(4).

concatenate lv_year lv_month '01' into lv_date.

date1 = lv_date.

*Get the last date of the month.

CALL FUNCTION 'SG_PS_GET_LAST_DAY_OF_MONTH'

EXPORTING

day_in = date1

IMPORTING

LAST_DAY_OF_MONTH = date2

EXCEPTIONS

DAY_IN_NOT_VALID = 1

OTHERS = 2.

select * from VBRK where date1 >= '<date1>' and date2 <= '<date2>' .

Rgds,

Prakash

Read only

Former Member
0 Likes
2,361

Hello,

1. Create a ranges.

2. Prepare the range.

3. Access the range.

Ex:

RANGES <sel> FOR <f>.

Now,

clear <sel>

<sel>-option = 'I'.

<sel>-sign = 'BT'.

<sel>-low = 'XXXX'.

<sel>-high = 'YYYY'.

append <sel>.

Now use this range in the select query like,

select * from <ABC> where datab in <sel>.

Regs,

Venkat Ramanan

Read only

Former Member
0 Likes
2,361

Hi,

Try this,

SELECT * FROM VBRK INTO TABLE itab

WHERE FKDAT BETWEEN date1 AND date2.

Kind regards,

Thangesh