Application Development and Automation 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: 
Read only

Insert Space in CSV file

Former Member
0 Likes
3,171

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

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
1,074

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

3 REPLIES 3
Read only

Former Member
0 Likes
1,074

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.

Read only

Shafiq_Rehman1
Active Contributor
0 Likes
1,074

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.

Read only

Clemenss
Active Contributor
0 Likes
1,075

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