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

check a date validity

former_member246786
Participant
0 Likes
7,418

Hi there,

I would like to know how to check the validity of a date ?

By validity I does not mean "format" but the existence of the date in daily calendar (no need to check in enterprises calendars).

For example 12

Do you have any idea ?

thanks a lot

Regards

Morgan

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,305

REPORT ZTEST MESSAGE-ID Z1.

data: lv_date type sy-datum,

lv_msg(50) type c.

lv_date = '20051232'.

CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'

EXPORTING

DATE = lv_date

EXCEPTIONS

PLAUSIBILITY_CHECK_FAILED = 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 into lv_msg.

write: lv_msg.

ENDIF.

7 REPLIES 7
Read only

former_member156446
Active Contributor
0 Likes
3,305
PARAMETER: p_date TYPE sy-datum.

its being checked if its declared as sy-datum.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,305

Hello Morgan,

I will like to add to J@y's post if you declare the date as TYPE datum compiler automatically performs the check for you.

Hope i am clear.

BR,

Suhas

Read only

0 Likes
3,305

Hi,

thanks but I never tell that the dat was a parameter ... it's just a variable filled in from a file.

If I try to fill on a variable of type datum, it works but the date is not consistant ...

Read only

0 Likes
3,305

Check this conversation on a similar issue :

Read only

Former Member
0 Likes
3,305

Try FM DATE_CHECK_PLAUSIBILITY

Rob

Read only

Former Member
0 Likes
3,306

REPORT ZTEST MESSAGE-ID Z1.

data: lv_date type sy-datum,

lv_msg(50) type c.

lv_date = '20051232'.

CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'

EXPORTING

DATE = lv_date

EXCEPTIONS

PLAUSIBILITY_CHECK_FAILED = 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 into lv_msg.

write: lv_msg.

ENDIF.

Read only

Former Member
0 Likes
3,305

DATE_CHECK_PLAUSIBILITY :Check for the invalid date.

This function module checks if the date is in valid format for sap.

It also check if it is valid calender date or no.

So this should work for your requirement.

CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
     EXPORTING
          DATE                                         = p_date
     EXCEPTIONS
          PLAUSIBILITY_CHECK_FAILED   = 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 the value of Sy-subrc is 0 that means the date field has a valid value.

If the input is 01/01/2008 then the output of the above program is as follows.

Validate the date 0

If the input is 31/31/2008 then the output is as follows.

Validate the date 1

Regards,

Lalit Mohan Gupta.