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: 

Selection Screen validation for date

Former Member
0 Kudos

Hi,

I have a date in Select option s_budat which is a mandatory field

The Criteria for validation is

1) The start date should not be older than current date minus 8 weeks. Otherwise error message should appear:

EN: Start date is older than 8 weeks

2)The end date should not be more than one week ahead of date-from. Otherwise error message should appear:

EN: Selection period is more than 1 week

please help me to solve this

regards

Avi

1 ACCEPTED SOLUTION

Former Member
0 Kudos
SELECT-OPTIONS: s_date LIKE sy-datum.

AT SELECTION SCREEN ON s_date.

IF NOT s_date[] IS iNITIAL.
v_date1 = sy-datum - ( 8 * 7 ).
IF s_date-low < v_date.
 message e000 with 'Start date is older than 8 weeks'.
ENDIF.

v_date2 = s_date-low + 7.
IF s_date-high > v_date2.
 message e000 WITH 'Selection period is more than 1 week'.
ENDIF.
 
ENDIF.
6 REPLIES 6

Former Member
0 Kudos

Hello Avi,

Try like this.

SELECT-OPTIONS: SO_ERSDA FOR MARA-ERSDA OBLIGATORY.

--- Initialization -


INITIALIZATION.

PERFORM INITIALIZATION.

FORM INITIALIZATION.

  • 004 vsm1kor 11.09.06 - en

DATA:

LR_ERSDA LIKE LINE OF SO_ERSDA.

LR_ERSDA-SIGN = 'I'.

LR_ERSDA-OPTION = 'BT'.

LR_ERSDA-LOW = SY-DATUM - 56(For 8 Weeks).

<b>Move LR_ERSDA-LOW to global variable</b> say LOW

LR_ERSDA-HIGH = SY-DATUM + 7.

<b>Move LR_ERSDA-HIGH to global variable</b> say HIGH

APPEND LR_ERSDA TO SO_ERSDA.

ENDFORM. " initialization

AT SELECTION-SCREEN ON SO_ERSDA.

PERFORM AT_SELECTION_SCREEN_SO_ERSDA.

FORM AT_SELECTION_SCREEN_SO_ERSDA.

LOOP AT SO_ERSDA.

IF SO_ERSDA-LOW NE LOW.

MESSAGE E551.

ENDIF.

IF SO_ERSDA-HIGH NE HIGH.

MESSAGE E551.

ENDIF.

ENDLOOP.

ENDFORM. " at_selection_screen_so_ersda

Hope this could solve ur problem.

Vasanth

Former Member
0 Kudos

Data:

zlv_8_weeks_ago type d,

zlv_period type i.

selection-screen begin of block b01.

select-options: s_budat for ....

selection-screen end of block b01.

at selection-screen on block b01.

zlv_8_weeks_ago = syst-datum - 56.

if s_budat_low lt zlv_8_weeks_ago.

message "Start date is older than 8 weeks"

endif.

zlv_period = s_budat-high - s_budat-low.

if zlv_period gt 7.

message "Selection period is more than 1 week"

endif.

Regards,

John.

Former Member
0 Kudos

execute the code .

TABLES :vbak.
SELECT-OPTIONS:so_erdat FOR vbak-erdat.

AT SELECTION-SCREEN ON so_erdat.

  DATA: date LIKE sy-datum,
        date1 LIKE sy-datum,
        cdate LIKE sy-datum.


  DATA: date2 LIKE sy-datum.
  DATA: cnt TYPE i.
  date2 = so_erdat-high.

  date = so_erdat-low. "start date.
  cdate = sy-datum. "current date


  CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
       EXPORTING
            date      = cdate
            days      = 56  "days subtrtd 8*7 = 56
            months    = 00
            signum    = '-'
            years     = 00
       IMPORTING
            calc_date = date1. " new date

*start-of-selection.
  WRITE:/ 'new date',  date1.

  IF date < date1. "8 weeks condition
    MESSAGE e999(zvij) WITH 'Start date is older than 8 weeks'.
  ENDIF.

  IF date2 NE '00000000'.
    cnt = date2 - date.

    IF cnt > 7 .
      MESSAGE e999(zvij) WITH 'Selection period is more than 1 week'.
    ENDIF.

  ENDIF.

let me know if this is working for u .

regards,

vijay.

Former Member
0 Kudos

Hello,

You can write the below logic in the AT-SELECTION SCREEN OUTPUT.

AT-SELECTION SCREEN OUTPUT.

if s_budat-low < ( sy-datum - 56 ).

' Error

endif.

lv_date = s_budat-low + 7.

if s_budat-high > lv_date .

' Error

endif.

Regs,

Venkat Ramanan N

Message was edited by:

Venkat Ramanan Natarajan

Former Member
0 Kudos
SELECT-OPTIONS: s_date LIKE sy-datum.

AT SELECTION SCREEN ON s_date.

IF NOT s_date[] IS iNITIAL.
v_date1 = sy-datum - ( 8 * 7 ).
IF s_date-low < v_date.
 message e000 with 'Start date is older than 8 weeks'.
ENDIF.

v_date2 = s_date-low + 7.
IF s_date-high > v_date2.
 message e000 WITH 'Selection period is more than 1 week'.
ENDIF.
 
ENDIF.

Former Member
0 Kudos

data : date1 like sy-datum,

date2 like sy-datum.

CALL FUNCTION 'HRWPC_BL_DATES_WEEK_INTERVAL'

EXPORTING

DATUM = sy-datum

WEEK_PST = 8

WEEK_FTR = 0

  • START_SUNDAY =

IMPORTING

BEGDA = tdate

ENDDA = tdate1

  • EXCEPTIONS

  • INVALID_VALUES = 1

  • OTHERS = 2

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

if s_date-low lt tdate.

message.

endif.

CALL FUNCTION 'HRWPC_BL_DATES_WEEK_INTERVAL'

EXPORTING

DATUM = s_date-low

WEEK_PST = 0

WEEK_FTR = 1

  • START_SUNDAY =

IMPORTING

BEGDA = tdate

ENDDA = tdate1

  • EXCEPTIONS

  • INVALID_VALUES = 1

  • OTHERS = 2

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

if s_date-high gt tdate1.

message.

endif.

regards

shiba dutta