cancel
Showing results for 
Search instead for 
Did you mean: 

HCI: How to Skip CSV header line when using CSV to XML Converter

0 Kudos

Hi folks,

I have an incoming CSV file with header line.

I want to use the "CSV to XML Converter" to convert the CSV file to XML file start from line 2.

Can the "Record Marker in CSV" achieve that?

Test Data :

employeeid, first_name, last_name

1, Bean, Jelly

2, Butter, Peanut

Expected Result:

<?xml version="1.0" encoding="UTF-8"?>

<DT_HCI_Conversion>

  <Line>

    <employeeid>1</employeeid>

    <first_name>Bean</first_name>

    <last_name>Jelly<last_name>

  </Line>

  <Line>

    <employeeid>2</employeeid>

    <first_name>Butter</first_name>

    <last_name>Peanut<last_name>

  </Line>

</DT_HCI_Conversion>

Thank you.

Regards,

YingHeng

Accepted Solutions (1)

Accepted Solutions (1)

Sriprasadsbhat
Active Contributor
0 Kudos

Helo YingHeng,

You need to add script step before convertor step and use the below script.

Script:

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;

def Message processData(Message message)

{

      def body = message.getBody(String.class);

      body = body.substring(body.indexOf('\n')+1);

      message.setBody(body);

     return message;

}

Please note a we don't have option in CSV to XML convertor.

Regards,

Sriprasad Shivaram Bhat

0 Kudos

Helo Sriprasad,

Thank you for your quick respond.

Ya, we're aware of adding a script step before converter can achieve the same result.

But we want to check is there any alternative way can achieve the same result by using the CSV to XML Converter itself.

By referring to the documentation, it stated the field of "Record Marker in CSV" can control starting point of the content.

Do you have any idea to how utilize "Record Marker in CSV" field?

Thank you.

Regards,

Ying Heng

Sriprasadsbhat
Active Contributor
0 Kudos

Hello YingHeng,

Yes you can utilize the above option.

For Example if you add record marker as 'RECSTART'.

1) All the rows in your CSV having first column RECSTART will be considered for conversion.

2) Records without having first column value RESSTART will be ignored for conversion.

Convertor Configuration:

Input:

Output:

I guess in your case leave the record marker blank in first row and have the record marker for rest of the rows in your csv.

Regards,

Sriprasad Shivaram Bhat

0 Kudos

Hi Sriprasad,

Thank you very much for your example on "Record Marker on CSV".

I don't think the "Record Marker on CSV" can help to eliminate the header line in my case.

At the moment we will use script before the CSV to XML Converter to skip CSV header line.

Thank you.

Regards,

Ying Heng

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Ying,

Thanks for the update.Please close the thread.

Regards,

Sriprasad Shivaram Bhat

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Ying,

In sender file channel with message protocol as FCC, where you can see a parameter Document Offset on the control conversion tab. The Document Offset is use to ignore the number of lines.

example: If you provide the value as "1" for document offset it will ignore the first line from the file and which is your requirement here.

Thanks

Sagarika

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Sagarika and  Baskaran,

Unfortunately In SAP HCI-PI FCC [ Adapter Level ] is not available.

Regards,

Sriprasad Shivaram Bhat

0 Kudos

Hi Ying,

A suggestion from my side.

We have an option of Document Offset in File Adapter (FCC is enabled under Message protocol). This parameter asks for the number of lines to be skipped(starting from the first line) while processing a CSV file. For your requirement, you need to set this value as 1.

Hope this helps.