I'm trying to load data from flat file. The first line of the flat file is the field names(header names).
I'm storing the field names into wa_header then dynamically reading the value of the field from w_infile.
My question is, can I get the internal table field names dynamically (i.e t_good-<fs_comp> = <fs_dat>).
Any help or suggestion is highly received.
below is my code:
CALL FUNCTION 'DB_GET_TABLE_FIELDS' "Returns the description of fields in a database table
tabname = 'ZHR_INCENTIVE'
dbfields = lt_dbfields.
LOOP AT t_infile INTO w_infile.
WHILE sy-subrc = 0.
IF sy-index = 1. CONTINUE. ENDIF. "Do not process index 1
*wa_header holds the table headers such field names.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_header TO <fs_comp>.
READ TABLE lt_dbfields WITH KEY name = <fs_comp> INTO ls_dbfields.
ASSIGN COMPONENT <fs_comp> OF STRUCTURE w_infile TO <fs_dat>.
t_good-<fs_comp> = <fs_dat>. "This code is not compiling or working
Asik Shameem replied
For that only I am telling. Do in the following way.
DATA: gv_temp TYPE string. FIELD-SYMBOLS: <fs_new> TYPE ANY. CONCATENATE 'T_GOOD-' <fs_comp> INTO gv_temp. " Add '-' ASSIGN (gv_temp) to <fs_new>. " gv_temp will have T_GOOD-FIELD1 <fs_new> = <fs_dat>. " Now T_GOOD(work area or hearder) will have the value <fs_dat> APPEND T_GOOD. " Append the value to internal table