[RESOLVIDO] dataviewer

Discussão em 'EMS , HCM e Totvs 11' iniciado por Will, Outubro 2, 2009.

Status do Tópico:
Não esta aberto para novas mensagens.
  1. Will

    Will Membro Participativo

    Eae glera blz? seguinte tenho um relatório gerado pelo dataviewer, e ele tá muito lento, mas muito mesmo, to postasndo o código , se alguém souber o que posso fazer para melhorar o desempenho dele agradeço

    abrçs

    Código:
    /*****************************************************************************
    **       Programa: keko951.p
    **       Data....: 02/10/09
    **       Autor...: DATASUL S.A.
    **       Objetivo: Movimento Estoq Conta Contabil
    **       Versão..: 1.00.000 - willianh
    **       OBS.....: Este fonte foi gerado pelo Data Viewer 3.00
    *******************************************************************************/
    
    define variable c-prog-gerado as character no-undo initial "KEKO951".
    
    def new global shared var c-arquivo-log    as char  format "x(60)"no-undo.
    
    def new global shared var c-prg-vrs as char no-undo.
    
    def new global shared var c-prg-obj as char no-undo.
    
    
    
    run grapi/gr2002.p (input c-prog-gerado, input "2.00.00.000").
    
    /****************** DefiniþÒo de Tabelas Temporßrias do Relat¾rio **********************/
    
    define temp-table tt-raw-digita
        field raw-digita as raw.
    
    define temp-table tt-param
        field destino              as integer
        field arquivo              as char
        field usuario              as char
        field data-exec            as date
        field hora-exec            as integer
        field parametro            as logical
        field formato              as integer
        field v_num_tip_aces_usuar as integer
        field ep-codigo            as integer
        field c-cod-estabel-ini like mgmov.movto-estoq.cod-estabel
        field c-cod-estabel-fim like mgmov.movto-estoq.cod-estabel
        field c-it-codigo-ini like mgmov.movto-estoq.it-codigo
        field c-it-codigo-fim like mgmov.movto-estoq.it-codigo
        field da-dt-trans-ini like mgmov.movto-estoq.dt-trans
        field da-dt-trans-fim like mgmov.movto-estoq.dt-trans
        field c-conta-contabil-ini like mgmov.movto-estoq.conta-contabil
        field c-conta-contabil-fim like mgmov.movto-estoq.conta-contabil
        field c-nro-docto-ini like mgmov.movto-estoq.nro-docto
        field c-nro-docto-fim like mgmov.movto-estoq.nro-docto
    .
    
    /****************** INCLUDE COM VARIÁVEIS GLOBAIS *********************/
    
    def new global shared var i-ep-codigo-usuario  like mguni.empresa.ep-codigo no-undo.
    
    def new Global shared var l-implanta           as logical    init no.
    
    def new Global shared var c-seg-usuario        as char format "x(12)" no-undo.
    
    def new global shared var i-num-ped-exec-rpw  as integer no-undo.   
    
    def new global shared var i-pais-impto-usuario as integer format ">>9" no-undo.
    
    def new global shared var l-rpc as logical no-undo.
    
    def new global shared var r-registro-atual as rowid no-undo.
    
    def new global shared var c-arquivo-log    as char  format "x(60)"no-undo.
    
    def new global shared var i-num-ped as integer no-undo.         
    
    def new global shared var v_cdn_empres_usuar   like mguni.empresa.ep-codigo        no-undo.
    
    def new global shared var v_cod_usuar_corren   like mguni.usuar_mestre.cod_usuario no-undo.
    
    def new global shared var h_prog_segur_estab     as handle                   no-undo.
    
    def new global shared var v_cod_grp_usuar_lst    as char                     no-undo.
    
    def new global shared var v_num_tip_aces_usuar   as int                      no-undo.
    
    def new global shared var rw-log-exec            as rowid                    no-undo.
    
    
    
    def new global shared var c-dir-spool-servid-exec as CHAR no-undo.
    /****************** Definiçao de Parâmetros do Relatório *********************/ 
    
    /****************** Definiçao de Variáveis de Seleção do Relatório *********************/ 
    
    def new shared var c-cod-estabel-ini like mgmov.movto-estoq.cod-estabel format "x(3)" initial "" no-undo.
    def new shared var c-cod-estabel-fim like mgmov.movto-estoq.cod-estabel format "x(3)" initial "ZZZ" no-undo.
    def new shared var c-it-codigo-ini like mgmov.movto-estoq.it-codigo format "x(16)" initial "" no-undo.
    def new shared var c-it-codigo-fim like mgmov.movto-estoq.it-codigo format "x(16)" initial "ZZZZZZZZZZZZZZZZ" no-undo.
    def new shared var da-dt-trans-ini like mgmov.movto-estoq.dt-trans format "99/99/9999" initial "01/01/1800" no-undo.
    def new shared var da-dt-trans-fim like mgmov.movto-estoq.dt-trans format "99/99/9999" initial "12/31/9999" no-undo.
    def new shared var c-conta-contabil-ini like mgmov.movto-estoq.conta-contabil format "x(17)" initial "" no-undo.
    def new shared var c-conta-contabil-fim like mgmov.movto-estoq.conta-contabil format "x(17)" initial "ZZZZZZZZZZZZZZZZZ" no-undo.
    def new shared var c-nro-docto-ini like mgmov.movto-estoq.nro-docto format "x(16)" initial "" no-undo.
    def new shared var c-nro-docto-fim like mgmov.movto-estoq.nro-docto format "x(16)" initial "ZZZZZZZZZZZZZZZZ" no-undo.
    
    /****************** Definiçao de Variáveis p/ Campos Virtuais do Relatório *******************/ 
    
    /****************** Definiçao de Variáveis Campo Calculado do Relatório **********************/ 
    
    def var Valortotal as decimal label "Vl Total".
    
    /****************** Definiçao de Variáveis do Relatório Não Pedidas em Tela ******************/ 
    
    /****************** Definiçao de Variáveis de Total do Relatório *****************************/ 
    
    /****************** Definiçao de Variáveis dos Calculos do Relatório *************************/ 
    
    def input param raw-param as raw no-undo.
    def input param table for tt-raw-digita.
    
    /***************** Definiçao de Variáveis de Processamento do Relatório *********************/
    
    def var h-acomp              as handle no-undo.
    def var h-FunctionLibrary    as handle no-undo.
    def var v-cod-destino-impres as char   no-undo.
    def var v-num-reg-lidos      as int    no-undo.
    def var v-num-point          as int    no-undo.
    def var v-num-set            as int    no-undo.
    def var v-num-linha          as int    no-undo.
    def var v-cont-registro      as int    no-undo.
    def var v-des-retorno        as char   no-undo.
    def var v-des-local-layout   as char   no-undo.
    
    /****************** Definiçao de Forms do Relatório 132 Colunas ***************************************/ 
    
    form mgcad.item.desc-item column-label "Descrição" format "x(35)" at 001
         mgmov.movto-estoq.un column-label "Un" format "xx" at 037
         mgmov.movto-estoq.conta-contabil column-label "Conta Contábil" format "x(17)" at 040
         mgmov.movto-estoq.dt-trans column-label "Transação" format "99/99/9999" at 058
         mgmov.movto-estoq.tipo-trans column-label "Tp" format ">9" at 069
         mgmov.movto-estoq.it-codigo column-label "Item" format "x(14)" at 072
         mgmov.movto-estoq.nro-docto column-label "Documento" format "x(10)" at 087
         mgmov.movto-estoq.quantidade column-label "Qtde" format ">>>>>,>>9.9999" at 098
         Valortotal column-label "Vl Total" format "->>>,>>>,>>9.99" at 113
         mgmov.movto-estoq.cod-depos column-label "Dep" format "x(3)" at 130
         with down width 132 no-box stream-io frame f-relat-09-132.
    
    create tt-param.
    raw-transfer raw-param to tt-param.
    
    def temp-table tt-editor no-undo
        field linha      as integer
        field conteudo   as character format "x(80)"
        index editor-id is primary unique linha.
    
    
    def var rw-log-exec                            as rowid no-undo.
    
    def var c-erro-rpc as character format "x(60)" initial " " no-undo.
    
    def var c-erro-aux as character format "x(60)" initial " " no-undo.
    
    def var c-ret-temp as char no-undo.
    
    def var h-servid-rpc as handle no-undo.     
    
    define var c-empresa       as character format "x(40)"      no-undo.
    
    define var c-titulo-relat  as character format "x(50)"      no-undo.
    
    define var i-numper-x      as integer   format "ZZ"         no-undo.
    
    define var da-iniper-x     as date      format "99/99/9999" no-undo.
    
    define var da-fimper-x     as date      format "99/99/9999" no-undo.
    
    define var i-page-size-rel as integer                       no-undo.
    
    define var c-programa      as character format "x(08)"      no-undo.
    
    define var c-versao        as character format "x(04)"      no-undo.
    
    define var c-revisao       as character format "999"        no-undo.
    
    
    
    define new shared var c-impressora   as character                      no-undo.
    
    define new shared var c-layout       as character                      no-undo.
    
    define new shared var v_num_count     as integer                       no-undo.
    
    define new shared var c-arq-control   as character                     no-undo.
    define new shared var c-sistema       as character format "x(25)"      no-undo.
    
    define new shared var c-rodape        as character                     no-undo.
    
    
    
    define new shared buffer b_ped_exec_style for mguni.ped_exec.
    
    define new shared buffer b_servid_exec_style for mguni.servid_exec.
    
    
    
    define new shared stream str-rp.
    
    assign c-programa     = "keko951"
           c-versao       = "2.00"
           c-revisao      = ".00.000"
           c-titulo-relat = "Movimento Estoq Conta Contabil"
           c-sistema      = "".
    
    
    find first mguni.empresa no-lock
    
        where mguni.empresa.ep-codigo = i-ep-codigo-usuario no-error.
    
    if  avail mguni.empresa
    
    then
    
        assign c-empresa = mguni.empresa.razao-social.
    
    else
    
        assign c-empresa = "".
    
    if  tt-param.formato = 2 then do:
    
    
    form header
    
        fill("-", 132) format "x(132)" skip
    
        c-empresa c-titulo-relat at 50
    
        "Folha:" at 122 page-number(str-rp) at 128 format ">>>>9" skip
    
        fill("-", 112) format "x(110)" today format "99/99/9999"
    
        "-" string(time, "HH:MM:SS") skip(1)
    
        with stream-io width 132 no-labels no-box page-top frame f-cabec.
    
    
    
    form header
    
        fill("-", 132) format "x(132)" skip
    
        c-empresa c-titulo-relat at 50
    
        "Folha:" at 122 page-number(str-rp) at 128 format ">>>>9" skip
    
        "Periodo:" i-numper-x at 08 "-"
    
        da-iniper-x at 14 "to" da-fimper-x
    
        fill("-", 74) format "x(72)" today format "99/99/9999"
    
        "-" string(time, "HH:MM:SS") skip(1)
    
        with stream-io width 132 no-labels no-box page-top frame f-cabper.
    
    
    
    run grapi/gr2004.p.
    
    
    
    form header
    
        c-rodape format "x(132)"
    
        with stream-io width 132 no-labels no-box page-bottom frame f-rodape.
    
    
    
    end. /* tt-param.formato = 2 */
    
    
    run grapi/gr2009.p (input tt-param.destino,
    
                        input tt-param.arquivo,
    
                        input tt-param.usuario,
    
                        input no).
    
    assign i-ep-codigo-usuario = tt-param.ep-codigo
           v_cdn_empres_usuar  = i-ep-codigo-usuario
           c-cod-estabel-ini = tt-param.c-cod-estabel-ini
           c-cod-estabel-fim = tt-param.c-cod-estabel-fim
           c-it-codigo-ini = tt-param.c-it-codigo-ini
           c-it-codigo-fim = tt-param.c-it-codigo-fim
           da-dt-trans-ini = tt-param.da-dt-trans-ini
           da-dt-trans-fim = tt-param.da-dt-trans-fim
           c-conta-contabil-ini = tt-param.c-conta-contabil-ini
           c-conta-contabil-fim = tt-param.c-conta-contabil-fim
           c-nro-docto-ini = tt-param.c-nro-docto-ini
           c-nro-docto-fim = tt-param.c-nro-docto-fim
    .
    
    def var l-imprime as logical no-undo.
    
    assign l-imprime = no.
    if  tt-param.destino = 1 then
        assign v-cod-destino-impres = "Impressora".
    else
        if  tt-param.destino = 2 then
            assign v-cod-destino-impres = "Arquivo".
        else
            assign v-cod-destino-impres = "Terminal".
    
    
    run utp/ut-acomp.p persistent set h-acomp.
    
    run pi-inicializar in h-acomp(input "Acompanhamento Relatório").
    
    assign v-num-reg-lidos = 0.
    
    /* gr9020a.p */
    
    for each mgmov.movto-estoq no-lock
             where mgmov.movto-estoq.cod-estabel >= c-cod-estabel-ini and 
                   mgmov.movto-estoq.cod-estabel <= c-cod-estabel-fim and
                   mgmov.movto-estoq.conta-contabil >= c-conta-contabil-ini and 
                   mgmov.movto-estoq.conta-contabil <= c-conta-contabil-fim and
                   mgmov.movto-estoq.dt-trans >= da-dt-trans-ini and 
                   mgmov.movto-estoq.dt-trans <= da-dt-trans-fim and
                   mgmov.movto-estoq.it-codigo >= c-it-codigo-ini and 
                   mgmov.movto-estoq.it-codigo <= c-it-codigo-fim and
                   mgmov.movto-estoq.nro-docto >= c-nro-docto-ini and 
                   mgmov.movto-estoq.nro-docto <= c-nro-docto-fim,
        each mgcad.item no-lock
             where mgcad.item.it-codigo = mgmov.movto-estoq.it-codigo:
    
        assign v-num-reg-lidos = v-num-reg-lidos + 1.
        run pi-acompanhar in h-acomp(input string(v-num-reg-lidos)).
    
        assign Valortotal = (mgmov.movto-estoq.valor-ggf-m[1] + mgmov.movto-estoq.valor-mat-m[1] + mgmov.movto-estoq.valor-mob-m[1]).
        /***  CÓDIGO PARA SAÍDA EM 132 COLUNAS ***/
    
        if  tt-param.formato = 2 then do:
    
            view stream str-rp frame f-cabec.
            view stream str-rp frame f-rodape.
            assign l-imprime = yes.
    
            if mgmov.movto-estoq.tipo-trans = 1 then
    valortotal = valortotal * -1.
    
    
            display stream str-rp mgcad.item.desc-item
                mgmov.movto-estoq.un
                mgmov.movto-estoq.conta-contabil
                mgmov.movto-estoq.dt-trans
                mgmov.movto-estoq.tipo-trans
                mgmov.movto-estoq.it-codigo
                mgmov.movto-estoq.nro-docto
                mgmov.movto-estoq.quantidade
                Valortotal
                mgmov.movto-estoq.cod-depos
                    with stream-io frame f-relat-09-132.
                down stream str-rp with frame f-relat-09-132.
        end.
        
    end.
    
    
    if  l-imprime = no then do:
        if  tt-param.formato = 2 then do:
            view stream str-rp frame f-cabec.
            view stream str-rp frame f-rodape.
        end.
        disp stream str-rp " " with stream-io frame f-nulo.
    end.
    
    if  tt-param.destino <> 1 then
    
        page stream str-rp.
    
    else do:
    
        if   tt-param.parametro = yes then
    
             page stream str-rp.
    
    end.
    
    if  tt-param.parametro then do:
    
    
       disp stream str-rp "SELEÇÃO" skip(01) with stream-io frame f-imp-sel.
       disp stream str-rp 
          c-cod-estabel-ini colon 19 "|< >|"   at 43 c-cod-estabel-fim no-label
          c-it-codigo-ini colon 19 "|< >|"   at 43 c-it-codigo-fim no-label
          da-dt-trans-ini colon 19 "|< >|"   at 43 da-dt-trans-fim no-label
          c-conta-contabil-ini colon 19 "|< >|"   at 43 c-conta-contabil-fim no-label
          c-nro-docto-ini colon 19 "|< >|"   at 43 c-nro-docto-fim no-label
            with stream-io side-labels overlay row 030 frame f-imp-sel.
    
       put stream str-rp unformatted skip(1) "IMPRESSÃO" skip(1).
    
       put stream str-rp unformatted skip "    " "Destino : " v-cod-destino-impres " - " tt-param.arquivo format "x(40)".
       put stream str-rp unformatted skip "    " "Execução: " if i-num-ped-exec-rpw = 0 then "On-Line" else "Batch".
       put stream str-rp unformatted skip "    " "Formato : " if tt-param.formato = 1 then "80 colunas" else "132 colunas".
       put stream str-rp unformatted skip "    " "Usuário : " tt-param.usuario.
    
    end.
    
        output stream str-rp close.
    
    procedure pi-print-editor:
    
        def input param c-editor    as char    no-undo.
        def input param i-len       as integer no-undo.
    
        def var i-linha  as integer no-undo.
        def var i-aux    as integer no-undo.
        def var c-aux    as char    no-undo.
        def var c-ret    as char    no-undo.
    
        for each tt-editor:
            delete tt-editor.
        end.
    
        assign c-ret = chr(255) + chr(255).
    
        do  while c-editor <> "":
            if  c-editor <> "" then do:
                assign i-aux = index(c-editor, chr(10)).
                if  i-aux > i-len or (i-aux = 0 and length(c-editor) > i-len) then
                    assign i-aux = r-index(c-editor, " ", i-len + 1).
                if  i-aux = 0 then
                    assign c-aux = substr(c-editor, 1, i-len)
                           c-editor = substr(c-editor, i-len + 1).
                else
                    assign c-aux = substr(c-editor, 1, i-aux - 1)
                           c-editor = substr(c-editor, i-aux + 1).
                if  i-len = 0 then
                    assign entry(1, c-ret, chr(255)) = c-aux.
                else do:
                    assign i-linha = i-linha + 1.
                    create tt-editor.
                    assign tt-editor.linha    = i-linha
                           tt-editor.conteudo = c-aux.
                end.
            end.
            if  i-len = 0 then
                return c-ret.
        end.
        return c-ret.
    end procedure.
    
    IF VALID-HANDLE(h-acomp) THEN /*gr9030g*/
        RUN pi-finalizar IN h-acomp NO-ERROR.
    
    return 'OK'.
    
    /* fim do programa */
    
    
    
  2. petruzad

    petruzad Membro Participativo

    No for each acrescente use-index veja abaixo:

    for each mgmov.movto-estoq use-index data-conta no-lock ...

    Att.
  3. Will

    Will Membro Participativo

    Eae cara vlw pela ajuda , funcionou
    tive que criar u mrelatório novo, pois pelo dataviewer eu realizava as alterações e ele sobresscrevia
Status do Tópico:
Não esta aberto para novas mensagens.

Compartilhe esta Página