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: 

How to assign value to a field in internal table dynamically

Former Member
0 Kudos

Hi all,

T_TEMP contains the fields

matnr, mng001, mng002 . . .mng0010.

Now i have to move a value to the MNG fields dynamically. Is it possible by field symbols.

do 10 times.

CONCATENATE 'T_TEMP-MNG0' l_val INTO l_tempstr.

l_tempstr = '400'.

enddo.

now the l_tempstr value only changes. But i want T_TEMP-MNG001 to be changed. Is it possible.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

dinesh's apporach is not bad, but

1. the structure' name cannot be part of the component

2. you need to make sure the component-name always is in upper case.

Try adapting the following code:

data: begin of wa_test,
          field01 type string,
          field02 type string,
          field03 type string,
       end of wa_test.

data:  l_fieldname  type string,
       l_counter    type string.

field-symbols: <testc> type string.

do 3 times.

  l_counter = sy-index.

  concatenate 'field0' l_counter into l_fieldname.
  translate l_fieldname to upper case.

  assign component l_fieldname of structure wa_test to <testc>.

  if <testc> is assigned.
    <testc> = 'any value'.
  endif.

enddo.

write / wa_test-field01.

best regards

5 REPLIES 5

Former Member
0 Kudos

Hi TRY using this way .

declare a workarea of type t_temp .

Field Symbol : <f1> type any .

do 10 times .

concatenate 'T_TEMP-MNG0' sy-index into v_}var

assign component v_var of structure wa_temp to <f1>.

<f> = '400'.

enddo.

Please reward if useful.

0 Kudos

Hi dinesh,

If value is assigned like this <f> = '400', only the field symbol value is getting changed and not the field. If possible could u mail me any example source code.

Former Member
0 Kudos

Hi,

dinesh's apporach is not bad, but

1. the structure' name cannot be part of the component

2. you need to make sure the component-name always is in upper case.

Try adapting the following code:

data: begin of wa_test,
          field01 type string,
          field02 type string,
          field03 type string,
       end of wa_test.

data:  l_fieldname  type string,
       l_counter    type string.

field-symbols: <testc> type string.

do 3 times.

  l_counter = sy-index.

  concatenate 'field0' l_counter into l_fieldname.
  translate l_fieldname to upper case.

  assign component l_fieldname of structure wa_test to <testc>.

  if <testc> is assigned.
    <testc> = 'any value'.
  endif.

enddo.

write / wa_test-field01.

best regards

0 Kudos

Hi Das,

Thank u very much for your clear explanation....Ur idea works fine.

Regards,

Vijay.

Former Member
0 Kudos

Hi Vijay ,

My reply was also same as Das Omen except without code.