Skip to Content
-1

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

Aug 15, 2017 at 09:31 PM

128

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

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

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

Show 1 Share
10 |10000 characters needed characters left 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

0
Nic Teunckens Aug 16, 2017 at 01:53 PM
1

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

References :

  • SAP Blog on that Project : link
  • GitHub : link
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks, will get a look at it.

Regards,

Luis

0
avatar image
Former Member Aug 16, 2017 at 02:48 PM
0
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.
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Jay,

Thanks...

0