CREATE OR REPLACE PROCEDURE REVERTE_LOTE (
   P_CDEMPRESA IN EMPRESA.CDEMPRESA%TYPE,
   P_CDLOTE    IN LANCLOTE.CDLOTE%TYPE  )
AS
V_VERSAO     VARCHAR2(1);
BEGIN
   UPDATE CAPALOTE
   SET CAPALOTE.IDLOTE = 'D'
   WHERE (CAPALOTE.CDEMPRESA = P_CDEMPRESA)  AND
         (CAPALOTE.CDLOTE    = P_CDLOTE);

   DELETE LANCCONT
   WHERE (LANCCONT.CDEMPRESA = P_CDEMPRESA)     AND
         (LANCCONT.IDLANCINTE IN ('L','F','S')) AND
         (LANCCONT.NRLANCCONT) IN (SELECT DISTINCT LANCLOTE.NRLANCDEFI
                                   FROM LANCLOTE
                                   WHERE (LANCLOTE.CDEMPRESA = P_CDEMPRESA) AND
                                         (LANCLOTE.CDLOTE    = P_CDLOTE)  );

END;
/

-- VERSAO --
BEGIN ATUVEROBJ('REVERTE_LOTE','5.05.020'); END;
/

