Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Dynamic programing

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:

INITIALIZATION.

CALL FUNCTION 'DB_GET_TABLE_FIELDS' "Returns the description of fields in a database table

EXPORTING

tabname = 'ZHR_INCENTIVE'

TABLES

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

ENDWHILE.

ENDLOOP.

Tags:
replied

Hi

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question