Importing a generic table from an ABAP memory?

I am exporting a dynamicaly created internal table to memory.

I'd like to know if it's possible to somehow get it back (from another program), with the addition that whereas the first program at least KNOWS the name of the table from which i dynamically created my itab, the second program doesn't.

Here's my code that exports my itab (which works :P ).

parameters: pi_tbl(5) type c obligatory.    "The table name - input from the user. can be jibberish.

data: gr_tabref type ref to data.
field-symbols:<gfs_tab> type any table. 

form create_dynamic_gr_tabref .
  data: lo_struct type ref to cl_abap_structdescr,
        lo_tabref type ref to cl_abap_tabledescr.
  lo_struct ?= cl_abap_typedescr=>describe_by_name( pi_tbl ).
      call method cl_abap_tabledescr=>create
          p_line_type  = lo_struct
          p_result     = lo_tabref
    catch cx_sy_table_creation .
      message 'Couldn''t create the table description. Quitting' type 'E'.
  create data gr_tabref type handle lo_tabref.

  assign gr_tabref->* to <gfs_tab>.

  select * from (pi_tbl) into table <gfs_tab> up to 200 rows.
  data: lv_memory_id(30) type c.
  lv_memory_id = 'MYMEMORYID'.

  export itab from <gfs_tab> to memory id lv_memory_id.


Can I get the data back only with parameter with the name of the table?

What I want is to declare a generic data type, and just poor the data into it, something like:

Object myObject; import itab to myObject memory id 'MYMEMORYID'.


  • For Tables: Yes, it can be done, but it shouldn't be done. One reason is that the user session will have to carry the data around unless you're very carefull to release the memory, another one is that this is a kind of hidden global (as in cross-program) variable which is usually a bad idea to introduce it into new programs. If you have control over both the caller and the called program, function module or class, there are better ways to transfer the data. Use this only if you have to / want to use some other program that you cannot change to provide a better interface -- or in some special cases like SUBMIT ... EXPORTING LIST TO MEMORY. This is one of the "legacy-smelling" parts of ABAP that it's good to now about, but that you can do without for most of the time.