How to convert a structure to an internal table dynamically in ABAP

非 Y 不嫁゛ 提交于 2019-12-12 14:33:43

问题


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.


回答1:


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.




回答2:


There is absolutely no need to use CL_ALV_TABLE_CREATE - pure overkill. Use the Run Time Type Services (RTTS) to get information about your input data (and validate your assumption about the component types), then use the dynamic form of CREATE TABLE:

* asssuming that l_type_name contains the type name of a single element
  CREATE DATA lr_table TYPE STANDARD TABLE OF (l_type_name).


来源:https://stackoverflow.com/questions/15235913/how-to-convert-a-structure-to-an-internal-table-dynamically-in-abap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!