create or replace FUNCTION MHA_EXPORTA_CONC_ESTOQUE(
   P_DTPOSICAO IN DATE)

   RETURN XML_ARQ PIPELINED
IS
   V_CLIDEPOS VARCHAR2(3);

   V_CDFILIAL    VARCHAR2(4);
   V_EMPRESA     VARCHAR2(2);
   V_FILIAL      VARCHAR2(10);
   V_DATBASE     VARCHAR2(8);
   V_CDPRODUTO   VARCHAR2(10);
   V_CODPRODUTO  VARCHAR2(20);
   V_CODUNIDADE  VARCHAR2(5);
   V_QUANTIDADE  FLOAT;
   V_PESO        FLOAT;

   V_QTRESERVADA FLOAT;

   OUT_XML_ARQ XML := XML(NULL);

   L_XMLTYPE XMLTYPE;
   L_DOMDOC DBMS_XMLDOM.DOMDOCUMENT;
   L_ROOT_NODE DBMS_XMLDOM.DOMNODE;

   L_ELEMENT DBMS_XMLDOM.DOMELEMENT;
   L_ELEMENT_NODE DBMS_XMLDOM.DOMNODE;

   L_NODE DBMS_XMLDOM.DOMNODE;

   L_NAME_ELEMENT DBMS_XMLDOM.DOMELEMENT;
   L_NAME_NODE DBMS_XMLDOM.DOMNODE;
   L_NAME_TEXT DBMS_XMLDOM.DOMTEXT;
   L_NAME_TEXTNODE DBMS_XMLDOM.DOMNODE;

   CURSOR C_CONC_ESTOQUE IS
      SELECT F.CDFILIAL, F.CDEMPRESA, R.CDFILWMSMHA, O.CDPRODUTO,
             O.CDARVPROD, O.SGUNIDADE, NVL(O.VRPESOLIQUPR,0)
        FROM PARAMFILIAL R, FILIAL F, PRODFILI D, (SELECT CDPRODUTO, CDARVPROD, SGUNIDADE, VRPESOLIQUPR
                                                     FROM PRODUTO
                                                    WHERE INSTR(CDARVPROD, '9') = 1
                                                      AND CDNVPRODUTO = (SELECT MAX(CDNVPRODUTO)
                                                                           FROM PRODUTO)) O
       WHERE R.CDFILWMSMHA IS NOT NULL
         AND F.CDFILIAL = R.CDFILIAL
         AND F.IDFUNCAOFILI = 'O'
         AND D.CDFILIAL = R.CDFILIAL
         AND D.CDPRODUTO = O.CDPRODUTO
       ORDER BY F.CDFILIAL, O.CDARVPROD;
