Skip to Content

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

Dynamic Column Value using Field Symbol

I have a requirement in which i need to access columns of an internal table dynamically, manipulate them using work area and update back onto the internal table.

The code looks something like this.

loop at it_table1.
if condition1 = '1'.
    lv_colname = 'col1'.
elseif condition2 = '2'.
    lv_colname = 'col2'.
elseif..
..
..
concatenate 'wa_itab-' lv_colname into lv_field.
assign (lv_field) to <fs_col>.
if <fs_col> is assigned.
   <fs_col> = <fs_col> + 1.
endif.
endloop.
append wa_itab to itab.

The above code gives a runtime error "Unable to Interpret as Number" as the field symbol doe not correspond to the correct datatype. I basically need to increase the value of a column dynamically by 1. Please suggest a way to do this.

Former Member
Former Member replied

Here is an example:

DATA : wa0001 TYPE pa0001.

wa0001-pernr = 1.

DATA : lv_pernr TYPE string VALUE 'pernr',
             lv_fs TYPE string.

FIELD-SYMBOLS : <fs> TYPE ANY.

CONCATENATE 'wa0001-' lv_pernr INTO lv_fs.

ASSIGN (lv_fs) TO <fs>.

IF <fs> IS ASSIGNED.

  <fs> = <fs> + 1.

ENDIF.

WRITE <fs>.

This is working fine...

KR

Veeranji Reddy P.

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