Zdynamic Table
Zdynamic Table
la_comp-name = field_name.
*& For This Example we will build all field with type C and lenght
1024
la_comp-type = cl_abap_elemdescr=>get_c( p_length = 1024 ).
APPEND la_comp TO lt_comp.
CLEAR: la_comp.
ENDDO.
*&-------------------------------------------------------------------*& STEP. Three
*& Now we must create a Structure with all fields loaded before.
*&-------------------------------------------------------------------str_type = cl_abap_structdescr=>create( lt_comp ).
*& In this step we create a type table by using the structure
STR_TYPE,
*& and passing 2 Additional Parameters: p_table_kind (Standard,
Hashed, Sorted)
*& p_unique (this to indicate if have unique key or not)
tab_type = cl_abap_tabledescr=>create( p_line_type = str_type
p_table_kind =
cl_abap_tabledescr=>tablekind_std
p_unique
= abap_false ).
*&-------------------------------------------------------------------*& STEP: FOUR
*&-------------------------------------------------------------------*& Data to handle the new table type. We could catch an exception
here.
TRY.
CREATE DATA lt_data TYPE HANDLE tab_type.
CATCH cx_sy_create_data_error.
ENDTRY.
*&-------------------------------------------------------------------*& STEP: FIVE
*&-------------------------------------------------------------------*& New internal table referenced by field symbol
TRY.
ASSIGN lt_data->* TO <t_tab>.
CATCH cx_sy_assign_cast_illegal_cast.
CATCH cx_sy_assign_cast_unknown_type.
CATCH cx_sy_assign_out_of_range.
ENDTRY.
*&
at this point you will have a reference to your dynamic table type
BREAK-POINT.