zoukankan      html  css  js  c++  java
  • SAP ABAP将大数据量排序后输入到内表

    要向内表读入3百50万条数据,如果一次读入就会产生运行错误,错误提示为,没有内存对于扩展 
    内表。 我考虑使用SELECT...INTO TABLE...PACKAGE SIZE 和ENDSELECT来解决这个问题,每次比 
    如只让10000条数据读入。第二次再让10000条数据读入等等。 现在我有个问题,对于3百50万 条 
    数据最后输出是应该有顺序的。 但是每次SELECT和ENDSELECT之中只能对10000条数据进行排序, 
    第二次循环又有10000条新的,并且代替了老的10000,这样导致了只能对内表的10000条数据进行 
    排序。

    You might do your sorting upon the database side. 

    Here are my two "forms" for your reference. If they don't work for you, mind letting 
    me take a look at your code here? 

    *&---------------------------------------------------------------------* 
    *&      Form  implicit_cursor 
    *&---------------------------------------------------------------------* 
    *       text 
    *----------------------------------------------------------------------* 
    FORM implicit_cursor. 
     DATA lt_billing TYPE TABLE OF zbilling. 

     SELECT * FROM zbilling INTO TABLE lt_billing 
       PACKAGE SIZE pk_size 
         WHERE vbeln   IN vbeln 
           AND aubel   IN aubel 
           AND erfdate IN erfdate 
           AND fkdat   IN fkdat 
          ORDER BY aubel aupos augrp erfdate DESCENDING erftime DESCENDING. 

       PERFORM process_data TABLES lt_billing. 
     ENDSELECT. 
    ENDFORM.                    "implicit_cursor 
    *&---------------------------------------------------------------------* 
    *&      Form  explicit_cursor 
    *&---------------------------------------------------------------------* 
    *       text 
    *----------------------------------------------------------------------* 
    FORM explicit_cursor. 
     DATA a_cursor TYPE cursor. 
     DATA lt_billing TYPE TABLE OF zbilling. 

     OPEN CURSOR a_cursor FOR 
       SELECT * FROM zbilling 
         WHERE vbeln   IN vbeln 
           AND aubel   IN aubel 
           AND erfdate IN erfdate 
           AND fkdat   IN fkdat 
           ORDER BY aubel aupos augrp erfdate DESCENDING erftime DESCENDING. 
     CHECK sy-subrc = 0. 

     DO. 
       FETCH NEXT CURSOR a_cursor INTO TABLE lt_billing 
         PACKAGE SIZE pk_size. 

       IF sy-subrc <> 0. 
         EXIT.  " done Fetch 
       ENDIF. 

       PERFORM process_data TABLES lt_billing. 
     ENDDO. 
     CLOSE CURSOR a_cursor. 
    ENDFORM.                    "explicit_cursor 


    谢谢你的回复。请看我的部分代码: 
    loop at g_t_grid into wa_g_t_grid. 
       s_grid-y = wa_g_t_grid-y. 
       s_grid-x = wa_g_t_grid-x. 
       s_grid-data = wa_g_t_grid-data. 
       if s_grid-data(1) = m1.                   "删除冒号 
       shift s_grid-data. 
       endif. 

       INSERT INTO zubpgrid VALUES  s_grid.   "运行错误在这里,以前我是直接把3百50万 
    数据插入到内表,现在我想用一个数据库来代替. 

     endloop. 

     refresh g_t_grid. 

     CLEAR s_grid. 

     SELECT * FROM zubpgrid INTO TABLE ii_grid PACKAGE SIZE 10000."这里从数据库倒入到内 
    表,并且限制每次的数量. 

    SORT ii_grid BY y. 
    LOOP AT ii_grid. 
        at new y.                         "行号 
         refresh i_quellzeile. 
       endat.                            "new y 



       i_quellzeile-x    = ii_grid-x. 
       i_quellzeile-data = ii_grid-data. 
       append i_quellzeile. 
       at end of y. 
    .....对属于同个行号的信息进行汇总. 
    ENDSELECT. 

    在这个案例中我觉得不需要cursor 和 fetch; 现在我需要整个内表都是有循序的,我想只要在 
    select后面加上order by y 就可以了.不只到是否正确.但是对于AT NEW y and AT END OF 
    y,应该在加入if语句,因为每次只要10000条数据进来,在下一次10000可能还有相同 
    Y 的信息. 
    请shaw1236帮我看看.谢谢.

    ==>在这个案例中我觉得不需要cursor 和 fetch; 现在我需要整个内表都是有循序的,我想只要 
    在select后面加上order by y 就可以了.不只到是否正确. 
    [Shaw1236] Yes. I think so. No explicit cursor is need. 
    I am not sure that you are able to loop table "ii_grid" by using "at new y" and "at 
    end of y" due to the package restriction. Can you simply use "on change of ii_grid- 
    y" after sorting(order by) data from the database? 




    下面是引用shaw1236于2008-4-7 19:20发表的回复:: 
    ==>在这个案例中我觉得不需要cursor 和 fetch; 现在我需要整个内表都是有循序的,我想只要 
    在select后面加上order by y 就可以了.不只到是否正确. 
    [Shaw1236] Yes. I think so. No explicit cursor is need. 
    I am not sure that you are able to loop table "ii_grid" by using "at new y" and "at 
    .......


    What's the length of each row? I think you will be fine. Probably you need check the 
    table technical setting and monitor the table space.


    Hi, 

    each row consists of x(int4 10), y( int4 10) and data(Char 73). I have set the 
    information about table technical Setting eg. Maximum data entries: 
    1,900,000 to 3,800,000 

    I am not sure if  an error for inserting in Databank table occurs?


    3500000 * (10 + 10 + 73) is roughly 310MB. 
    I think you will be fine. Ensure the table buffer is turned off. Just curious why 
    you save so much data into a z-table. 

    Maximum data entries: 1,900,000 to 3,800,000 is only a threshold number, which won't 
    absolutely block the size growing. 

    转自:http://11643599.blog.hexun.com/37289101_d.html

  • 相关阅读:
    渡一 5-1、2 条件语句补充,初识引用值,typeof,类型转换
    渡一 3-2 js基础知识
    渡一 25 正则表达式
    渡一 15-1 数组去重(上下)
    渡一 14-3 数组,类数组
    渡一 14-1&2 三目运算符,数组,类数组
    3_Guess Fingers
    2_Cat Years
    27_Blog Reader
    26_Json_Example
  • 原文地址:https://www.cnblogs.com/ruingy/p/3455355.html
Copyright © 2011-2022 走看看