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: 

Insert a line with field names in a tab delimited file

Former Member
0 Kudos

Hello Experts,

I am struggling in one scenarios in which I have to display field names along with data in a flat file which is tab delimited.

The data should appear like this

MATNR ERSDA ERNAM LAEDA

000000000005653681 20140927 Z0016CRX 00000000

000000000005653682 20140927 Z0016CRX 00000000

000000000005653683 20140927 Z0016CRX 00000000

000000000005653684 20140927 Z0016CRX 00000000

000000000005653685 20140927 Z0016CRX 00000000

000000000005653686 20140927 Z0016CRX 00000000

The problem is, that the select query is going to be dynamic and I would not have information from beginning about the fields which are required to be fetched and downloaded.

I have written code which would fetch the required data from the tables but the problem is, I am not able to insert a line containing field names in that table. This happens because the field symbols is of type STANDARD TABLE.

But it appears like this after all my efforts of adding a line with tab delimited.

MATNRERSDAERNAMLA.M.ERNAEDA. .
00000000000565368027.09.2014Z0016CRX00.00.0000
00000000000565368127.09.2014Z0016CRX00.00.0000
00000000000565368227.09.2014Z0016CRX00.00.0000
00000000000565368327.09.2014Z0016CRX00.00.0000
00000000000565368427.09.2014Z0016CRX00.00.0000

Is there a way out of this problem ?

Regards,

Jaydeep

1 ACCEPTED SOLUTION

Clemenss
Active Contributor
0 Kudos

Hi Jaydeep,

you wrote, that the select query is going to be dynamic. So you create a dynamic internal table, right?

The you can get the field names using RTTY.

Pass field-symbol of the table line and get a list of field names:

{code}

METHOD get_fields.

* IMPORTING is_any TYPE ANY   RETURNING rt_field TYPE FIELDNAME_TAB (or stringtable)

  DATA:

    lo_structdescr TYPE REF TO cl_abap_structdescr.

  FIELD-SYMBOLS:

    <component>   TYPE LINE OF abap_compdescr_tab.

  lo_structdescr ?= cl_abap_typedescr=>describe_by_data( is_any ).

  LOOP AT lo_structdescr->components ASSIGNING <component>.

    APPEND <component>-name TO rt_field.

  ENDLOOP.

ENDMETHOD.

* IMPORTING is_any TYPE ANY   RETURNING rt_field TYPE FIELDNAME_TAB (or stringtable)

{code}

Regards

Clemens

2 REPLIES 2

Clemenss
Active Contributor
0 Kudos

Hi Jaydeep,

you wrote, that the select query is going to be dynamic. So you create a dynamic internal table, right?

The you can get the field names using RTTY.

Pass field-symbol of the table line and get a list of field names:

{code}

METHOD get_fields.

* IMPORTING is_any TYPE ANY   RETURNING rt_field TYPE FIELDNAME_TAB (or stringtable)

  DATA:

    lo_structdescr TYPE REF TO cl_abap_structdescr.

  FIELD-SYMBOLS:

    <component>   TYPE LINE OF abap_compdescr_tab.

  lo_structdescr ?= cl_abap_typedescr=>describe_by_data( is_any ).

  LOOP AT lo_structdescr->components ASSIGNING <component>.

    APPEND <component>-name TO rt_field.

  ENDLOOP.

ENDMETHOD.

* IMPORTING is_any TYPE ANY   RETURNING rt_field TYPE FIELDNAME_TAB (or stringtable)

{code}

Regards

Clemens

Former Member
0 Kudos

Thanks a lot Clemens for your reply.

One of my friend suggested another way which I found to be very simple.

After the open data set statment, I pushed the header line in the internal file and then let the process push the normal data in tab delimited way.

This way, header was pushed before the main data and it appeared correctly in the output file too.

The problem got solved.

Thanks again for replying Clemens.