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: 

Get the Field count and value of a dynamic internal table

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Your approach is correct but use ASSIGN COMPONENT :

Please check with this code of lines;

loop at itab into <fs>. " Loop at the itab

DO. "Loop at <fs>. " Loop at the table-line

ASSIGN COMPONENT SY-INDEX OF <FS> INTO <F1>.

IF NOT SY-SUBRC IS INITIAL.

EXIT.

ENDIF.

ENDDO.

  • Read field value into <fs>-field " Get the value of the field

concatenate out_line '","' <F1> 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.

1 REPLY 1

Former Member
0 Kudos

Your approach is correct but use ASSIGN COMPONENT :

Please check with this code of lines;

loop at itab into <fs>. " Loop at the itab

DO. "Loop at <fs>. " Loop at the table-line

ASSIGN COMPONENT SY-INDEX OF <FS> INTO <F1>.

IF NOT SY-SUBRC IS INITIAL.

EXIT.

ENDIF.

ENDDO.

  • Read field value into <fs>-field " Get the value of the field

concatenate out_line '","' <F1> 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.