Skip to end of metadata
Go to start of metadata

Author: Anirban Bhattacharjee
Submitted: 10-Sept-2008
Related Links:

Concept of RTTC

Steps to Create Type Dynamically

This code snippet is meant to create an internal table dynamicaly, data population into it and display its contains as simple report.

RTTC, namely Run Time Type Creation is a concept of creating any data type at runtime. The feature is introduced in SAP Web Application Server 6.40

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
REPORT z_rttc.
  p_tab TYPE dd02l-tabname .                  " Input data table name

  <fsym_itab> TYPE ANY TABLE,                 " Field symbol for internal table
  <fsym_warea> TYPE any,                      " Field symbol for work area
  <fsym_field> TYPE any.                      " Field symbol for field value

    TYPE REF TO cl_abap_structdescr,            " Rowtype ref to RTTS
    TYPE REF TO cl_abap_tabledescr.             " Internal table type ref to RTTS

  ref_wa TYPE REF TO data,           " Declaration of work area instance
  ref_itab TYPE REF TO data.                  " Declaration of internal table instance



* Create row type and tabletype by RTTC technique
  ref_rowtype ?= cl_abap_typedescr=>describe_by_name( p_tab ).
  ref_tabletype = cl_abap_tabledescr=>create( p_line_type = ref_rowtype ).

* Object type created by RTTC.
  CREATE DATA ref_itab TYPE HANDLE ref_tabletype.
  CREATE DATA ref_wa TYPE HANDLE ref_rowtype.

*Type assignment
  ASSIGN ref_itab->* TO <fsym_itab>.
  ASSIGN ref_wa->* TO <fsym_warea>.

* Value assignment to the internal table
    FROM (p_tab)
    INTO TABLE <fsym_itab>.

* Display Output
  LOOP AT <fsym_itab> INTO <fsym_warea>.
      ASSIGN COMPONENT sy-index OF STRUCTURE <fsym_warea> TO
      IF sy-subrc NE 0.
        NEW-LINE.                           " Shift Cursor to next line
        EXIT.                               " EXIT to next work area
      ENDIF.                              " IF sy-subrc NE 0.
      WRITE <fsym_field>.
  ENDLOOP.                            " LOOP AT <fsym_itab> INTO <fsym_warea>.

1 Comment

  1. Hi,

    How would you proceed to achieve similar goal before 6.40?

    Thanks in advance,