简体   繁体   English

具有多个内部表的ABAP CURSOR FETCH

[英]ABAP CURSOR FETCH with multiple internal table

I have a CURSOR below . 我在下面有一个游标。

OPEN CURSOR WITH HOLD s_cursor FOR
  SELECT * FROM (QUERY_TABLE)   WHERE (OPTIONS).

DO.

    FETCH NEXT CURSOR s_cursor APPENDING TABLE <lt_itab>  PACKAGE SIZE 100000.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
ENDDO.

Since I have huge data in the table , I need to split the data into multiple internal tables . 由于表中有大量数据,因此需要将数据拆分为多个内部表。 What want here is , need to pass different internal table for each FECTH . 这里要的是,需要为每个FECTH传递不同的内部表。

Also I need to create multiple internal table with the same structure . 另外,我需要创建具有相同结构的多个内部表。 Naming of internal table will be like below CONCATENATE 'Lt_ITAB' count INTO intname . 内部表的命名将类似于CONCATENATE 'Lt_ITAB' count INTO intname I should be able to create the internal table from the variable intname . 我应该能够从变量intname创建内部表。

Kindly provide some sample or logic . 请提供一些示例或逻辑。

Thanks in advance S Sukumar 在此先感谢S Sukumar

DATA tables TYPE STANDARD TABLE OF table_type WITH EMPTY KEY.

OPEN CURSOR WITH HOLD cursor FOR
  SELECT *
    FROM (db_table)
    WHERE (conditions).

WHILE sy-subrc = 0.
  INSERT NEW LINE INTO TABLE tables ASSIGNING FIELD-SYMBOL(<target_table>).
  FETCH NEXT CURSOR cursor APPENDING TABLE <target_table> PACKAGE SIZE 100000.
ENDWHILE.

Note that this doesn't make sense. 请注意, 这没有任何意义。 As Sandra Rossi points out, the idea of FETCH CURSOR is that the database stores much more data than ABAP's main memory can hold. 正如Sandra Rossi所指出的那样, FETCH CURSOR的想法是数据库存储的数据远远超过ABAP主存储器所能容纳的数据。 You want to retrieve all of that data into main memory anyway - if your data set is really huge, you will run out of memory anyway. 无论如何,您都希望将所有这些数据检索到主内存中-如果您的数据集确实很大,那么无论如何您都会用光内存。

If, on the other hand, your data set is small enough to fit into ABAP's main memory, you should instead load it in one go and apply a suitable packaging afterwards, as in 另一方面,如果您的数据集足够小以适合ABAP的主存储器,则应一次性加载它,然后使用合适的包装,如下所示:

SELECT * FROM (db_table) INTO TABLE (all_data) WHERE (conditions).
DATA(tables) = split_data_in_packages( data = all_data  package_size = 100000 ).

Also note that there is no way to create a set of lt_itab<count> variables dynamically. 另请注意, 无法动态创建一组lt_itab<count>变量。 My solution creates a table of tables instead, which can then be addressed conveniently with the [] index accessor as in lt_itab[ <count> ] . 我的解决方案改为创建一个表表,然​​后可以使用[]索引访问器方便地对其进行寻址,如lt_itab[ <count> ]

This answer focuses on the packaging aspect. 这个答案集中在包装方面。 There is another aspect in your question, with (db_table) being dynamic and you probably not being aware of the actual table type until runtime. 您的问题还有另一方面, (db_table)是动态的,您可能直到运行时才知道实际的表类型。 For these cases, you can refer to ABAP's Run-Time Type Interfaces (RTTI) and the CREATE DATA statement to determine and instantiate suitable data types. 对于这些情况,可以参考ABAP的运行时类型接口(RTTI)和CREATE DATA语句来确定和实例化合适的数据类型。

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

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