Question Error In Procedure

Hello guys!


My routine is returning an error when commenting the code :

Code:
/*   
OUTPUT TO c:\temp\tt-atend.txt.
FOR EACH tt-atend NO-LOCK:
    EXPORT DELIMITER ";" tt-atend.
END.

OUTPUT TO c:\temp\tt-resumo.txt.
FOR EACH tt-resumo NO-LOCK:
    EXPORT DELIMITER ";" tt-resumo.
END. */

if i remove the comment no return an error.

see error :

erro_retorno.JPG

Code:
DEF TEMP-TABLE tt-atend
    FIELD cod-estabel   AS CHAR
    FIELD dt-trans      AS DATE
    FIELD turno         AS CHAR FORMAT "X"
    FIELD hora          AS INT
    FIELD elaboradas    AS INT INITIAL 0
    FIELD aprovadas     AS INT INITIAL 0
    FIELD quantidade    AS INT INITIAL 0
    FIELD dest-fam      AS INT INITIAL 0
    FIELD saldo         AS INT INITIAL 0
    FIELD liberadas     AS INT INITIAL 0
    FIELD todas         AS INT INITIAL 0
    FIELD elab_aprov    AS INT64 INITIAL 0
    FIELD aprov_atend   AS INT64 INITIAL 0
    FIELD elab_atend    AS INT64 INITIAL 0
    FIELD cod-usuar     LIKE esb053-estat.cod-usuar
    FIELD nom-usuar     LIKE esb053-estat.nom-usuar
    FIELD hr-atualiz    LIKE esb053-estat.hr-atualiz
    INDEX pk-tt-atend cod-estabel dt-trans hora.

DEF TEMP-TABLE tt-resumo
    FIELD dt-trans      AS DATE
    FIELD turno         AS CHAR FORMAT "X"
    FIELD hora          AS INT
    FIELD Ufa-Ela       AS INT INITIAL 0
    FIELD Ufa-Apv       AS INT INITIAL 0
    FIELD Ufa-Ate       AS INT INITIAL 0
    FIELD Ufa-Des       AS INT INITIAL 0
    FIELD Ufa-Sal       AS INT INITIAL 0
    FIELD Ufa-Lib       AS INT INITIAL 0
    FIELD Ufa-Tot       AS INT INITIAL 0
    FIELD Ufl-Ela       AS INT INITIAL 0
    FIELD Ufl-Apv       AS INT INITIAL 0
    FIELD Ufl-Ate       AS INT INITIAL 0
    FIELD Ufl-Des       AS INT INITIAL 0
    FIELD Ufl-Sal       AS INT INITIAL 0
    FIELD Ufl-Lib       AS INT INITIAL 0
    FIELD Ufl-Tot       AS INT INITIAL 0
    FIELD Uju-Ela       AS INT INITIAL 0
    FIELD Uju-Apv       AS INT INITIAL 0
    FIELD Uju-Ate       AS INT INITIAL 0
    FIELD Uju-Des       AS INT INITIAL 0
    FIELD Uju-Sal       AS INT INITIAL 0
    FIELD Uju-Lib       AS INT INITIAL 0
    FIELD Uju-Tot       AS INT INITIAL 0
    FIELD Usi-Ela       AS INT INITIAL 0
    FIELD Usi-Apv       AS INT INITIAL 0
    FIELD Usi-Ate       AS INT INITIAL 0
    FIELD Usi-Des       AS INT INITIAL 0
    FIELD Usi-Sal       AS INT INITIAL 0
    FIELD Usi-Lib       AS INT INITIAL 0
    FIELD Usi-Tot       AS INT INITIAL 0
    INDEX pk-resumo-req dt-trans DESC hora DESC.

/*
DEFINE DATASET dsResumo  FOR tt-resumo.
DEFINE VARIABLE hdResumo AS HANDLE NO-UNDO.
ASSIGN hdResumo = DATASET dsResumo:HANDLE.*/
/*
DEFINE INPUT    PARAMETER dt-inicial    AS DATETIME.
DEFINE INPUT    PARAMETER dt-final      AS DATETIME.

DEFINE DATASET dsResumo                  FOR tt-resumo.
DEFINE VARIABLE hdResumo                 AS HANDLE     NO-UNDO.
DEFINE OUTPUT PARAMETER DATASET                 FOR dsResumo.
ASSIGN hdResumo                          = DATASET dsResumo:HANDLE. 

/*DEFINE OUTPUT   PARAMETER DATASET       FOR dsResumo.*/

