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: 

Convert ITAB to CSV file with formatting options

Former Member
0 Kudos

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!

11 REPLIES 11

FredericGirod
Active Contributor
0 Kudos

Does the format used in the convertion correspond to the format specified in the user conf ? (trans SU3)

Former Member
0 Kudos

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

TheGokke
Active Participant

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.

I recommend the string expression.

var_c_10 = |{ sy_datum DATE = USER }|.

I personally find this spelling mor legible and lighter.

Former Member
0 Kudos

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

0 Kudos

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.

TheGokke
Active Participant
Andreas Blättler: that would have to be the biggest overkill of the month, just because he doesn't want to do his data formatting (3 or 4 lines of codes) 🙂

Former Member
0 Kudos

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?

FredericGirod
Active Contributor
0 Kudos

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.

TheGokke
Active Participant
0 Kudos

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.

DoanManhQuynh
Active Contributor
0 Kudos

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.