‎2008 Jun 23 2:41 PM
Hi All,
I am uploading the data from excel file to SAP database table.
But i am facing a problem with date field.
The source dates are 8/24/2004 9/9/9999 8/24/2004 in Excel sheet. But when they went into SAP Dtable they are appearing like /2/00/8/24 99/99/9/9/ /2/00/8/24.
I have taken same date fields as reference in declarations.
Thanks,
Subbu.S
‎2008 Jun 23 2:53 PM
Before saving the data to databse u should convert the dates into internal format using FM 'CONVERT_DATE_TO_INTERNAL' .
EX:
REPORT ZEXAMPLE.
TABLES: MARA, MDKP.
DATA V_DATE(30).
SELECT * FROM MARA UP TO 100 ROWS.
SELECT SINGLE * FROM MDKP WHERE MATNR EQ MARA-MATNR AND
BEADA NE '00000000'.
IF SY-SUBRC EQ 0.
V_DATE = MDKP-BEADA.
WRITE:/ 'DATE IN INTERNAL FORMAT:', V_DATE.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
DATE_INTERNAL = MDKP-BEADA
IMPORTING
DATE_EXTERNAL = V_DATE
EXCEPTIONS
DATE_INTERNAL_IS_INVALID = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
WRITE:/ 'DATE NOW IN EXTERNAL FORMAT:', V_DATE.
ENDIF.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
DATE_EXTERNAL = V_DATE
IMPORTING
DATE_INTERNAL = V_DATE
EXCEPTIONS
DATE_EXTERNAL_IS_INVALID = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
WRITE:/ 'DATE NOW BACK IN INTERNAL FORMAT:', V_DATE.
ULINE.
ENDIF.
ENDIF.
ENDSELECT.
‎2008 Jun 23 2:46 PM
During the upload you will have to do the translation of the Excel format to the SAP internal format yourself; just typing fields will not do!
Regards,
John.
‎2008 Jun 23 2:47 PM
hi
change the format of date in Excel to
YYYY/MM/DD.
i think it will work
Cheers
Snehi
‎2008 Jun 23 2:49 PM
Hi Subramanyam,
It is beacause SAP internal date format is YYYYMMDD
When you give him a date in this format it will go crazy;)
Change date in your spreadsheet and should be ok.
Regards,
Marcin
‎2008 Jun 23 3:08 PM
I can not change the date format in excel sheet. If i change in dev ok but in production system we coont change the excel file date field.
so i can change code only.
‎2008 Jun 23 3:22 PM
read your date into a Char field with a length of 10 and use this type logic.
DATA: in_date(10) VALUE '9/5/2008',
in_mm(2) TYPE n,
in_dd(2) TYPE n,
in_yy(4) TYPE n,
out_date TYPE d.
SPLIT in_date AT '/' INTO in_mm in_dd in_yy.
WRITE in_mm TO in_mm RIGHT-JUSTIFIED.
WRITE in_dd TO in_dd RIGHT-JUSTIFIED.
out_date+0(4) = in_yy.
out_date+4(2) = in_mm.
out_date+6(2) = in_dd.
translate out_date using ' 0'.
WRITE:/ out_date MM/DD/YYYY.
‎2008 Jun 23 2:53 PM
Before saving the data to databse u should convert the dates into internal format using FM 'CONVERT_DATE_TO_INTERNAL' .
EX:
REPORT ZEXAMPLE.
TABLES: MARA, MDKP.
DATA V_DATE(30).
SELECT * FROM MARA UP TO 100 ROWS.
SELECT SINGLE * FROM MDKP WHERE MATNR EQ MARA-MATNR AND
BEADA NE '00000000'.
IF SY-SUBRC EQ 0.
V_DATE = MDKP-BEADA.
WRITE:/ 'DATE IN INTERNAL FORMAT:', V_DATE.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
DATE_INTERNAL = MDKP-BEADA
IMPORTING
DATE_EXTERNAL = V_DATE
EXCEPTIONS
DATE_INTERNAL_IS_INVALID = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
WRITE:/ 'DATE NOW IN EXTERNAL FORMAT:', V_DATE.
ENDIF.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
DATE_EXTERNAL = V_DATE
IMPORTING
DATE_INTERNAL = V_DATE
EXCEPTIONS
DATE_EXTERNAL_IS_INVALID = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
WRITE:/ 'DATE NOW BACK IN INTERNAL FORMAT:', V_DATE.
ULINE.
ENDIF.
ENDIF.
ENDSELECT.