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: 

Date conversion using WRITE statement

kjyothiraditya
Participant
0 Kudos

Hi Experts,

In a report I need to convert date (YYYYMMDD) to another format DD/MM/YY using WRITE statement as below. For one of the record which has value 20170403 it is converting wrongly as 17/04/03. the conversion is done using as below.

WRITE lv_fkdat to lv_date DD/MM/YY.

The type of lv_date is declared as char8.

However for other records it is working fine. If I change the value in debugger, it is working correctly.

Thanks and Regards,

Aditya

1 ACCEPTED SOLUTION

former_member182550
Active Contributor

The Write statement will generally get things right (!) if the data has a domain that has a conversion exit attached to it and it's the type of lv_fkdat that you need to worry about.

If lv_fkdat has a dats type (sy-datum or whatever) then writing that will result in the correct format for the user. Otherwise have a look at the date convert function modules such as CONVERT_DATE_TO_EXTERNAL.

Rich

12 REPLIES 12

former_member182550
Active Contributor

The Write statement will generally get things right (!) if the data has a domain that has a conversion exit attached to it and it's the type of lv_fkdat that you need to worry about.

If lv_fkdat has a dats type (sy-datum or whatever) then writing that will result in the correct format for the user. Otherwise have a look at the date convert function modules such as CONVERT_DATE_TO_EXTERNAL.

Rich

0 Kudos

Hi Richard,

Thanks for your answer. Does it mean that the conversion routine takes precedence over the WRITE statement ?

It happened only with this test case. However for another date, if I changed the value, it is considering the WRITE statement format. Request you to help me understand this ambiguity.

Once again thanks foryour time.

Thanks and Regards,

Aditya

0 Kudos

The Write statement uses the conversion exit if the data element is specified with the correct domain.

Rich

horst_keller
Product and Topic Expert
Product and Topic Expert

The separators and the sequence depend on the formatting setting of the language environment that is predefined by fixed values in the user master record and can be influenced by SET COUNTRY. Is your result user dependend or is there any SET COUNTRY before WRITE TO?

0 Kudos

Hi Horst,

Thanks for your reply, but we are not using any user-specific setting or country speciifc formatting in the report.

It happened only with this test case. However for another date, if I changed the value, it is considering the WRITE statement format.

Once again thanks for your time.

Regards,

Aditya

horst_keller
Product and Topic Expert
Product and Topic Expert

"Thanks for your reply, but we are not using any user-specific setting or country speciifc formatting in the report."

Of course you do. Any WRITE statement using these date options does it - if not overridden by a conversion routine as Rich pointed out.

former_member200754
Participant

I'm not sure in your program contain any Set country or be effected from user profile.

Why don't you try to split to day month and year then combine the format that your want.

day = lv_from_date +6(2).

month = lv_from_date+4(2).

year = lv_from_date+2(2).

Thank,

Agreed - KISS principle: if one doesn't master ABAP, just use:

lv_date = |{ lv_fkdat+6(2) }/{ lv_fkdat+4(2) }/{ lv_fkdat+2(2) }|. " CCYYMMDD -> DD/MM/YY

0 Kudos

Use substring instead of +x(y)?

0 Kudos

+() is obsolete ? 🙂

0 Kudos

Substring is more obvious. I like obvious code.

0 Kudos

I prefer a structure - move your string to the struc and then read the components, or move your data to the components and read the string.