Skip to Content

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

How to assign value to a field in internal table dynamically

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.

Tags:
Former Member
Former Member replied

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 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question