pondelok 30. januára 2012

Processing of Dynamically created table (with TYPE REF TO DATA).

The current post represents a method of how:
  1. to get reference of dynamically created internal table. The example suggest an internal table of type range, which structure consists of fields 'SIGN', 'OPTION', 'LOW', 'HIGH'.
  2. to get reference of dynamically created work area - based on a type of dynamically created internal table.
  3. to set fields of dynamically created work area with default values.
  4. to insert dynamically created work area to dynamically created internal table.
* Local variables:
  DATA:
      lref_table TYPE REF TO data,
      lref_wa    TYPE REF TO data.
  FIELD-SYMBOLS:
      <fs_table> TYPE ANY TABLE,
      <fs_wa>    TYPE ANY,
      <fs_field> TYPE ANY.

* Dynamically created table with the use of an class from WebDynpro ABAP:
* 'MINE RANGE' is defined as data element in Data Dictionary.
  lref_table = 
    lref_helper_class->create_range_table( i_typename = 'MINE_RANGE' ).
  FIELD-SYMBOLS <fs_table> type ANY TABLE.
  FIELD-SYMBOLS <fs_wa> TYPE any.
  data lref_wa TYPE REF TO data.


* Get reference of dynamic internal table
  ASSIGN lref_table->* TO <fs_table>.
* Create dynamic work-area for dynamic table
  CREATE DATA lref_wa LIKE LINE OF <fs_table>.

* Get reference of dynamic work area
  ASSIGN lref_wa->* TO <fs_wa>.





* Since we have dynamic RANGE table, work-are structure consists of components
* as 'SIGN' & 'OPTION' & 'LOW' & 'HIGH'.
  ASSIGN COMPONENT 'SIGN'   OF STRUCTURE <fs_wa> TO <fs_field>.
  <fs_field> = 'I'.
  ASSIGN COMPONENT 'OPTION' OF STRUCTURE <fs_wa> TO <fs_field>.
  <fs_field> = 'EQ'.
  ASSIGN COMPONENT 'LOW'    OF STRUCTURE <fs_wa> TO <fs_field>.
  <fs_field> = 'xxx'.



* Insert dynamic work-area into dynamic table
  INSERT <fs_wa> INTO TABLE <fs_table>.

A cl_alv_table_create with a method create_dynamic_table may be used to create internal table dynamically with predefined field-catalog.

Žiadne komentáre:

Zverejnenie komentára