Skip to Content
0
Former Member
Jun 12, 2009 at 04:17 PM

Dynamic Internal Table creation and population

137 Views

Hi gurus !

my issue refers to the slide 10 provided in this slideshow : https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b332e090-0201-0010-bdbd-b735e96fe0ae

My example is gonna sound dumb, but anyway: I want to dynamically select from a table into a dynamically created itab.

Letu2019s use only EKPO, and only field MENGE.

For this, I use Classes cl_abap_elemdescr, cl_sql_result_set and the Data Ref for table creation. But while fetching the resultset, program dumps when fields like MENGE, WRBTR are accessed. Obviously their type are not correctly taken into account by my program.

Here it comes:

DATA: element_ref             TYPE REF TO cl_abap_elemdescr,
	 vl_fieldname	          TYPE string,
       	 tl_components         TYPE abap_component_tab,
       	 sl_components         LIKE LINE OF tl_components_alv,
 linetype_lcl          	TYPE REF TO cl_abap_structdescr,
 ty_table_type            TYPE REF TO cl_abap_tabledescr,
 g_resultset   		TYPE REF TO cl_sql_result_set

u2026

CONCATENATE sg_columns-table_name '-' sg_columns-column_name INTO vl_fieldname.
* sg_columns-table_name contains 'EKPO'
* sg_columns-column_name contains 'MENGE'


* getting the element as a component
element_ref ?= cl_abap_elemdescr=>describe_by_name( vl_fieldname ).

sl_components-name  = sg_columns-column_name.
sl_components-type ?= element_ref.

APPEND sl_components TO tl_components.


* dynamic creation of internal table
linetype_lcl = cl_abap_structdescr=>create( tl_components ).

ty_table_type = cl_abap_tabledescr=>create(
                  p_line_type = linetype_lcl ).


u2026


* Then I will create my field symbol table and line. Code has been cut here.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.

u2026

* Then I will execute my query. Here itu2019s: Select MENGE From EKPO Where Rownum = 1.
  g_resultset = g_stmt_ref->execute_query( stmt_str ).

* Then structure for the Resultset is set
  CALL METHOD g_resultset->set_param_struct
    EXPORTING
      struct_ref = dy_line.


* Fetching the lines of the resultset  => Dumpu2026
  WHILE g_resultset->next( ) > 0.
    ASSIGN dy_line->* TO <dyn_wa>.
    APPEND <dyn_wa> TO <dyn_table>.
  ENDWHILE.

Anyone has any clue to how prevent my Dump ??

The component for MENGE seems to be described as a P7 with 2 decimals. And the resultset wanna use a QUAN type... or something like that ! 😊