Skip to Content
-2

Date conversion using WRITE statement

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

date.jpg (104.9 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Apr 03, 2017 at 11:52 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 03, 2017 at 11:52 AM

    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?

    Add comment
    10|10000 characters needed characters exceeded

    • "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.

  • avatar image
    Former Member
    Apr 04, 2017 at 03:54 AM

    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,

    Add comment
    10|10000 characters needed characters exceeded