简体   繁体   English

从 ABAP 内存导入通用表?

[英]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.我想知道是否有可能以某种方式(从另一个程序)取回它,另外,虽然第一个程序至少知道我动态创建 itab 的表的名称,但第二个程序不知道.

Here's my code that exports my itab (which works :P ).这是我导出 itab 的代码(有效 :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 ).
  try.
      call method cl_abap_tabledescr=>create
        exporting
          p_line_type  = lo_struct
        receiving
          p_result     = lo_tabref
          .
    catch cx_sy_table_creation .
      message 'Couldn''t create the table description. Quitting' type 'E'.
  endtry.
  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.

endform.

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'.

in first program replace在第一个程序中替换

export itab from <gfs_tab> to memory id lv_memory_id.

with

cl_salv_bs_runtime_info=>set(
  EXPORTING
    display        = space
    metadata       = space
    data           = 'X'
).

cl_salv_bs_runtime_info=>set_data(
  EXPORTING
    data      = <gfs_tab>
).

In second program do like this:在第二个程序中这样做:

data lpt_data type ref to data.
cl_salv_bs_runtime_info=>get_data_ref(
    IMPORTING
        r_data            = lpt_data
).

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 .仅当您必须/想要使用某些无法更改以提供更好界面的其他程序时才使用此选项 - 或者在某些特殊情况下,例如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.这是 ABAP 的“遗留气味”部分之一,它现在很好用,但大部分时间你都可以不用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM