‎2014 Oct 20 3:50 AM
Hello development experts,
I am using "format input on/off" to allow user to input date & time from a reporting screen, i am looking for a simple method or function to validate the date & time. If you refer to my Abap coding below, there will be no control and user can enter everything (alphanumeric, symbol & etc) into these 2 fields. Can i have a suggestion or recommendation on how to put in the validataion check here (only valid date & valid time is allowed)?
……
………
WRITE: SY-VLINE NO-GAP.
POSITION 107.
FORMAT INPUT ON.
WRITE: TAB-S_DATE NO-GAP. “what is the simple way to validate date input
FORMAT INPUT OFF.
WRITE: SY-VLINE NO-GAP.
POSITION 118.
FORMAT INPUT ON.
WRITE: TAB-S_TIME NO-GAP. “what is the simple way to validate time input
FORMAT INPUT OFF.
WRITE: SY-VLINE NO-GAP.
………
…….
|X |PM.Order# |OrdCreated |PM.Description |Start Date |Str.Time|
|--+---------------+----------------+--------------------+--------------+-----------|
| |4600011 |30.08.2014 |test 123 |31.08.2014|12.12.12|
| |4600012 |24.09.2014 |test 456 |41.55.2014|09:69:10|
| |4600013 |13.10.2014 |test 789 |14.10.2014|13:11:07|
| |4600014 |15.10.2014 |test abc | | |
Best Regards,
alx
‎2014 Oct 20 5:39 AM
Hi,
you can use the functions DATE_CHECK_PLAUSIBILITY and L_MC_TIME_DIFFERENCE for this purpose.
for e.g.
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
date = s_date
EXCEPTIONS
plausibility_check_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE: / 'Invalid date'.
ELSE.
WRITE: / 'Correct date'.
ENDIF.
CALL FUNCTION 'L_MC_TIME_DIFFERENCE'
EXPORTING
DATE_FROM = s_date
DATE_TO = sydate
TIME_FROM = s_time
TIME_TO = sytime
IMPORTING
DELTA_TIME = timedif
* DELTA_UNIT =
EXCEPTIONS
FROM_GREATER_TO = 1
OTHERS = 2
IF sy-subrc <> 0.
WRITE: / 'Invalid time'.
ELSE.
WRITE: / 'Correct time'.
ENDIF.
‎2014 Oct 20 4:34 AM
Hi Alx,
You may use FMs CONVERT_DATE_INPUT and CONVERT_TIME_INPUT.
Regards,
Custodio
‎2014 Oct 20 5:39 AM
Hi,
you can use the functions DATE_CHECK_PLAUSIBILITY and L_MC_TIME_DIFFERENCE for this purpose.
for e.g.
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
date = s_date
EXCEPTIONS
plausibility_check_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE: / 'Invalid date'.
ELSE.
WRITE: / 'Correct date'.
ENDIF.
CALL FUNCTION 'L_MC_TIME_DIFFERENCE'
EXPORTING
DATE_FROM = s_date
DATE_TO = sydate
TIME_FROM = s_time
TIME_TO = sytime
IMPORTING
DELTA_TIME = timedif
* DELTA_UNIT =
EXCEPTIONS
FROM_GREATER_TO = 1
OTHERS = 2
IF sy-subrc <> 0.
WRITE: / 'Invalid time'.
ELSE.
WRITE: / 'Correct time'.
ENDIF.
‎2014 Oct 21 3:52 AM
Thanks Anish for the functions you recommended, exactly this is what i am looking for, DATE_CHECK_PLAUSIBILITY & TIME_CHECK_PLAUSIBILITYD, and it is solved now 🙂