2006 Jun 10 1:35 PM
Hi!
I have a text field which may store a date or some text.
I need to validate if the contents of field is a valid date or not.
Is there a function module for the same?
Also what are the commonly used FM for date validations or conversions?
Thanks a lot.
Regards,
(Points will be awarded for help)
Hi!
I have a text field which may store a date or some text.
I need to validate if the contents of field is a valid date or not.
Is there a function module for the same?
Also what are the commonly used FM for date validations or conversions?
Thanks a lot.
Regards,
(Points will be awarded for help)
2006 Jun 10 1:54 PM
Use 'DATE_CHECK_PLAUSIBILITY' for date check
and
'CONVERT_DATE_TO_INTERNAL'
'CONVERT_DATE_TO_EXTERNAL'
for conversions.
Regds
Manohar
2006 Jun 10 1:55 PM
2006 Jun 10 5:09 PM
HI,
======================================================================
Description : This program has two macros and a sample code which is showing how to use that,.
Macro 1. > Val_date
Macro 2. > Valdate
It return SY-Subrc value if it 0 then the entered date
is valid else either the date is invalid or the specified format is invalid
*----
PROGRAM ZDATE_VALIDATE .
Validation of Date
DEFINE VAL_DATE.
CLEAR: %_DATE1,
%_DATE2.
%_DATE1(4) = &1. "Year
%_DATE1+4(2) = &2. "Month
%_DATE1+6(2) = &3. "Date
%_DATE2 = %_DATE1 - 1.
%_DATE2 = %_DATE2 + 1.
IF %_DATE1 <> %_DATE2.
SY-SUBRC = 1.
ELSE.
SY-SUBRC = 0.
ENDIF.
END-OF-DEFINITION.
DEFINE VALDATE.
***************************************************
Passing Parameters: &1 - Date
&2 - Date Format
*
Date Format:
DDMMYYYY MMDDYYYY YYYYMMDD YYYYDDMM
*
SY-SUBRC Return Value:
1 invalid date
0 Valid Date
2 Invalid Format
***************************************************
DATA: %_DATE1 LIKE SY-DATUM ,
%_DATE2 LIKE SY-DATUM ,
%_DATE3(8).
case &2.
when 'DDMMYYYY'.
val_date &14(4) &12(2) &1+0(2).
when 'MMDDYYYY'.
val_date &14(4) &10(2) &1+2(2).
when 'YYYYMMDD'.
val_date &10(4) &14(2) &1+6(2).
when 'MMYYYYDD'.
val_date &12(4) &10(2) &1+6(2).
when others.
sy-subrc = 2.
endcase.
END-OF-DEFINITION.
***********************************************
SAMPLE USE of above MACRO *
***********************************************
DATA: V_DATE(8).
V_DATE = '30022002'.
*=>
VALDATE V_DATE 'DDMMYYYY'.
*=>
IF SY-SUBRC = 0.
WRITE:/ 'Valid Date'.
ELSEIF SY-SUBRC = 1.
WRITE:/ 'Invalid Date'.
ELSEIF SY-SUBRC = 2.
WRITE:/ 'Invalid Format'.
ENDIF.
*********************************************************************
*-- End of Program
Hope you use this .....
Thanks
Sudheer
2006 Jun 10 6:22 PM
hi kulkarni..
you could use fm CONVERT_DATE_TO_INTERNAL for converting the date from external format say for eg.10.12.2005 to SAP format say for eg.20051210.
And you could use the fm CONVERT_DATE_TO_EXTERNAL for converting the date from internal format to external format.
Cheers,
Abdul Hakim
Mark all useful answers..