Many times while doing flat file load, the date in the csv file is given in the format DD.MM.YYYY. When this data is loaded to PSA, it will load without any error. But if we try to load this to further targets via DTP, it will throw invalid date error.
To solve this problem, editing date in the csv file prior to loading is not a practical solution as the file can be huge with many distinct values or there are large number of such files.
Here you need to use a function module in the transformation routine to convert the date in the internal format (YYYYMMDD).
In the transformation, for the target date field, select routine. Use function module ‘CONVERT_DATE_TO_INTERNAL’ as shown below-
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL' EXPORTING DATE_EXTERNAL = SOURCE_FIELDS-ZDATE * ACCEPT_INITIAL_DATE = "Comment this statement IMPORTING DATE_INTERNAL = RESULT EXCEPTIONS DATE_EXTERNAL_IS_INVALID = 1 OTHERS = 2 . IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF.
In this code, ZDATE is the dummy name given to the source field for date, you have to give your source field technical name here.
Also here you can use the ‘Pattern’ option from the top menu to get the syntax of the function module typed automatically.
This kind of error is mostly observed while loading flat files. We should check for any other date fields in the file and apply routine wherever applicable.