2023 Jun 16 12:19 PM
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!
2023 Jun 16 1:33 PM
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
2023 Jun 16 2:53 PM
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.
2023 Jun 21 3:50 PM
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.
2023 Jun 21 5:22 PM
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.