CREATE OR REPLACE FUNCTION RETORNA_CFOP_DFC(
   P_CDLIVROMAG     IN LIVROMAGNETICO.CDLIVROMAG%TYPE,
   P_CDFISCOPERNF   IN IMPOSTONF.CDFISCOPERNF%TYPE,
   P_CDLAYOUTLMAG   IN CFOPLIVROMAG.CDLAYOUTLMAG%TYPE) RETURN NUMBER
AS
   V_CDLAYOUTLMAG    VARCHAR2(03);
BEGIN

   SELECT MAX(CDLAYOUTLMAG)
   INTO V_CDLAYOUTLMAG
   FROM CFOPLIVROMAG
   WHERE CDLIVROMAG = P_CDLIVROMAG
     AND CDCFOPLMAG = P_CDFISCOPERNF
     AND CDLAYOUTLMAG = P_CDLAYOUTLMAG;

   RETURN(V_CDLAYOUTLMAG);

END;
/


-- VERSAO --
BEGIN ATUVEROBJ('RETORNA_CFOP_DFC','5.05.025'); END;
/

