Click here to Skip to main content
15,890,609 members
Articles / CSV

How to remove the Header row of a CSV file from Infor MEC/IEC

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
28 Jan 2021CPOL1 min read 3K   1   1
In this post, I'm going to share one of the possible methods to get rid of the CSV header.

Integrating CSV files with MEC is a very old but frequently used method. A CSV file may have a header and the data as in the below format. If we use this file (converting FLAT To XML) directly as it is, it will feed the data with the header. In this post, I'm going to share one of the possible methods to get rid of the CSV header.

FACI,PRDCT,MO,OPERNO,MANUQTY
A01,Y3003-Y01-010,3000018,10,2
A01,Y3003-Y01-010,3000018,50,2

Using the Flat file definition tool I will define the following structure.

Then I will get the following XML message into the MEC process.

<WORKBOOK>
	<ManuObj>
		<FACI>FACI</FACI>
		<PRDCT>Product</PRDCT>
		<MO>MO</MO>
		<OPRNO>Operation No</OPRNO>
		<MANUQTY>ManuQty</MANUQTY>
	</ManuObj>
	<ManuObj>
		<FACI>A01</FACI>
		<PRDCT>Y3001-Y02-016</PRDCT>
		<MO>0003000164</MO>
		<OPRNO>0010</OPRNO>
		<MANUQTY>1</MANUQTY>
	</ManuObj>
	<ManuObj>
		<FACI>A01</FACI>
		<PRDCT>Y3001-Y02-016</PRDCT>
		<MO>0003000164</MO>
		<OPRNO>0040</OPRNO>
		<MANUQTY>1</MANUQTY>
	</ManuObj>
</WORKBOOK>

You can notice the XML message contains the header. To get rid of the header one method is;

  1. Read all the XML elements into a Java array in the Mapper.
  2. Then process the data from the first position of the Array (remember 0th position will have the header segment).
But here I will show you a different method that is using XSLT transformation. Very easy.

Steps are

  1.  Define the XLST definition. You can reuse this definition with two small modifications. Change the "WORKBOOK" value in <xsl:element name="WORKBOOK"> to the root element of your XML message. The change the xpath of  <xsl:copy-of select=""/> to match your respetive xpath.
     
    XML
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                    version="1.0">
    	<xsl:output indent="yes"/>
    	<xsl:template match="/">
    		<xsl:element name="WORKBOOK">
    			<xsl:copy-of select="WORKBOOK/ManuObj[position()>1]"/>
    		</xsl:element>
    	</xsl:template>
    </xsl:stylesheet>
  2. Go to the Partner Admin, Manage->XSLT Definitions..,  create the new XSLT Definition.
  3. Go the Process tab in your Partner Admin. Right click and select XSL Transform.
     
  4. Select the XSLT definition you created in Step 2.
     
  5. Make sure XSL Transform process step will be after the FLAT To XML process step in the process tab and Save. (You can add XML Transform after the XSL Transform to implement the logic, transformation you want).
     
     
  6. Test the process and see messages in Admin page. 

     Happy Coding.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Brandix Lanka Pvt Ltd.
Sri Lanka Sri Lanka
I’ve started my career in 2001 with Microsoft .net ver 1.0. I’m a MCSD for .net.

Currently, I’m working for Sri Lanka’s largest apparel exporter as a Software Engineer. All projects in .net, MS Sql Server, Biztalk Server, WCF and WPF. And also, I’m developing components to the ERP. In addition to that, I’ve involved to create architecture of ERP integration.

Comments and Discussions

 
AnswerRemove header row of CSV file. Pin
Dimiter20114-Feb-21 13:20
Dimiter20114-Feb-21 13:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.