08-04-2020 8:55 AM
Hey everyone,
i have an ITAB which i want to write into a CSV file.
The FM 'SAP_CONVERT_TO_CSV_FORMAT' works for that, but it formats the date as "YYYYMMDD", but i need "DD.MM.YY", and it also outputs a decimal point with ",", but i need "."
Is there a way to achieve this in a relatively simple way (without specifying each field individually etc.)?
Thanks in advance for the help!
08-04-2020 9:07 AM
Does the format used in the convertion correspond to the format specified in the user conf ? (trans SU3)
08-04-2020 9:15 AM
frdric.girod the Date yes, but it does not have a YYYYMMDD option
The decimal point doesnt work, the numbers come from S963FKMENG and S962-FKMENG btw
08-04-2020 9:20 AM
convert the date in the itab to the format before calling the csv format function.
write sy_datum to var_c_10 DD/MM/YYYY.
08-04-2020 9:30 AM
I recommend the string expression.
var_c_10 = |{ sy_datum DATE = USER }|.
I personally find this spelling mor legible and lighter.
08-04-2020 9:40 AM
skieyes i also really like string expressions, but would it work to say something like
<FS>-ERDAT = |{ <FS>-ERDAT DATE = USER }|.
Because i still have my table i want to turn into a CSV file, so i dont really want to mess with a lot of variables
Thanks and regards
08-04-2020 10:25 AM
Former Member, Ok if i understand you correctly you want the CSV Converter to do the date conversion. So you don't have to change your data elements at the date and can use their advantages. Hmmmm..... 🤔
Depending on the SAP release, there is the class CL_RSDA_CSV_CONVERTER.
This class is not FINAL and you can therefor inherit from it.
Then you could implement your logic for the date conversion.
08-04-2020 6:33 PM
08-05-2020 6:49 AM
Exactly nexago
I want something that works like this:
LOOP AT ITAB INTO DATA(WA).
TRANSFER WA TO DATASET ( DATE = 'YYYYMMDD' DECIMAL = '.' ).
ENDLOOP.
Is that possible?
08-04-2020 9:23 AM
I have wrote a complet solution to do what you request, but it is not a simple way.
As nexago proposed, the WRITE statement will used the FIELD-EXIT output convertion and format the text as you see on screen. So the SU3 conf will be used.
08-05-2020 9:51 AM
Ok now I think I understand why you don't want to do the formatting, because the property of the ITAB is a real date and you need a char10 to have it formatted. Can't you add an extra field to the structure (like CDATE). Or if you don't want to colums, change the first one to a char10? Than you can change the code where you fill the itab as mentioned with the write or the newer abap functionalities.
08-06-2020 1:42 AM
there is no such simple way. you dont have to deal with each column individually but you can check what is column data type is using RTTS class:
1. Loop itab in structure.
2. Assign each component of structure to a field symbol.
3. check if that component is a date or decimal => do the conversion.
4. concatenate result to a string to transfer latter.