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: 

Converting internal tables to .CSV - How to add header columns?

luis_rod
Participant
0 Kudos

Hi all,

I'm trying to convert an internal table to .CSV using the 'SAP_CONVERT_TO_CSV_FORMAT' function. How can I add the header (title) columns to the output table?

Thanks beforehand,

Regards,

Luis

1 ACCEPTED SOLUTION

Former Member

Pass I_LINE_HEADER = 'X' and add the header column/field names as the first row of the internal table.

6 REPLIES 6

Former Member

Pass I_LINE_HEADER = 'X' and add the header column/field names as the first row of the internal table.

0 Kudos

Sinu,

Thanks for your answer. I had already passed I_LINE_HEADER = 'X' without success. I did not imagine that the function was so restricted in its functionality.

I accept that's the way things are, nevertheless, it seems to me a little bit kludgy way to do things...

Thanks again,

Luis

NTeunckens
Active Contributor

If you want to take a different Approach, look into the "ABAP2XLSX" Project on GitHub ...

References :

  • SAP Blog on that Project : link
  • GitHub : link

0 Kudos

Thanks, will get a look at it.

Regards,

Luis

former_member156446
Active Contributor
0 Kudos
DATA: lo_struct_descr TYPE REF TO cl_abap_structdescr,

          lo_elem_descr   TYPE REF TO cl_abap_elemdescr,

          ls_line         TYPE string,

          lc_char         TYPE char40,

          lt_file         TYPE STANDARD TABLE OF string.

*-- Get RTTI object for the local structure

    lo_struct_descr ?= cl_abap_typedescr=>describe_by_name( iv_objtype ). " iv_objtype ----> table/structure name

*-- Get the components of the structure
    DATA(lt_struct_fields) = lo_struct_descr->get_components( ).

    LOOP AT lt_struct_fields INTO DATA(lwa_struct_field).
      lo_elem_descr ?= lwa_struct_field-type.
      DATA(long) = lo_elem_descr->get_ddic_field( )-scrtext_l. " Long text is used to fill the header line
*-- Prepare Unix file headings
      CONCATENATE ls_line long INTO ls_line SEPARATED BY iv_delim.
      CLEAR long.
    ENDLOOP.

*-- Append file header
    APPEND ls_line TO lt_file.
    CLEAR ls_line.

0 Kudos

Jay,

Thanks...