01-09-2008 11:15 AM
I have a date coming from an upload file in internal format(ie yyyymmdd) . I need to validate it. Please help.
01-09-2008 11:16 AM
After uploading the data to internal table.
Validate with in the loop and endloop of that itab by taking each and every record.
Regards,
Satish
01-09-2008 11:16 AM
After uploading the data to internal table.
Validate with in the loop and endloop of that itab by taking each and every record.
Regards,
Satish
01-09-2008 11:17 AM
Hi,
use the Function Module DATE_CHECK_PLAUSIBILITY and pass your date field in the DATE parameter.
Reward if helpful,
Regards,
George
01-09-2008 11:18 AM
hi Jayesh,
DATE_CONV_EXT_TO_INT
Conversion of dates to SAP internal format e.g. '28.03.2000' -> 20000328 . Can also be used to check if a date is valid ( sy-subrc <> 0 )
DATE_CHECK_PLAUSIBILITY Check to see if a date is in a valid format for SAP. Works well when validating dates being passed in from other systems.
Hope this is helpful, Do reward.
01-09-2008 11:19 AM
======================================================================
Programme : zdate_validate *
Title : Macro to validate Date *
Author : Parminder *
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 *
----
Created and Designed by Parminder in Nov 2007. *
----
*Parminder is not responsible for any damages caused by the use or *
*misuse of this program and cannot provide any warranty with this *
*program. Use it entirely at your own risk. *
*
*You are not authorised to make any changes without prior written *
*permission from the author. *
======================================================================
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
Edited by: Parminder Singh Saluja on Jan 9, 2008 12:20 PM
01-09-2008 11:20 AM
Hi Jayesh,
First try to map the data which you get from the flat file with the data element used in the internal table. Here itself the validation should be done.
If the format is correct fine, else try to change the input format accordingly to the format of your data element.
Hope this will resolve your Query.
Reward alll the helpful answers.
Regards
Nagaraj T
01-09-2008 11:21 AM
Hi,
Declare that field as character type with length 10. Then use FM CY_CONVERT_DATE to convert it into current use format.
Regards,
Prashant
01-09-2008 11:21 AM
Hi,
subtract urdate from sy-date or sy-date from urdate and give some tolerance -365 or- 730.
Thanks and Regards