Skip to Content
Former Member
Feb 12, 2008 at 03:50 AM

Problem with Internal Table - Get Field/Column names


Hi all you ABAP experts!

I have an Internal Table with around 45 fields and want to concatenate all of them into a string separated by a character (specified by the user at selection screen). Well I was trying to get all the field names into an internal table then loop at that table with the field names and for each field get its value an concatenate it.

I tried to use the FM 'CACS_GET_TABLE_FIELDS' but unfortunely it only works with transparent tables so it is not working.

Here is the code I am using:

  " Get field names from extract internal table (it_extract)
    i_tabname     = 'it_extract' " it_extract is the name of my internal table
    t_nonkeyfield = it_fields.

  LOOP AT it_extract INTO wa_extract. " For each record in extract table
    LOOP AT it_fields INTO wa_fields. " For each field of extract table
      CONCATENATE 'wa_extract' wa_fields-fieldname
        INTO sfield_name SEPARATED BY '-'.

      CLEAR cfield_value.
      WRITE (sfield_name) TO cfield_value.

      CONCATENATE wa_output_file-sline cfield_value
        INTO wa_output_file-sline
        SEPARATED BY cseparator.

    APPEND wa_output_file TO it_output_file. " Add to output file

That is basically the idea. If any of you have a better solution please let me know. I know I could concatenate field by field (for instance: wa_output-field1, wa_output-field2...) but I think there must be an easy way to do it without specifying the name of each field in hard code.

Many thanks in advance.