itab-f1 = 2.
itab-f2 = 3.
itab-f3 = 4.
itab-f4 = 5.
APPEND itab.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form addfield
*&---------------------------------------------------------------------*
FORM. addfield TABLES itab
CHANGING tmp TYPE i.
DATA: BEGIN OF headtab OCCURS 0 ,
length TYPE i ,
decimals TYPE i,
type_kind TYPE c,
name(30) TYPE c,
END OF headtab.
DATA: sum TYPE i,
n TYPE i,
count TYPE i ,
count2 LIKE count,
descr_ref TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS: TYPE abap_compdescr .
FIELD-SYMBOLS TYPE ANY.
descr_ref ?= cl_abap_typedescr=>describe_by_data( itab ).
LOOP AT descr_ref->components ASSIGNING .
MOVE-CORRESPONDING TO headtab.
APPEND headtab.
ENDLOOP.
DESCRIBE TABLE headtab LINES n.
LOOP AT itab.
count = n.
DO count TIMES.
ASSIGN COMPONENT count OF STRUCTURE itab TO .
sum = sum + .
count = count - 1.
ENDDO.
total = total + sum.
CLEAR sum.
ENDLOOP.