cancel
Showing results for 
Search instead for 
Did you mean: 

Complex CSV file reading

Former Member
0 Kudos

Hi Experts,

I am trying to read a csv file in zip.So I used File adapter module "PayloadZipBean" to unzip and read csv with MTB(Message Transform Bean) and its working fine.

Now I am getting error in case if my file has multi lines for a field value.

Eg::  

field1,field2,field3,filed4

"val1","val2","val3and

desription of line details","val4"

MTB parameters are : is it possible to read multi line values of single field with MTB ,if not what is other best alternate simple approach.

Please let me know the approach not just links as I cant understand the way to go ahead.

zip.modeunzip
Transform.Classcom.sap.aii.messaging.adapter.Conversion
Transform.ContentTypetext/xml;charset=utf-8
xml.conversionTypeSimplePlain2XML
xml.documentNameMT_test_SND
xml.documentNamespacehttp:\\xyz
xml.documentNamespaceScoperoot
xml.enclosureConversionNO
xml.enclosureSign"
xml.encodingUTF-8
xml.endSeparator"'nl'
xml.fieldNames
f1,f2,f3,f4...f10
xml.fieldSeparator,
xml.processFieldNamesfromConfiguration
xml.structureTitleRow

Regards

Siri

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

Siri,

Please follow this blog

Former Member
0 Kudos

Hi Raghu,

Thanks a lot for blog.. I have tried this approach and now I can able to overlook "nl" in data.

I still have 2 queries.

1) If I am having "," in between any data its treating it as separate field.

eg:

"Name2","345",he

is CEO,from now onward","IND"

In such case I am missing "IND"

2) Is UDF remains same if I map it to a RFC, I need to map onlt to relevant segments in target from UDF?

Eg: instead Records. do I need to take my relevant segment?


Records.addValue(""); 


Thanks in advance...

Regards

Siri

RaghuVamseedhar
Active Contributor
0 Kudos

Siri,

1. I have updated the blog to handle comma, please check it.

2. Yes UDF will be same. Please update it according to target structure.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Raghu/all

I observed other issue with this approach..if data is coming like below, its throwing error.

If there is no data coming in any field, its creating just commas ,, with out any quotes ..(check for Name2 row values)

UTF8

Name,ID,Description,Location

"Name1","123","He is developer","IND"

"Name2",,"He is

CEO","IND"

"Name3","567","He is CIO, from today","USA"

How to add same variation to below code

input = input.replace("\",\"", "__________").replace(",", "").replace("__________", "\",\"") 

                 .replace("\"\r\n\"", "__________").replace("\r\n", " ").replace("__________", "\"\r\n\"");

Thanks in advance.

Regards

Siri

RaghuVamseedhar
Active Contributor
0 Kudos

Siri,

Updated the UDF in blog. Please check it.

Former Member
0 Kudos

Hi Varun,

Thanks for your reply..

In this case what should be the alternate way to go ahead.

could you please explain more on custom module or mapping to get this..

Regards

Siri

Former Member
0 Kudos

Hi Sunitha,

Thanks for links ..

1 is about "" which we already handled,

2 is about exactly of my problem ,,but it does not working ..

May I know what could be the solution for this..looks simple but not working with given all options.

Regards

Siri.

Former Member
0 Kudos

Hi Experts,

Good day..

Any inputs for me on this please ...

Regards

Siri

former_member192892
Active Contributor
0 Kudos

Hi Siri,

Unfortunately I don't see this happening without custom module/custom mapping.

Regards

Varun

Former Member
0 Kudos

Hi all,

Any inputs on this for me to read CSV file with multiple lines.

Eg:: 

field1,field2,field3,filed4

"val1","val2","val3and

desription of line details","val4"

Regards,

Siri

sahithi_moparthi
Contributor
0 Kudos


Hi Siri,

<<Any inputs on this for me to read CSV file with multiple lines

You mean that,you have multiple rows in the files ??

If that is the case just mention Row,*.

Can you please provide the sample data for refernce.

Former Member
0 Kudos

Hi Sahiti,

Thanks for reply..

If any one filed value is having line break in it I am getting error,do we have any option to escape "nl" in between filed values.

Eg::  Failing case:

field1,field2,field3,filed4

"val1","val2","val3and

desription of line details","val4"

"val1","val2","val3and

desription of line details","val4"

"val1","val2","val3and

desription of line details","val4"

its processing if data come like this,in single line:

field1,field2,field3,filed4

"val1","val2","val3anddesription of line details","val4"

"val1","val2","val3anddesription of line details","val4"

"val1","val2","val3anddesription of line details","val4"

Regards

Siri.

sahithi_moparthi
Contributor