Skip to Content

Read the file from SAP folder and remove commas inside Quotes

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Mar 23 at 02:11 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Evgeniy,

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

      Regards

  • Mar 23 at 02:20 PM

    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. :D

    Can you proved more details what you want to do.

    Regards,

    Anoop Rai

    Add comment
    10|10000 characters needed characters exceeded