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: 

Dynamic programing

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

asik_shameem
Active Contributor
0 Kudos

Hi

Do like this.

DATA: gv_temp TYPE string.

FIELD-SYMBOLS: <fs_new> TYPE ANY.

CONCATENATE 'T_GOOD' <fs_comp> INTO gv_temp.

ASSIGN (gv_temp) to <fs_new>.

<fs_new> = <fs_dat>. " Here you can assign the value

7 REPLIES 7

asik_shameem
Active Contributor
0 Kudos

Hi

Do like this.

DATA: gv_temp TYPE string.

FIELD-SYMBOLS: <fs_new> TYPE ANY.

CONCATENATE 'T_GOOD' <fs_comp> INTO gv_temp.

ASSIGN (gv_temp) to <fs_new>.

<fs_new> = <fs_dat>. " Here you can assign the value

0 Kudos

I'm trying to move data to internal table daynamically. If you look my previous code you will see it. But I have problem getting internal table fields dynamically.

How can I get the internal table field name daynamicaly(t_good-<fs_comp>)?

ASSIGN COMPONENT <fs_comp> OF STRUCTURE w_infile TO <fs_dat>.

t_good-<fs_comp> = <fs_dat>. "This code is not compiling or working

Thanks

0 Kudos

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 Kudos

Hi

U need to use another field-symbols in order to move the data to structure:

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

* U need another field-symbols:
     ASSIGN COMPONENT <FS_COMP> OF STRUCTURE T_GOOD TO <FS_TAB>.
     <FS_TAB> = <FS_DAT>.

    ENDWHILE.
  ENDLOOP.

0 Kudos

Thank you <h4>Asik shameem,</h4> your answer really did solve my questions, I have really apreciated your prompt, quick and correct solution to my questions.

Than you very much.

0 Kudos

Thank you,

<h3>Max bianchi</h3> , Your answer was really helpfull.

Great people here

Cheers.

0 Kudos

You are welcome Hassan.