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: 

Restrict Date Range

Former Member
0 Kudos
2,202

Hi All,

I have a select-option for Date.I need to restrict dates within a month??

How can i do that??

6 REPLIES 6

JozsefSzikszai
Active Contributor
0 Kudos
373

you should check if the months are the same :

AT SELECTION-SCREEN.
IF date-low+4(2) NE date-high+4(2).
==> different months
ENDIF.

Former Member
0 Kudos
373

Hi Mohan,

do it this way:

Select-options:
  s_date for sy-datum.

At Selection-screen on s_date.

    If s_date-high+4(2) NE s_date-low+4(2) or
       s_date-high+0(4) NE s_date-low+0(4).
       Message 'date range should be for same month' type 'E'.
    Endif.

With luck,

Pritam.

Former Member
0 Kudos
373

Hi ,

Same problem i also faced , so you will follow below code you will get the solution definately .

SELECT-OPTIONS : S_CALP FOR RFPDO1-SZISABRZ NO-EXTENSION obligatory , "date

DATA:

v_text TYPE STRING,

v_from_month TYPE STRING,

v_to_month TYPE STRING,

V_LEAP TYPE I . "leap year variable

  • From/To date validation

CLEAR : v_days .

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

EXPORTING

I_DATE_FROM = CALC_PERIOD_FROM "date low

I_DATE_TO = CALC_PERIOD_TO "date high

IMPORTING

E_DAYS = v_days.

  • From/To date validation

clear : v_text , v_to_month , V_YEAR ,V_LEAP.

v_text = CALC_PERIOD_FROM .

v_from_month = v_text+4(2).

clear : v_text .

v_text = CALC_PERIOD_TO .

v_to_month = v_text+4(2).

V_YEAR = v_text+0(4).

IF NOT V_YEAR IS INITIAL . "logic for leap year .

V_LEAP = V_YEAR MOD 4 .

ENDIF .

****logic for months validation

IF NOT v_from_month = v_to_month .

RETURN-MESSAGE = 'From/To Month should be same !'.

APPEND RETURN.

EXIT.

ENDIF .

IF ( v_to_month = '01' OR

v_to_month = '03' OR

v_to_month = '05' OR

v_to_month = '07' OR

v_to_month = '08' OR

v_to_month = '10' OR

v_to_month = '12' ) .

IF NOT v_days EQ 30 .

RETURN-MESSAGE = ' Please Enter Valid Date !'.

APPEND RETURN.

EXIT.

ENDIF .

ELSEIF ( v_to_month = '04' OR

v_to_month = '06' OR

v_to_month = '09' OR

v_to_month = '11' ) .

IF NOT v_days EQ 29 .

RETURN-MESSAGE = 'Please Enter Valid Date !'.

APPEND RETURN.

EXIT.

ENDIF .

ELSEIF v_to_month = '02' .

IF V_LEAP = 0 .

IF NOT v_days EQ 28 .

RETURN-MESSAGE = 'Please Enter Valid Date !'.

APPEND RETURN.

EXIT.

ENDIF .

ELSE .

IF NOT v_days EQ 27 .

RETURN-MESSAGE = 'Please Enter Valid Date!'.

APPEND RETURN.

EXIT.

ENDIF .

ENDIF .

ENDIF .

*****************************

Regards ,

Nilesh Jain .

Former Member
0 Kudos
373

Hi Madan,

USe this FM to get the interval bet dates , and then check the g_month if its >1 then throw a Message.

*Finding difference between dates

CALL FUNCTION 'HR_99S_INTERVAL_BETWEEN_DATES'

EXPORTING

begda = s_date-Low

endda = s_date-high

tab_mode = ' '

IMPORTING

c_months = g_month.

Amresh

Former Member
0 Kudos
373

You need to check years and days also..

Just checking the month wont suffice

AT SELECTION_SCREEN on s_date.

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'

EXPORTING

i_date_from = s_date-low

i_date_to = s_date-high

IMPORTING

E_DAYS = E_DAYS

E_MONTHS = E_MONTHS

E_YEARS = E_YEARS.

IF e_days <=31 and e_months = 0 and e_years = 0.

else.

Message 'Date Interval should be less than a month' TYPE 'E'.

ENDIF.

Regards,

Prashant

0 Kudos
373

I need a date range of 1 month in selection screen for every user other wise it should throw a error message.

So any solution yet?

Is that FM "FIMA_DAYS_AND_MONTHS_AND_YEARS" is working fine?