cancel
Showing results for 
Search instead for 
Did you mean: 

Delete special characters in the input text file in SAP HCI

ramu_g4
Participant
0 Kudos

Hi Experts,

We are working on File to IDoc scenario where the input file would like below:

Input :-

"Name","Employee_No","Dept","Location" ==> Header line

"Ramu","439554","Manlog","Newyork" ==> Line item

"Raju","837823","ISU","Chicago ==> Line item

We need to remove " " characters from the input flat file & convert it to as below without " ":

Output :-

Name,Employee_No,Dept,Location ==> Header line

Ramu,439554,Manlog,Newyork ==> Line item

Raju,837823,ISU,Chicago ==> Line item

Bold letters above is the content of file. Once I remove the " " characters then using CSV to XML converter I can transform it to XML and map it to IDoc structure.

Hence, kindly help me with groovy script to remove " " as above or any other alternate solution you can provide in HCI.

-Ramu.

Accepted Solutions (0)

Answers (5)

Answers (5)

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Ramu,

Standard converter will work with only one level data.

If I am not wrong you need to populate fields under Header and LineSplit(as per the above screenshot),if that's the case refer my blog.

If both line and lineaplit fields needs to be populated from input CSV in one shot then no other go you have to write a script and do you have any identifier in your CSV so that we can differentiate line and linesplit values.

Regards,

Sriprasad Shivaram Bhat

ramu_g4
Participant
0 Kudos

Hi Shivaram,

Thank you for your useful & valuable glog 🙂

In my case we need to populate data to two sub nodes Header & Line as shown below:

Also input file consists of header line which we need to exclude while populating the data to subnodes.

Please find snippet of input file:

Please help me to achieve this requirement.

Thanks,

Ramu.

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Ramu,

As per my understanding CSV to XML converter will automatically remove those double quotes post conversion..I dont think its required to remove those manually before conversion.

Also those double quotes are very much important to differentiate the fields from converter perspective.

Please give a try from your end with Converter( Its working fine for me ) and still if you are able to locate the double quotes post conversion please do reply back.Will try to help on that if required.

Regards,

Sriprasad Shivaram Bhat

ramu_g4
Participant
0 Kudos

Hi Shivaram,

Thanks for your response. My input file will have header names in top column * line item values below. In my case we need to convert that CSV to XML with 3 sub-nodes and under that sub-nodes actual fields exist. Just like below.

For eg: I have given "Header" node fields as below, similarly fields are present under "Line" & "LineSplit" subnodes.

Kindly suggest me on CSV to XML converter configuration in HCI as below to achieve this requirement.

- Ramu.

gagandeep_batra
Active Contributor
0 Kudos

Hi

You can try this in groovy script ---

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
def body = message.getBody(java.lang.String) as String;


body = body.replaceAll('\\"','');


def messageLog = messageLogFactory.getMessageLog(message);
if(messageLog != null){
messageLog.setStringProperty("Logging#1", "Printing Payload As Attachment")
messageLog.addAttachmentAsString("ResponsePayload:", body, "text/plain");
}
return message;
}

former_member216164
Participant
0 Kudos

Hi Ramu,

Assuming you have less number of fields. Try using this simple UDF.

Thanks & Regards,

Avinash B

ramu_g4
Participant
0 Kudos

Hi,

Firstly we are not using PI here & we are using HCI :). Also I need to remove "" from not only line item values but also from header values.

I need help on groovy script here in HCI.

-Ramu.

ramu_g4
Participant
0 Kudos

Hi Experts,

Kindly help on this.

-Ramu.