cancel
Showing results for 
Search instead for 
Did you mean: 

Read the file from SAP folder and remove commas inside Quotes

former_member183906
Active Contributor
0 Kudos

Hi,

TXT File need to be picked from SAP folder using file adapter.

After implementing below logic file can be put in other sap folder.

If quotes sign appear in line (“) then replace commas with spaces, until closing quotes sign appear (“), after that continue counting of commas as usual and in case of next quotes sign repeat the logic.

Example:
Input - 4,9,3,”55,77,66”,”1,5"

Output should be - 4,9,3,55 77 66,1 5

Can you please let me know how this can be achieved ?

Regards

Accepted Solutions (1)

Accepted Solutions (1)

former_member190293
Active Contributor

Hi Vijay!

If you want to avoid the situation when FCC reacts on comma sign as the field separator within the field value, I would better try using enclosureSign and enclosureSignEsc parameters:

NameA.enclosureSign Specify a string that acts as a text delimiter. Text enclosed by such delimiters is transferred to the target structure unchanged, although the default setting is to remove all text delimiters. Separators within such texts are ignored.

If you specify xml.enclosureSign=" and xml.enclosureSignEsc="" , text enclosed in quotation marks is transferred unchanged and the quotation marks are removed.

https://help.sap.com/saphelp_nw73/helpdata/en/44/6713ec3f914ddee10000000a1553f7/frameset.htm

Regards, Evgeniy.

former_member183906
Active Contributor
0 Kudos

Hi Evgeniy,

Thanks for your reply. Its the perfect one. I needed this only as I am working on a FCC requirement.

Regards

Answers (1)

Answers (1)

former_member207703
Active Participant
0 Kudos

Hi,

Use below set of code in UDF, here -in is String parameter:-

		String out = "";
		try {
		while(in.contains("\"")) {
			out = out + in.substring(0, in.indexOf("\""));
			in = in.substring(in.indexOf("\"")+1, in.length());
			String commaRemove = in.substring(0, in.indexOf("\"")).replaceAll(",", " ");
			out = out + commaRemove;
			in = in.substring(in.indexOf("\"")+1, in.length());
		}
		}catch (StringIndexOutOfBoundsException e) {
			throw new StreamTransformationException("Error while transforming message as number of double quotes are odd."
					+ "For more details please follow the error log : " + e.getLocalizedMessage());
		}
		return out+in;

Please note that if Double Quotes are odd, then it fail to perform its task. 😄

Can you proved more details what you want to do.

Regards,

Anoop Rai