Duvida FOR EACH - trazer registro com maior data

Discussão em 'Progress 4GL' iniciado por jc01, Abril 20, 2015.

  1. bootstrapmaster

    bootstrapmaster Moderator Moderador Equipe de Suporte

    Código:
    define buffer bfTabela of tabela.
    
    for each tabela no-lock
        break
           by tabela.tipo:
    
        for last bftabela no-lock
            where bfTabela.tipo = tabela.tipo
             break
                by bftabela.data:
    
            disp bfTabela.tpo bfTabela.data.
        end.
    end.
    
  2. jc01

    jc01 Membro Participativo

    Usando essa lógica funciona.
  3. bootstrapmaster

    bootstrapmaster Moderator Moderador Equipe de Suporte

    Dividir pra conquistar .... hehehehe
    rafael.andrade e rlfritz curtiram isso.
  4. rlfritz

    rlfritz Membro Ativo

    Legal ! mas mudando o "and" para "or" ... já resolve...

    to empolgado hoje ... e botei isso em código.

    Código:
    DEFINE VARIABLE c-dados AS CHARACTER   NO-UNDO.
    ASSIGN c-dados = "1;2;1;01/01/2010;1226,35#2;2;1;01/05/2010;3263,23#3;2;1;01/04/2010;3352,98#4;2;2;01/06/2012;1233,27#5;2;2;01/03/2011;3266,35#6;3;1;01/02/2009;8963,32#7;3;1;01/10/2010;903,26#8;3;2;01/03/2012;63,23#9;3;2;01/02/2012;753,15".
    
    DEFINE TEMP-TABLE tt-resumo NO-UNDO
        FIELD codigo AS INTEGER
        FIELD tipo AS INTEGER
        FIELD grupo AS INTEGER
        FIELD data AS DATE
        FIELD valor AS DECIMAL
        INDEX tt-resumo AS PRIMARY UNIQUE codigo
        INDEX tt-res2 tipo grupo data     .
    
    DEFINE VARIABLE i-aux AS INTEGER     NO-UNDO.
    DEFINE VARIABLE c-registro AS CHARACTER   NO-UNDO.
    
    DO i-aux = 1 TO NUM-ENTRIES(c-dados,"#"):
    
        ASSIGN c-registro = ENTRY(i-aux,c-dados,"#").
        CREATE tt-resumo.
        ASSIGN tt-resumo.codigo = int(ENTRY(1,c-registro,";"))
               tt-resumo.tipo = INT(ENTRY(2,c-registro,";"))
               tt-resumo.grupo = INT(ENTRY(3,c-registro,";"))
               tt-resumo.data = DATE(ENTRY(4,c-registro,";"))
               tt-resumo.valor = DECIMAL(ENTRY(5,c-registro,";")).
    
    
    END.
    
    
    /* código principal  */
    for each tt-resumo break by tt-resumo.tipo by tt-resumo.grupo by tt-resumo.data :
    
         if last-of(tt-resumo.grupo) OR last-of(tt-resumo.tipo)  then do:
             DISP tt-resumo.                  
        end.
    
    end.
    

    A saída deste código foi exatamente o que você queria.
    Eilleen curtiu isso.
  5. jc01

    jc01 Membro Participativo

    Realmente, desse modo funciona. Nem passou pela minha cabeça usar "OR" invés de "AND".
    Valeu!
    rlfritz curtiu isso.
  6. bootstrapmaster

    bootstrapmaster Moderator Moderador Equipe de Suporte

    mas o OR vai trazer o ultimo tipo ou a ultima data, não fica 100%, pode ser que com os dados de teste funcione, mas no dia-a-dia eu tenho minhas duvidas.

Compartilhe esta Página