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

Date field problem

Former Member
0 Likes
836

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
802

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.

6 REPLIES 6
Read only

Former Member
0 Likes
802

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.

Read only

Former Member
0 Likes
802

hi

change the format of date in Excel to

YYYY/MM/DD.

i think it will work

Cheers

Snehi

Read only

MarcinPciak
Active Contributor
0 Likes
802

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

Read only

0 Likes
802

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.

Read only

0 Likes
802

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.

Read only

Former Member
0 Likes
803

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.