Recieving Multiple Idocs from SAP to SAP BC

Hi all

MY code is supposed to receive multiple IDOCS from SAP and convert into XML format which in turn is transported to Oracle. Now the situation is I am able to receive multiple IDOCS, but since the Flow (inbound) is triggered for each idoc the format of the xml file is corrupted.

EG. When i receive a master info for a customer in the form of an IDOC the flow is triggered which will create an xml file… if i receive an IDOC soon after this the flow is triggered again and the xml file is appended with the new information. in this case the format of the xml file is corrupted as shown below

--------------------XML-----------------
<debmas05>
<idoc>
<edi_dc40>
<tabnam>EDI_DC40</tabnam>
<mandt>200</mandt>
<docnum>0000000000029002</docnum>
<docrel>46C</docrel>
<status>30</status>


<jmjah>0000</jmjah>
<umsa1>0</umsa1>
<hzuor>00</hzuor>
<civve>X</civve>
<spras_iso>EN</spras_iso>
<e1kna11>
</e1kna1m>
</idoc>
</debmas05> ----------------> This shouldn’t be here
<debmas05> -----------------> This shouldn’t be here
<idoc>
<edi_dc40>
<tabnam>EDI_DC40</tabnam>
<mandt>200</mandt>
<docnum>0000000000029003</docnum>
<docrel>46C</docrel>
<status>30</status>


<jmzah>000000</jmzah>
<jmjah>0000</jmjah>
<umsa1>0</umsa1>
<hzuor>00</hzuor>
<civve>X</civve>
<spras_iso>EN</spras_iso>
<e1kna11>
</e1kna1m>
</idoc>
</debmas05>


I would appreciate if any one could shed some light on this issue.

cheers
Rohit