Application Development 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: 

conversion of date field format from char to dats

Former Member
0 Kudos

Hi All,

one issue with Date field.

in my internal table i have a date field with type char(10).

But when I upload the data to database through upload program, there I have a date field with type "DATS".

how do I convert and store it in "DATS " format in database.

please help...

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI ,

Try this use CONVERT_DATE_TO_INTERNAl

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

date_external = "ur date from file

  • ACCEPT_INITIAL_DATE =

IMPORTING

DATE_INTERNAL = "( date in dats format )

  • EXCEPTIONS

  • DATE_EXTERNAL_IS_INVALID = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

8 REPLIES 8

Former Member
0 Kudos

Hi

U need to MOVE the date from CHAR field to DATs field:

DATA: DATE_C(10), DATE_D TYPE SY-DATUM.

MOVE DATE_C TO DATE_D.

It's important the date if CHAR field is in format YYYYMMDD

Max

Former Member
0 Kudos

Hi,

Day = date(2)

month = date+2(2)

Year = date+4(4)

then concanate year month day to date format.

Thanks.

0 Kudos

hi,

i have an entry in my internal table like:

01.01.2004 31.12.2006 of type char 10.

when i storing it in ztable(DB) its of type DATS.

so any sample code helps me.

0 Kudos

Hi

Just as I said u need to convert the date in internal forma YYYYMMDD, there are some function to do it, but it's easy and u can do it by yourself:

DATA: DATE_CHAR(10) TYPE C.

DATA: DATE_DATS TYPE SY-DATUM.

DATE_CHAR = '01.01.2004'.

DATE_DATS (4) = DATE_CHAR+6(4).

DATE_DATS 4(2) = DATE_CHAR+3(2).

DATE_DATS 6(2) = DATE_CHAR(2).

Max

0 Kudos

Hi, Try this way.


DATA: date_1 type char10 value '01.01.2004',
         date_2 type char10 value '31.12.2006'.
DATA: date_x type DATUM,
         date_y type DATUM.
concatenate date_1+6(4) date_1+4(2) date_1+0(2) into date_x.
concatenate date_2+6(4) date_2+4(2) date_2+0(2) into date_y.
Write:/ date_x, date_x.
Thanks Venkat.O

0 Kudos

hi Venkat,

I tried like this.

v_startdate(10).

in loop

I move my internal table entry to date1 like

move wa_cost-v_startdate to date1.

move wa_cost-v_enddate to date2.

CONCATENATE date_16(4) date_14(2) date_1+0(2) INTO date_x.

CONCATENATE date_26(4) date_24(2) date_2+0(2) INTO date_y.

MOVE date_x TO ztable-startdate.

MOVE date_y TO ztable-enddate.

modify ztable.

date format is not storing properly. output is coming as 20041.01.

please help.

0 Kudos

u can use convert_date_to_internal

Former Member
0 Kudos

HI ,

Try this use CONVERT_DATE_TO_INTERNAl

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

date_external = "ur date from file

  • ACCEPT_INITIAL_DATE =

IMPORTING

DATE_INTERNAL = "( date in dats format )

  • EXCEPTIONS

  • DATE_EXTERNAL_IS_INVALID = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.