DEFINE OUTPUT   PARAMETER pocErro       AS CHAR INITIAL 'OK'.
*/

DEF VAR i-indice    AS int.

DEF VAR dt-inicial AS DATE.
DEF VAR dt-final AS DATE.
DEF VAR pocerro AS CHAR.
ASSIGN dt-inicial   = TODAY
       dt-final     = TODAY.



FIND FIRST param_integr_sisma NO-ERROR.
CONNECT VALUE(param_integr_sisma.des_conexao) NO-ERROR.
/*OUTPUT TO c:\temp\erros3.txt.*/
IF CONNECTED('mb')
THEN do:
    RUN c:\temp\sew_cons_Esb053_Assiste.p
                                  (INPUT  dt-inicial,
                                   INPUT  dt-final,
                                   OUTPUT TABLE tt-atend).
           MESSAGE "saindo"
               VIEW-AS ALERT-BOX INFO BUTTONS OK.
    FOR EACH tt-atend  NO-LOCK  BREAK BY tt-atend.dt-trans DESC
                                    BY tt-atend.hora DESC:
        /*
        FIND tt-resumo WHERE
            tt-resumo.dt-trans = tt-atend.dt-trans AND
            tt-resumo.hora      = tt-atend.hora
        NO-ERROR.
        IF NOT AVAIL tt-resumo
        THEN DO:
            CREATE tt-resumo.
            ASSIGN tt-resumo.dt-trans   = tt-atend.dt-trans
                   tt-resumo.turno      = tt-atend.turno
                   tt-resumo.hora       = tt-atend.hora.           
        END.
        */
        
        IF first-of(tt-atend.hora)
        THEN DO:
            CREATE tt-resumo.
            ASSIGN tt-resumo.dt-trans   = tt-atend.dt-trans
                   tt-resumo.turno      = tt-atend.turno
                   tt-resumo.hora       = tt-atend.hora.
        END.
        
        /*PUT tt-atend.cod-estab tt-atend.hora AVAIL(tt-resumo) SKIP.*/
            
        CASE tt-atend.cod-estabel:
            WHEN "UFA" THEN ASSIGN tt-resumo.Ufa-Ela = tt-atend.elaboradas
                                   tt-resumo.Ufa-Apv = tt-atend.aprovadas
                                   tt-resumo.Ufa-Ate = tt-atend.quantidade
                                   tt-resumo.Ufa-Des = tt-atend.dest-fam
                                   tt-resumo.Ufa-Sal = tt-atend.saldo
                                   tt-resumo.Ufa-Lib = tt-atend.liberadas
                                   tt-resumo.Ufa-Tot = tt-atend.todas.
            WHEN "UFL" THEN ASSIGN tt-resumo.Ufl-Ela = tt-atend.elaboradas
                                   tt-resumo.Ufl-Apv = tt-atend.aprovadas
                                   tt-resumo.Ufl-Ate = tt-atend.quantidade
                                   tt-resumo.Ufl-Des = tt-atend.dest-fam
                                   tt-resumo.Ufl-Sal = tt-atend.saldo
                                   tt-resumo.Ufl-Lib = tt-atend.liberadas
                                   tt-resumo.Ufl-Tot = tt-atend.todas.
            WHEN "UJU" THEN ASSIGN tt-resumo.Uju-Ela = tt-atend.elaboradas
                                   tt-resumo.Uju-Apv = tt-atend.aprovadas
                                   tt-resumo.Uju-Ate = tt-atend.quantidade
                                   tt-resumo.Uju-Des = tt-atend.dest-fam
                                   tt-resumo.Uju-Sal = tt-atend.saldo
                                   tt-resumo.Uju-Lib = tt-atend.liberadas
                                   tt-resumo.Uju-Tot = tt-atend.todas.
            WHEN "USI" THEN ASSIGN tt-resumo.Usi-Ela = tt-atend.elaboradas
                                   tt-resumo.Usi-Apv = tt-atend.aprovadas
                                   tt-resumo.Usi-Ate = tt-atend.quantidade
                                   tt-resumo.Usi-Des = tt-atend.dest-fam
                                   tt-resumo.Usi-Sal = tt-atend.saldo
                                   tt-resumo.Usi-Lib = tt-atend.liberadas
                                   tt-resumo.Usi-Tot = tt-atend.todas.
        END CASE.
    END.
    IF CONNECTED('mb') THEN DISCON 'mb'.
