2012 Mar 16 1:06 PM
Hi ,
I am creating an CSV file using SAP_CONVERT_TO_CSV_FORMAT and gui_download...Say for example i have 5 fields separated by ' ; ' .Now i need to add empty space or Tab space for INITIAL fields.
I tried CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB , but not working . All my fields are char type .
How can i insert space in for empty fields in CSV file
Thanks,
Srini
2012 Mar 16 11:12 PM
Hi <cannot copy your name>
After converting using SAP_CONVERT_TO_CSV_FORMAT:
DATA:
lv_separator type string.
CONCATENATE
` `
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
` `
INTO lv_separator."or what ever you prefer
FIELD-SYMBOLS:
<ANY> TYPE ANY.
LOOP AT I_TAB_CONVERTED_DATA ASSIGNING <any>.
* REPLACE ALL OCCURRENCES OF ';;' WITH '; ;'. "OR
* REPLACE ALL OCCURRENCES OF ';;' WITH CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB. "OR
REPLACE ALL OCCURRENCES OF ';' WITH lv_separator.
ENDLOOP
Regards,
Clemens
2012 Mar 16 2:46 PM
Hi,
Unfortunately I think the FM SAP_CONVERT_TO_CSV_FORMAT does not care about spaces...
To do this I see two options: After calling SAP_CONVERT_TO_CSV_FORMAT and before calling GUI_DOWNLOAD, adapt you internal table accordingly (add spaces to initial fields).
Or do not use SAP_CONVERT_TO_CSV_FORMAT, but instead do the transformation by yourself (concatenate each field separated by ';' into a string table). This way you can really format your csv table the way you want.
Kr,
Manu.
2012 Mar 16 3:23 PM
You can try by checking if a field of the output internal table is initial or not, before you convert it to CSV.
Try putting up some code together like this:
DATA: BEGIN OF it_data OCCURS 0,
field1(10) TYPE c,
field2(10) TYPE c,
END OF it_data.
DATA: wa_data LIKE LINE OF it_data.
LOOP AT it_data INTO wa_data.
IF wa_data-field1 IS INITIAL.
wa_data-field1 = cl_abap_char_utilities=>horizontal_tab.
ENDIF.
IF wa_data-field2 IS INITIAL.
wa_data-field2 = cl_abap_char_utilities=>horizontal_tab.
ENDIF.
ENDLOOP.
2012 Mar 16 11:12 PM
Hi <cannot copy your name>
After converting using SAP_CONVERT_TO_CSV_FORMAT:
DATA:
lv_separator type string.
CONCATENATE
` `
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
` `
INTO lv_separator."or what ever you prefer
FIELD-SYMBOLS:
<ANY> TYPE ANY.
LOOP AT I_TAB_CONVERTED_DATA ASSIGNING <any>.
* REPLACE ALL OCCURRENCES OF ';;' WITH '; ;'. "OR
* REPLACE ALL OCCURRENCES OF ';;' WITH CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB. "OR
REPLACE ALL OCCURRENCES OF ';' WITH lv_separator.
ENDLOOP
Regards,
Clemens