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: 

character date conversion to sap internal format

Former Member
0 Kudos

Hi ,

I want to convert character date to internal sap format

say I have chardate -- 25/07/2007

i have to convert it to sap Internal 20070725

thanks

bobby

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Bobby,

Since your Date format is not decided(xyz format), I think you need to decide your approach.

To dispaly the Date form System Format to User Format the FM 'CONVERT_DATE_TO_EXTERNAL' is used.

Consider this code.

REPORT zztest_arun_2.

DATA: e_date(10) type c VALUE '2/2/2006',

i_date(10).

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

date_external = e_date

IMPORTING

date_internal = i_date

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.

ENDIF.

WRITE : / 'CONVERT_DATE_TO_INTERNAL',

/ 'My Date:' , e_date ,

'Conv Date:', i_date.

skip 2.

CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

EXPORTING

DATE_INTERNAL = sy-datum

IMPORTING

DATE_EXTERNAL = e_date

EXCEPTIONS

DATE_INTERNAL_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.

ENDIF.

WRITE : / 'CONVERT_DATE_TO_EXTERNAL',

/ 'My Date:' , sy-datum,

'Conv Date:', e_date.

Thanks,

Reward If Helpful.

8 REPLIES 8

Former Member
0 Kudos

Hi Bobby,

Since your Date format is not decided(xyz format), I think you need to decide your approach.

To dispaly the Date form System Format to User Format the FM 'CONVERT_DATE_TO_EXTERNAL' is used.

Consider this code.

REPORT zztest_arun_2.

DATA: e_date(10) type c VALUE '2/2/2006',

i_date(10).

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

date_external = e_date

IMPORTING

date_internal = i_date

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.

ENDIF.

WRITE : / 'CONVERT_DATE_TO_INTERNAL',

/ 'My Date:' , e_date ,

'Conv Date:', i_date.

skip 2.

CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

EXPORTING

DATE_INTERNAL = sy-datum

IMPORTING

DATE_EXTERNAL = e_date

EXCEPTIONS

DATE_INTERNAL_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.

ENDIF.

WRITE : / 'CONVERT_DATE_TO_EXTERNAL',

/ 'My Date:' , sy-datum,

'Conv Date:', e_date.

Thanks,

Reward If Helpful.

Former Member
0 Kudos

Hi

DAY_OUT(4)     = DAY_IN+6(4).
DAY_OUT+4(2) = DAY_IN+3(2).
DAY_OUT+6(2) = DAY_IN(2).

Max

Former Member
0 Kudos

The FM CONVERT_DATE_TO_INTERNAL or CONVERT_DATE_TO_EXTERNAL will solve your purpose.

former_member582701
Contributor
0 Kudos

DATA: c_date(8) TYPE C.

CONCATENATE chardate6(4) chardate3(2) chardate+0(2) INTO c_date.

regards

Former Member
0 Kudos

Hi use this Logic..

date(10) = '25/07/2007.

day = date+0(2).

month = date+3(2).

year = date+6(4).

concatenate year month date into date1.

Reward All elpfull Answers..........

Former Member
0 Kudos

Hi,

Use the Function module CONVERT_DATE_TO_INTERNAL

Regards

Sudheer

Former Member
0 Kudos

Hi,

use this snippet in ur code

CONDENSE temp_date NO-GAPS.

STRLEN( temp_date ) EQ 10.

o_date0(4) = temp_date6(4).

o_date4(2) = temp_date3(2).

o_date6(2) = temp_date0(2).

Regards

Former Member
0 Kudos

*date --> your date.

data: w_date like sy-datum.

concatenate date6(4) date3(2) date+0(2) into w_date.

reward points if its helpful.