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: 

Date range needs to be set to selection screen select option limit to 60 days range

calvinkarlo
Explorer
0 Kudos
2,243

Hi All,

I am having selection-screen with select-option of type date.

selection-screen begin of block b1 with frame title text-001.
select-options: s_time for mseg-budat_mkpf OBLIGATORY DEFAULT '0' TO sy-datum.

selection-screen end of block b1.

is there a FM to calculate the date range? or logic that the program will throw error message if date range exceeds to 60 days?

data type is budat_mkpf and sy-datum.

Thank you!

4 REPLIES 4

raymond_giuseppi
Active Contributor
0 Kudos
2,146

You could restrict the select-options to a single range of value, then subtract range-low froim range-high in an integer field, add 1 to get number of calendar dates. Look for

matt
Active Contributor
2,146

Rather than use a select option, use two parameters; one for the start date, one for the end date. See my blog here for the rationale. Select options allow for all kinds of complicated selections - far more than is required for a simple date range.

PARAMETERS p_start TYPE mseg-budat_mkpf OBLIGATORY.
PARAMETERS p_end TYPE mseg-budat_mkpf OBLIGATORY.
...
AT SELECTION-SCREEN.
  DATA(diff) = p_end - p_start.
  IF diff GT 60 or diff LT 0.
    MESSAGE 'The date range must be between 0 and 60 days' TYPE 'E'.
  ENDIF.

Of course you can put the parameters in a line so it looks like a select option.

2,146

Also put both parameters in a BLOCK so the error message will allow to correct wrong input.

SELECTION-SCREEN BEGIN OF BLOCK daterange.
PARAMETERS p_start TYPE mseg-budat_mkpf OBLIGATORY.
PARAMETERS p_end TYPE mseg-budat_mkpf OBLIGATORY.
SELECTION-SCREEN BEGIN OF BLOCK daterange.
...
AT SELECTION-SCREEN ON daterange.
  DATA(diff) = p_end - p_start.
  IF diff GT 60 or diff LT 0.
    MESSAGE 'The date range must be between 0 and 60 days' TYPE 'E'.
  ENDIF.

adityaIngale
Active Participant
0 Kudos
2,146

Hi calvinkarlo,

You can try like below,

SELECTION-SCREEN BEGIN OF BLOCK b1.
SELECT-OPTIONS: s_budat FOR mseg-budat_mkpf OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN.

IF s_budat-high - s_budat-low > 60.
MESSAGE 'You have Entered Date Range more than 60 Days' TYPE 'E'.
ENDIF.