Search code examples
structureabapinternal-tables

How to convert a structure to an internal table dynamically


I'm trying to create a method that will import a structure assuming that all structure elements are flat and the same data type. Then I want to convert it to a table with that type dynamically and return it. Where should I start? I've been trying to get this to work for several hours and am getting nowhere.


Solution

  • You can use the create_dynamic_table form using cl_alv_table_create like so:

    * Create dynamic internal table and assign to FS
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog  = ifc
          i_length_in_byte = 'X' "added by Paul Robert Oct 28, 2009 17:04
        IMPORTING
          ep_table         = dy_table.
      ASSIGN dy_table->* TO <dyn_table>.
    * Create dynamic work area and assign to FS
      CREATE DATA dy_line LIKE LINE OF <dyn_table>.
      ASSIGN dy_line->* TO <dyn_wa>.
    

    Here is a link that will help you get started.