Skip to Content
avatar image
Former Member

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 09, 2007 at 11:28 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 09, 2007 at 08:20 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

  • avatar image
    Former Member
    Oct 10, 2007 at 11:33 AM

    Hi Vijay ,

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

    Add comment
    10|10000 characters needed characters exceeded