BEGIN
   V_CLIDEPOS := '006';
   V_DATBASE  := TO_CHAR(TO_DATE(P_DTPOSICAO), 'YYYYMMDD');

   OPEN C_CONC_ESTOQUE;
   LOOP
      FETCH C_CONC_ESTOQUE INTO V_CDFILIAL, V_EMPRESA, V_FILIAL, V_CDPRODUTO,
                                V_CODPRODUTO, V_CODUNIDADE, V_PESO;
      EXIT WHEN C_CONC_ESTOQUE%NOTFOUND;

      -- Retorna qtde do produto no estoque
      BEGIN
         SELECT A.QTESTOQDIA
           INTO V_QUANTIDADE
           FROM POSESTDIA A
          WHERE A.CDFILIAL     = V_CDFILIAL
            AND A.CDPRODUTO    = V_CDPRODUTO
            AND A.CDALMOXARIFE = ' '
            AND A.CDLOCALESTOQ = ' '
            AND A.NRLOTEESTQ   = ' '
            AND A.NRSUBLOTE    = ' '
            AND A.QTESTOQDIA   > 0
            AND A.DTPOSIESTQ   = (SELECT MAX(P.DTPOSIESTQ)
                                    FROM POSESTDIA P
                                   WHERE P.CDFILIAL     = A.CDFILIAL
                                     AND P.CDPRODUTO    = A.CDPRODUTO
                                     AND P.CDALMOXARIFE = A.CDALMOXARIFE
                                     AND P.CDLOCALESTOQ = A.CDLOCALESTOQ
                                     AND P.NRLOTEESTQ   = A.NRLOTEESTQ
                                     AND P.NRSUBLOTE    = A.NRSUBLOTE
                                     AND P.DTPOSIESTQ   <= P_DTPOSICAO + 1);
      EXCEPTION
         WHEN NO_DATA_FOUND THEN
            V_QUANTIDADE := 0;
      END;

      -- Retorna qtde total reservada
      /*BEGIN
         SELECT SUM(A.QTRESPRPED)
           INTO V_QTRESERVADA
           FROM (SELECT QTRESPRODARR as QTRESPRPED
                   FROM RESERPRODPED
                  WHERE CDFILIAL     = V_CDFILIAL
                    AND CDALMOXARIFE = ' '
                    AND CDLOCALESTOQ = ' '
                    AND NRLOTEESTQ   = ' '
                    AND NRSUBLOTE    = ' '
                    AND CDPRODUTO    = V_CDPRODUTO
                  UNION ALL
                 SELECT QTRESERVESTOL
                   FROM RESERVAPEDEXOL RS, RELACPRODOL RL
                  WHERE RS.CDPRODUTO   = RL.CDPRARVORIG
                    AND RS.CDMARCA     = RL.CDMARCA
                    AND RS.CDFILRESOL  = V_CDFILIAL
                    AND RL.CDPRODARVOL = V_CDPRODUTO) A;
      EXCEPTION
         WHEN NO_DATA_FOUND THEN
            V_QTRESERVADA := 0;
      END;

      V_QUANTIDADE := V_QUANTIDADE - NVL(V_QTRESERVADA,0);
      */
      IF V_QUANTIDADE > 0 THEN
         L_DOMDOC    := DBMS_XMLDOM.NEWDOMDOCUMENT;
         L_ROOT_NODE := DBMS_XMLDOM.MAKENODE(L_DOMDOC);

         L_ELEMENT := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'ListaConciliacao');
         L_ELEMENT_NODE := DBMS_XMLDOM.APPENDCHILD(L_ROOT_NODE,DBMS_XMLDOM.MAKENODE(L_ELEMENT));

         L_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'ConciliacaoEstoque');
         DBMS_XMLDOM.SETATTRIBUTE(L_ELEMENT, 'CODIGO', V_CDFILIAL||V_CODPRODUTO);
         L_NODE     := DBMS_XMLDOM.APPENDCHILD(L_ELEMENT_NODE, DBMS_XMLDOM.MAKENODE(L_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'TIPOGERADOR');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, 'ERP');
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'TIPOINTERFACE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, 'INC');
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'EMPRESA');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_EMPRESA);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'FILIAL');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_FILIAL);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'CLIENTEDEPOSITANTE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_CLIDEPOS);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'CODDEPOSITO');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'DATBASE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_DATBASE);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'CODPRODUTO');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_CODPRODUTO);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'CODUNIDADE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_CODUNIDADE);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'LOTE_ITEM');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'DATAFABRICACAO');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'DATVALIDADE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'EMBALAGEM');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'SSCC');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'QUANTIDADE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_QUANTIDADE);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'PESO');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_PESO);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'DATBASE_YYYYMMDD');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'CODBARRA');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'DOCREFERENCIA');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_XMLTYPE := DBMS_XMLDOM.GETXMLTYPE(L_DOMDOC);
         DBMS_XMLDOM.FREEDOCUMENT(L_DOMDOC);

         OUT_XML_ARQ.XMLRETORNO := L_XMLTYPE;

         PIPE ROW(OUT_XML_ARQ);
      END IF;

      -- Verifica estoque reservado
      /*FOR C_RESERVA IN (SELECT CDLOTENVITOL, NVL(SUM(QTRESERVESTOL),0) AS QUANTIDADE
                          FROM RESERVAPEDEXOL RS, RELACPRODOL RL, ITEMPEDEXOL I
                         WHERE RS.CDPRODUTO   = RL.CDPRARVORIG
                           AND RS.CDMARCA     = RL.CDMARCA
                           AND RS.CDFILRESOL  = V_CDFILIAL
                           AND RL.CDPRODARVOL = V_CDPRODUTO
                           AND I.CDFILDEST    = RS.CDFILDEST
                           AND I.CDFILLANC    = RS.CDFILLANC
                           AND I.NRPEDEXOL    = RS.NRPEDEXOL
                           AND I.CDMARCA      = RS.CDMARCA
                           AND I.CDPRODUTO    = RS.CDPRODUTO
                           AND I.DTPROGENPEOL = RS.DTPROGENPEOL
                           AND RS.QTRESERVESTOL > 0
                         GROUP BY CDLOTENVITOL)
      LOOP
         L_DOMDOC    := DBMS_XMLDOM.NEWDOMDOCUMENT;
         L_ROOT_NODE := DBMS_XMLDOM.MAKENODE(L_DOMDOC);

         L_ELEMENT := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'ListaConciliacao');
         L_ELEMENT_NODE := DBMS_XMLDOM.APPENDCHILD(L_ROOT_NODE,DBMS_XMLDOM.MAKENODE(L_ELEMENT));

         L_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'ConciliacaoEstoque');
         DBMS_XMLDOM.SETATTRIBUTE(L_ELEMENT, 'CODIGO', V_CDFILIAL||V_CODPRODUTO);
         L_NODE     := DBMS_XMLDOM.APPENDCHILD(L_ELEMENT_NODE, DBMS_XMLDOM.MAKENODE(L_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'TIPOGERADOR');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, 'ERP');
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'TIPOINTERFACE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, 'INC');
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'EMPRESA');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_EMPRESA);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'FILIAL');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_FILIAL);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'CLIENTEDEPOSITANTE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_CLIDEPOS);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'CODDEPOSITO');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, C_RESERVA.CDLOTENVITOL);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'DATBASE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_DATBASE);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'CODPRODUTO');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_CODPRODUTO);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'CODUNIDADE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_CODUNIDADE);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'LOTE_ITEM');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'DATAFABRICACAO');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'DATVALIDADE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'EMBALAGEM');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'SSCC');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'QUANTIDADE');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, C_RESERVA.QUANTIDADE);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'PESO');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));
         L_NAME_TEXT     := DBMS_XMLDOM.CREATETEXTNODE(L_DOMDOC, V_PESO);
         L_NAME_TEXTNODE := DBMS_XMLDOM.APPENDCHILD(L_NAME_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_TEXT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'DATBASE_YYYYMMDD');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'CODBARRA');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_NAME_ELEMENT  := DBMS_XMLDOM.CREATEELEMENT(L_DOMDOC, 'DOCREFERENCIA');
         L_NAME_NODE     := DBMS_XMLDOM.APPENDCHILD(L_NODE,DBMS_XMLDOM.MAKENODE(L_NAME_ELEMENT));

         L_XMLTYPE := DBMS_XMLDOM.GETXMLTYPE(L_DOMDOC);
         DBMS_XMLDOM.FREEDOCUMENT(L_DOMDOC);

         OUT_XML_ARQ.XMLRETORNO := L_XMLTYPE;

         PIPE ROW(OUT_XML_ARQ);

      END LOOP;*/
   END LOOP;

   CLOSE C_CONC_ESTOQUE;

   RETURN;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('MHA_EXPORTA_CONC_ESTOQUE','5.87.XXX'); END;
/
