Pesquisar este blog

segunda-feira, 13 de março de 2017

Select para tebelas com mais de 10.000.000 de registros.

Pessoal, uma vez necessitei processar uma tabela com mais de 10.000.000 de registros, para que isso funcionasse,  utilizei o select com a cláusula PACKAGE SIZE 10000.

Veja baixo.

FORM f_embaralhamento_liquidacao .

  DATA: v_count           TYPE i,
        v_count_aux         TYPE i,
        v_count_reguh_tot TYPE i,
        vl_index              TYPE sy-tabix,
        vl_index_a           TYPE sy-tabix.

  DATA: cur TYPE cursor.

  vl_index = 1.

  CLEAR: r_laufd, r_lifnr, r_kunnr.

* Dados de pagamento do programa de pagamento
  OPEN CURSOR WITH HOLD cur FOR

  SELECT * FROM reguh.

* Dados de pagamento do programa de pagamento

  DO.
    FETCH NEXT CURSOR cur INTO TABLE t_reguh
    PACKAGE SIZE 10000.

    IF sy-subrc <> 0.
      EXIT.
    ELSE.
      DESCRIBE TABLE t_reguh LINES v_count_reguh.
      v_count_reguh_tot = v_count_reguh_tot + v_count_reguh.
    ENDIF.

*   Altera REGUH conforme LFA1
    SORT: t_lfa1_a BY lifnr,

* Fornecedor

    LOOP AT t_reguh ASSIGNING <fsw_reguh>.

        READ TABLE t_lfa1_a INTO wa_lfa1_a WITH KEY lifnr = <fsw_reguh>-lifnr BINARY SEARCH.

        IF sy-subrc IS INITIAL.

          wa_reguh_a = <fsw_reguh>.
          wa_reguh_a-name1 = wa_lfa1_a-name1.
          APPEND wa_reguh_a TO t_reguh_a.

          DESCRIBE TABLE t_reguh_a LINES v_count_aux.

          IF v_count_aux = 1000.

            v_update_reguh = v_update_reguh + v_count_aux.
            CLEAR: v_count_aux.

            IF sy-subrc = 0.
               CALL FUNCTION 'DB_COMMIT'.
            ENDIF.

            CALL FUNCTION 'DB_COMMIT'.

            REFRESH: t_reguh_a.

          ENDIF.

*         Gravando log

          CLEAR t_change_bp.
          MOVE:
          wa_reguh_a-lifnr    TO t_change_bp-ven,
          wa_reguh_a-name1    TO t_change_bp-nome,
          <fsw_reguh>-name1   TO t_change_bp-nome_old,
*        'REGUH'              TO t_change_bp-tabela.
          APPEND t_change_bp.

      ENDIF.

    ENDLOOP.

    CLEAR: t_reguh.


*   Contador
    DESCRIBE TABLE t_reguh_a LINES v_count_aux.

    v_update_reguh = v_update_reguh + v_count_aux.
    CLEAR: v_count_aux.

    UPDATE reguh FROM TABLE t_reguh_a.
    IF sy-subrc = 0.
       CALL FUNCTION 'DB_COMMIT'.
    ENDIF.

  ENDDO.

  CLOSE CURSOR cur.

ENDFORM.

Nenhum comentário: