O Livro.
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.
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.
Utilização Import Export quando execução via job
Declarar a tabela indx.
Tables : indx. "Tabela de sistema índice
Programa 1
EXPORT
indx-aedat = sy-datum.
indx-usera = sy-uname.
EXPORT tab_interna TO SHARED BUFFER indx(zr) CLIENT sy-mandt ID 'T_LOG'.
Programa 2
IMPORT
indx-aedat = sy-datum.
indx-usera = sy-uname.
IMPORT tab_interna FROM SHARED BUFFER indx(zp) CLIENT sy-mandt ID 'T_LOG'.
IF sy-subrc = 0.
DELETE FROM SHARED BUFFER indx(zp) CLIENT sy-mandt ID 'T_LOG'.
ENDIF.
Tables : indx. "Tabela de sistema índice
Programa 1
EXPORT
indx-aedat = sy-datum.
indx-usera = sy-uname.
EXPORT tab_interna TO SHARED BUFFER indx(zr) CLIENT sy-mandt ID 'T_LOG'.
Programa 2
IMPORT
indx-aedat = sy-datum.
indx-usera = sy-uname.
IMPORT tab_interna FROM SHARED BUFFER indx(zp) CLIENT sy-mandt ID 'T_LOG'.
IF sy-subrc = 0.
DELETE FROM SHARED BUFFER indx(zp) CLIENT sy-mandt ID 'T_LOG'.
ENDIF.
domingo, 12 de março de 2017
Três programas ABAP para organizar o seu código ABAP
ABAP Clipboard Utilities for Beautiful Commented Code
" Any fool can write code that a computer can understand.
Good programmers write code that humans can understand. "
--- Martin Fowler, Refactoring: Improving the Design of Existing Code
ABAP pretty printer is good for code but not supportive for data declarations.
As a result ABAP code often tends to need more labour to maintain.
1- REPORT yclipjnc.
*&---------------------------------------------------------------------*
* based on ideas from
* http://sap.ionelburlacu.ro/abap/sap2/Beautify_Source_Code.html
* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc
*-----------------------------------------------------------------------
* This program takes ABAP code in ClipBoard, and does the following:
* - Attempts to move comments to the end of the line
* - Adds comments (table name) for the tables listed after a TABLES
* statement if the line has not been commented already.
* - Adds comments (field name) for data elements, parameters, and
* select-options that are defined using the LIKE or FOR statement
* - For ENDLOOP/ENDSELECT adds comment identify the LOOP/SELECT
* that is being closed
* - For FORM/ENDFORM adds comment identify the FORM that is being
* closed
* - Calls function PRETTY_PRINTER to do the SAP standard pretty print
* after the custom comments have been created
* Returns Modified Code Via ClipBoard
*-----------------------------------------------------------------------
2- REPORT yclip2jnc.
*&---------------------------------------------------------------------*
*& Beautify ABAP Code Via Clip
*&---------------------------------------------------------------------*
* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc
*-----------------------------------------------------------------------
* This program takes Structure & internal table declarations in ClipBoard,
* and does prefect alignment as possible
* Returns Modified Code Via ClipBoard
*-----------------------------------------------------------------------
3- PROGRAM yclip3jnc.
*&---------------------------------------------------------------------*
*& Beautiful Function Module Call via clipboard
*
*&---------------------------------------------------------------------*
* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc
*-----------------------------------------------------------------------
* This program takes a parameter as a Function Module Name
* and does a documented "pattern paste"
* Returns pattern Code Via ClipBoard
*-----------------------------------------------------------------------
Link para 3 programas
" Any fool can write code that a computer can understand.
Good programmers write code that humans can understand. "
--- Martin Fowler, Refactoring: Improving the Design of Existing Code
ABAP pretty printer is good for code but not supportive for data declarations.
As a result ABAP code often tends to need more labour to maintain.
1- REPORT yclipjnc.
*&---------------------------------------------------------------------*
* based on ideas from
* http://sap.ionelburlacu.ro/abap/sap2/Beautify_Source_Code.html
* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc
*-----------------------------------------------------------------------
* This program takes ABAP code in ClipBoard, and does the following:
* - Attempts to move comments to the end of the line
* - Adds comments (table name) for the tables listed after a TABLES
* statement if the line has not been commented already.
* - Adds comments (field name) for data elements, parameters, and
* select-options that are defined using the LIKE or FOR statement
* - For ENDLOOP/ENDSELECT adds comment identify the LOOP/SELECT
* that is being closed
* - For FORM/ENDFORM adds comment identify the FORM that is being
* closed
* - Calls function PRETTY_PRINTER to do the SAP standard pretty print
* after the custom comments have been created
* Returns Modified Code Via ClipBoard
*-----------------------------------------------------------------------
2- REPORT yclip2jnc.
*&---------------------------------------------------------------------*
*& Beautify ABAP Code Via Clip
*&---------------------------------------------------------------------*
* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc
*-----------------------------------------------------------------------
* This program takes Structure & internal table declarations in ClipBoard,
* and does prefect alignment as possible
* Returns Modified Code Via ClipBoard
*-----------------------------------------------------------------------
3- PROGRAM yclip3jnc.
*&---------------------------------------------------------------------*
*& Beautiful Function Module Call via clipboard
*
*&---------------------------------------------------------------------*
* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc
*-----------------------------------------------------------------------
* This program takes a parameter as a Function Module Name
* and does a documented "pattern paste"
* Returns pattern Code Via ClipBoard
*-----------------------------------------------------------------------
Link para 3 programas
Trabalhando com estruturas dinâmicas.
Obtenha um estrutura de uma tabela SAP
Crie uma tabela interna dinamicamente
Popular dinamicamente uma tabela interna
Exiba dados usando ALV
Monte catálogo de campos para um Report ALV usando a estrutura de tabela SAP.
Exemplo do programa
Crie uma tabela interna dinamicamente
Popular dinamicamente uma tabela interna
Exiba dados usando ALV
Monte catálogo de campos para um Report ALV usando a estrutura de tabela SAP.
Exemplo do programa
quinta-feira, 9 de março de 2017
Apostilas
Apostila Completa de Excel 2010
Guia de Programação ALV vol 01
Guia de Programação ALV vol 02
Como encontrar uma BADI em um programa standard
Aprenda Programação Orientada a Objeto em 21 dias
Obs: Todos os arquivos foram verificados com Norton Antivirus.
Guia de Programação ALV vol 01
Guia de Programação ALV vol 02
Como encontrar uma BADI em um programa standard
Aprenda Programação Orientada a Objeto em 21 dias
Obs: Todos os arquivos foram verificados com Norton Antivirus.
Assinar:
Postagens (Atom)