SET TERM ^ ;

CREATE OR ALTER procedure SPC_CALC_PROJECAO_PEDIDO (
    MODELO integer,
    COR integer,
    TAMANHO integer,
    QUANTIDADE numeric(15,4),
    FAMILIA varchar(2000),
    CORES varchar(2000),
    NIVEL varchar(100))
returns (
    FAMILIA_CODIGO integer,
    FAMILIA_DESCRICAO varchar(20),
    PRODUTO_ID integer,
    TAM integer,
    GRADE_CODIGO integer,
    PRODUTO_DESCRICAO varchar(100),
    UM varchar(10),
    LOCALIZACAO_CODIGO integer,
    TAM_DESCRICAO varchar(10),
    SETOR_ID integer,
    SETOR varchar(20),
    PROJECAO numeric(15,4))
as
BEGIN

    FOR
        SELECT
            X.FAMILIA_CODIGO,
            COALESCE(F.DESCRICAO, '') AS FAMILIA_DESCRICAO,
            X.PRODUTO_ID,
            X.TAM,
            X.GRADE_CODIGO,
            X.PRODUTO_DESCRICAO,
            X.UM,
            X.LOCALIZACAO_CODIGO,
            COALESCE((SELECT TAM_DESCRICAO FROM SP_TAMANHO_GRADE (X.GRADE_CODIGO,X.TAM)), '') TAM_DESCRICAO,
            X.SETOR_ID,
            COALESCE(U.DESCRICAO, '') AS SETOR,
            X.PROJECAO

        FROM (
            SELECT 
                P.FAMILIA_CODIGO,
                B.CONSUMO_PRODUTO_CODIGO PRODUTO_ID,
                B.TAM,
                P.GRADE_CODIGO,
                P.DESCRICAO PRODUTO_DESCRICAO,
                P.UNIDADEMEDIDA_SIGLA UM,
                P.LOCALIZACAO_CODIGO,
                COALESCE(B.SETOR_CODIGO,0) AS SETOR_ID,

                CAST((
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 0) AND (B.CONSUMO_QUANTIDADE     > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE    , B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 1) AND (B.CONSUMO_QUANTIDADE_T01 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T01, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 2) AND (B.CONSUMO_QUANTIDADE_T02 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T02, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 3) AND (B.CONSUMO_QUANTIDADE_T03 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T03, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 4) AND (B.CONSUMO_QUANTIDADE_T04 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T04, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 5) AND (B.CONSUMO_QUANTIDADE_T05 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T05, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 6) AND (B.CONSUMO_QUANTIDADE_T06 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T06, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 7) AND (B.CONSUMO_QUANTIDADE_T07 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T07, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 8) AND (B.CONSUMO_QUANTIDADE_T08 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T08, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 9) AND (B.CONSUMO_QUANTIDADE_T09 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T09, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=10) AND (B.CONSUMO_QUANTIDADE_T10 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T10, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=11) AND (B.CONSUMO_QUANTIDADE_T11 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T11, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=12) AND (B.CONSUMO_QUANTIDADE_T12 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T12, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=13) AND (B.CONSUMO_QUANTIDADE_T13 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T13, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=14) AND (B.CONSUMO_QUANTIDADE_T14 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T14, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=15) AND (B.CONSUMO_QUANTIDADE_T15 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T15, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=16) AND (B.CONSUMO_QUANTIDADE_T16 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T16, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=17) AND (B.CONSUMO_QUANTIDADE_T17 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T17, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=18) AND (B.CONSUMO_QUANTIDADE_T18 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T18, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=19) AND (B.CONSUMO_QUANTIDADE_T19 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T19, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=20) AND (B.CONSUMO_QUANTIDADE_T20 > 0) THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) ,  CAST(FN_CALC_PRECISION_V2(B.CONSUMO_QUANTIDADE_T20, B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END)) AS NUMERIC(15,4))  PROJECAO

            FROM TBMODELO_CONSUMO B, TBPRODUTO P
            WHERE B.MODELO_CODIGO = :MODELO
            AND B.CONSUMO_PRODUTO_CODIGO = P.CODIGO

             AND IIF(:FAMILIA <> '', P.FAMILIA_CODIGO IN (SELECT OSPLIT FROM SPLIT(:FAMILIA, ',')), TRUE)
             AND IIF(:CORES <> '', TRUE = FALSE, TRUE)
             AND IIF(:NIVEL <> '', B.NIVEL IN (SELECT OSPLIT FROM SPLIT(:NIVEL, ',')), TRUE)

            UNION

            SELECT 
                P.FAMILIA_CODIGO, 
                B.PRODUTO_ID, 
                B.TAM, 
                P.GRADE_CODIGO, 
                P.DESCRICAO PRODUTO_DESCRICAO, 
                P.UNIDADEMEDIDA_SIGLA UM,
                P.LOCALIZACAO_CODIGO, 
                COALESCE(B.SETOR_ID,0) AS SETOR_ID,

                CAST((
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 0) AND (B.QUANTIDADE>0)  THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.QUANTIDADE,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 1) AND (B.T01 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T01       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 2) AND (B.T02 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T02       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 3) AND (B.T03 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T03       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 4) AND (B.T04 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T04       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 5) AND (B.T05 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T05       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 6) AND (B.T06 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T06       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 7) AND (B.T07 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T07       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 8) AND (B.T08 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T08       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)= 9) AND (B.T09 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T09       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=10) AND (B.T10 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T10       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=11) AND (B.T11 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T11       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=12) AND (B.T12 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T12       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=13) AND (B.T13 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T13       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=14) AND (B.T14 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T14       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=15) AND (B.T15 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T15       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=16) AND (B.T16 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T16       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=17) AND (B.T17 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T17       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=18) AND (B.T18 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T18       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=19) AND (B.T19 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T19       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END) +
                (CASE WHEN (CAST(:TAMANHO AS INTEGER)=20) AND (B.T20 > 0)       THEN CAST( (FN_CALC_PRECISION_V2(CAST(:QUANTIDADE AS NUMERIC(15,4)) , CAST(FN_CALC_PRECISION_V2(B.T20       ,B.FATOR_CONVERSAO,'/')AS NUMERIC(15,8)),'*')) AS NUMERIC(15,4)) ELSE 0 END)) AS NUMERIC(15,4)) PROJECAO

            FROM TBMODELO_CONSUMO_COR B, TBPRODUTO P
            WHERE B.MODELO_ID = :MODELO
            AND B.COR_ID = :COR
            AND B.PRODUTO_ID = P.CODIGO

             AND IIF(:FAMILIA <> '', P.FAMILIA_CODIGO IN (SELECT OSPLIT FROM SPLIT(:FAMILIA, ',')), TRUE)
             AND IIF(:CORES <> '', B.COR_ID IN (SELECT OSPLIT FROM SPLIT(:CORES, ',')), TRUE)
             AND IIF(:NIVEL <> '', B.NIVEL IN (SELECT OSPLIT FROM SPLIT(:NIVEL, ',')), TRUE)

        ) X 
        LEFT JOIN TBFAMILIA F ON F.CODIGO = X.FAMILIA_CODIGO
        LEFT JOIN TBUP U ON U.ID = X.SETOR_ID
        WHERE X.PROJECAO > 0

    INTO 
        :FAMILIA_CODIGO, 
        :FAMILIA_DESCRICAO, 
        :PRODUTO_ID, 
        :TAM,
        :GRADE_CODIGO, 
        :PRODUTO_DESCRICAO, 
        :UM, 
        :LOCALIZACAO_CODIGO,
        :TAM_DESCRICAO, 
        :SETOR_ID, 
        :SETOR, 
        :PROJECAO

    DO 
    BEGIN

        SUSPEND;
    END

END
^

SET TERM ; ^

