Application Development and Automation 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: 
Read only

using 'format input on' how to validate date & time

Former Member
0 Likes
1,733

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,189

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.

3 REPLIES 3
Read only

custodio_deoliveira
Active Contributor
0 Likes
1,189

Hi Alx,

You may use FMs CONVERT_DATE_INPUT and CONVERT_TIME_INPUT.

Regards,

Custodio

Read only

Former Member
0 Likes
1,190

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.

Read only

0 Likes
1,189

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 🙂