Skip to Content
0
Former Member
Jul 19, 2007 at 02:57 AM

Get the Field count and value of a dynamic internal table

414 Views

Hi,

In my case, I am trying to export a CSV file to the server with open dataset in a function module.

An internal table (itab) with different structure will be passed in to my FM.

I need to loop at the itab to read each line,

and then read each field value and concatenate into output_line.

This made the result to be a flat structure transfer to the open dataset for a new file.

I know that field-symbol can be used in the first loop of assigning lines of table to the field symbol <fs>. However, how can I get the value of each field?

Since the itab structure will be changed when passing different itab into the FM.

I cannot use <fs>-field_name to retrieve the data.

It is not a matter about what the data type is. Just need to concanate all the field values.

loop at itab into <fs>.    " Loop at the itab
  Loop at <fs>.              " Loop at the table-line
*       Read field value into <fs>-field                              " Get the value of the field
    concatenate out_line '","' <fs>-field into out_line         " Add Field value to output line
  endloop.
  concatenate '"' out_line '"' into out_line. " Formate the output line
  transfer out_line to csv_file.               " Write the output line to output file
endloop.