2017 Apr 03 11:53 AM
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
2017 Apr 03 12:52 PM
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
2017 Apr 03 12:52 PM
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
2017 Apr 03 5:32 PM
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
2017 Apr 04 1:26 PM
The Write statement uses the conversion exit if the data element is specified with the correct domain.
Rich
2017 Apr 03 12:52 PM
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?
2017 Apr 03 5:32 PM
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
2017 Apr 03 5:36 PM
"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.
2017 Apr 04 4: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,
2017 Apr 04 6:01 AM
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
2017 Apr 04 9:08 AM
2017 Apr 04 12:07 PM
2017 Apr 04 12:43 PM
2017 Apr 04 1:27 PM
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.