Tuesday, April 19, 2022

Oracle Integration Cloud | Merge two CSV files into a single file without any primary key or common field

Use Case: Here, we will Merge the content of two files into one csv file where there is no common field.

Consideration: we will map the two files sequencially. That means, for 1st row of file1 to 1st row of file2, 2nd row of file1 to 2nd row of file2......nth row of file1 to nth row of file2.

For example,

File1.csv:

FirstName,LastName

sid,das

dip,chak

File2.csv

EMail

sid@gmail.com

dip@gmail.com

Merged file:

FirstName,LastName

sid,das,sid@gmail.com

dip,chak,dip@gmail.com

Highlevel steps:

  1. Create a scheduled orchestration with a name.
  2. Drag and drop the FTP adapter and read both the source files one by one.
  3. Drag and drop the FTP adapter to write the final merge file. Here, in the map, for each file1 record, we will create a variable named "i" with value "position()" and that postion we will use to fetch the value from file 2 hsing $i.
Steps in detail(with screenshots):

Integration flow


Read file1






Read file2






Write Merge file






Map codes:

<xsl:template match="/" xml:id="id_11">

<nstrgmpr:WriteFile xml:id="id_12">

<ns28:FileMergedRecSet>

<ns28:FileMergedRec>

<ns28:C1>

<xsl:value-of select="'Fname'"/>

</ns28:C1>

<ns28:C2>

<xsl:value-of select="'Lname'"/>

</ns28:C2>

<ns28:C3>

<xsl:value-of select="'Email'"/>

</ns28:C3>

</ns28:FileMergedRec>

<xsl:for-each select="$readFile1/nsmpr1:SyncReadFileResponse/ns21:FileReadResponse/ns22:File1RecSet/ns22:File1Rec">

<xsl:variable name="i" select="position()"/>

<ns28:FileMergedRec>

<ns28:C1>

<xsl:value-of select="ns22:FirstName"/>

</ns28:C1>

<ns28:C2>

<xsl:value-of select="ns22:LastName"/>

</ns28:C2>

<ns28:C3>

<xsl:value-of select="$readFile2/nsmpr2:SyncReadFileResponse/ns25:FileReadResponse/ns24:File2RecSet/ns24:File2Rec[$i]/ns24:EMail"/>

</ns28:C3>

</ns28:FileMergedRec>

</xsl:for-each>

</ns28:FileMergedRecSet>

</nstrgmpr:WriteFile>

</xsl:template>




No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...