Skip to Content
-1

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

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 16, 2017 at 05:00 AM

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

    Add comment
    10|10000 characters needed characters exceeded

    • 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

  • Aug 16, 2017 at 01:53 PM

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

    References :

    • SAP Blog on that Project : link
    • GitHub : link
    Add comment
    10|10000 characters needed characters exceeded

  • Aug 16, 2017 at 02:48 PM
    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.
    Add comment
    10|10000 characters needed characters exceeded