Skip to Content
0

Delete special characters in the input text file in SAP HCI

Jun 20, 2017 at 02:10 PM

251

avatar image

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Ramu G Jun 20, 2017 at 03:18 PM
0

Hi Experts,

Kindly help on this.

-Ramu.

Share
10 |10000 characters needed characters left characters exceeded
Avinash Bandela Jun 21, 2017 at 03:33 AM
0

Hi Ramu,

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

Thanks & Regards,

Avinash B


udf.jpg (52.9 kB)
Show 1 Share
10 |10000 characters needed characters left characters exceeded

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.

0
Gagandeep Batra Jun 21, 2017 at 07:34 AM
0

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;
}

Share
10 |10000 characters needed characters left characters exceeded
Sriprasad Shivaram Bhat Jun 21, 2017 at 02:13 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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.

invoice.jpg (22.8 kB)
inputfile.jpg (62.8 kB)
inputcsv.jpg (90.6 kB)
0
Sriprasad Shivaram Bhat Jun 21, 2017 at 07:52 AM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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.

capture.jpg (25.0 kB)
capture1.jpg (25.0 kB)
capture3.jpg (41.0 kB)
0