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

Date range select option

0 Likes
4,129

Hello

I am stuck in a weird scenario where I need to find out all the users who are on holiday for those date entered.

I have a select option eg :- issue date ( date field ) .

I need to fetch all the records from a table where there are 2 fields i.e start date and end date . ( 2 different fields )

Below table for reference.

User || start date. || enddate

A. || 10.08.2020. || 15.08.2020

B. ||. 06.08.2020. ||. 08.08.2020

C. || 18.08.2020. || 20.08.2020

D. ||. 14.08.2020 ||. 17.08.2020

If user enters issue date = 13.08.2020 - 16.08.2020

Then user A and D should be shown.

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
3,628

A user should match the selection dates (SEL) or not as shown in this diagram:

----------------------------------------> TIME

        |---------|
            SEL

User is selected if his/her dates are like this:
|------------|
     |---------------|
             |------------|

User is not selected if his/her dates are like this:
|---|                   |--------------|

Let's say the selection dates are named SEL_START and SEL_END, and the column names are STARTDATE and ENDDATE.

So, the user is selected if STARTDATE <= SEL_END AND ENDDATE >= SEL_START

NB: your table better formatted:

User  start date  end date
----  ----------  ----------
A     10.08.2020  15.08.2020
B     06.08.2020  08.08.2020
C     18.08.2020  20.08.2020
D     14.08.2020  17.08.2020
6 REPLIES 6
Read only

Sandra_Rossi
Active Contributor
3,629

A user should match the selection dates (SEL) or not as shown in this diagram:

----------------------------------------> TIME

        |---------|
            SEL

User is selected if his/her dates are like this:
|------------|
     |---------------|
             |------------|

User is not selected if his/her dates are like this:
|---|                   |--------------|

Let's say the selection dates are named SEL_START and SEL_END, and the column names are STARTDATE and ENDDATE.

So, the user is selected if STARTDATE <= SEL_END AND ENDDATE >= SEL_START

NB: your table better formatted:

User  start date  end date
----  ----------  ----------
A     10.08.2020  15.08.2020
B     06.08.2020  08.08.2020
C     18.08.2020  20.08.2020
D     14.08.2020  17.08.2020
Read only

3,628

So If user enters in selection screen (1input )

S_date 13.08.2020 - 15.08.2020 ( single select option )

Query =

Select user from dbtable where startdate le s_date-high and end_date ge s_date-low

Thankyou Sandra this might get the job done .

Respectively if I can use s_date-low and high in my select query ,

Will try 2mrw

Read only

BiberM
Contributor
3,628

Are you sure that the select option is always exactly one date range to be inluded? A select option does offer a lot more possibilities.

Read only

BiberM
Contributor
0 Likes
3,628

Do you have a DB-Table which contains every possible date? You could Filter that with your select option and Join the result the way Sandra showed

Read only

matt
Active Contributor
0 Likes
3,628

Exactly. A select-option is often the wrong choice. How would you want the system to react if the user enters:

E BT 01.01.2020 31.01.2020

I EQ 01.02.2020

I GT 28.02.2020

Use two parameters instead. See my blog here: https://blogs.sap.com/2014/02/07/dates-and-select-options/

Read only

ponrajasekharan
Participant
0 Likes
3,628

Hi try this ,

select *
  from Z_TABLE 
  into  fields of table iITAB
  where ( begda <= LOWDATE and endda >= HIGHDAT ) or
        ( begda between LOWDATE and HIGHDAT and
          endda between LOWDATE and HIGHDAT )   or
        ( begda <= LOWDATE and
          endda between LOWDATE and HIGHDAT )   or
        ( begda between LOWDATE and HIGHDAT and
          endda >= HIGHDAT ).