END.
ELSE ASSIGN pocErro = "Base do Sisma com Problemas!".
        OUTPUT TO TERMINAL.

/*   
OUTPUT TO c:\temp\tt-atend.txt.
FOR EACH tt-atend NO-LOCK:
    EXPORT DELIMITER ";" tt-atend.
END.

OUTPUT TO c:\temp\tt-resumo.txt.
FOR EACH tt-resumo NO-LOCK:
    EXPORT DELIMITER ";" tt-resumo.
END. */
 
RETURN "OK".
 
If I change the code :


Code:
 IF first-of(tt-atend.hora)
        THEN DO:
            CREATE tt-resumo.
            ASSIGN tt-resumo.dt-trans   = tt-atend.dt-trans
                   tt-resumo.turno      = tt-atend.turno
                   tt-resumo.hora       = tt-atend.hora.
        END.

for :

Code:
        FIND tt-resumo WHERE
            tt-resumo.dt-trans = tt-atend.dt-trans AND
            tt-resumo.hora      = tt-atend.hora
        NO-ERROR.
        IF NOT AVAIL tt-resumo
        THEN DO:
            CREATE tt-resumo.
            ASSIGN tt-resumo.dt-trans   = tt-atend.dt-trans
                   tt-resumo.turno      = tt-atend.turno
                   tt-resumo.hora       = tt-atend.hora.           
        END.


no return error.
 

Cringer

ProgressTalk.com Moderator
Staff member
Code:
/*
DEFINE DATASET dsResumo  FOR tt-resumo.
DEFINE VARIABLE hdResumo AS HANDLE NO-UNDO.
ASSIGN hdResumo = DATASET dsResumo:HANDLE.*/
/*
DEFINE INPUT    PARAMETER dt-inicial    AS DATETIME.
DEFINE INPUT    PARAMETER dt-final      AS DATETIME.

DEFINE DATASET dsResumo                  FOR tt-resumo.
DEFINE VARIABLE hdResumo                 AS HANDLE     NO-UNDO.
DEFINE OUTPUT PARAMETER DATASET                 FOR dsResumo.
ASSIGN hdResumo                          = DATASET dsResumo:HANDLE.

/*DEFINE OUTPUT   PARAMETER DATASET       FOR dsResumo.*/

DEFINE OUTPUT   PARAMETER pocErro       AS CHAR INITIAL 'OK'.
*/
I don't know if this is the problem but these nested comments are nasty and confusing!
 

Stefan

Well-Known Member
My guess is that the for each statements are raising the record scope. Scope tight and strong and you will find the culprit.
 

Cringer

ProgressTalk.com Moderator
Staff member
Aha! I see the problem! When you're using the first-of function to create the tt-resumo then that tt-resumo record goes out of scope at the end of the first-of block. That means it is no longer available to update in the case statement. When you use the find, tt-resumo is now scoped to the higher block and is still available.

I think you need to do something along the lines of this:

Code:
do for tt-resumo:
FOR EACH tt-atend  NO-LOCK  BREAK BY tt-atend.dt-trans DESC
                                    BY tt-atend.hora DESC:

Obviously you'll also need to add an extra END.
 
I understand, but it's the same as me taking the comment from find.

What I do not understand is why when I shoot the OUPUT comment the application does not return me error.

That does not make sense to me.
 

Cringer

ProgressTalk.com Moderator
Staff member
Uncommenting the output statement must raise the scope of the buffers to the whole procedure.
 
Top