cancel
Showing results for 
Search instead for 
Did you mean: 

UDF for double quotes!

Former Member
0 Kudos

Hello All,

I need to put double quotes for each of the source field coming from file into target.

Although this can be achieved with existing mapping functions, can you provide me a udf which will accept the field and simply insert at the beginning and end a double quotes.

This will be easy for me as I need to do it for 40 fields.

Regards

Anandh.B

Accepted Solutions (0)

Answers (4)

Answers (4)

Ryan-Crosby
Active Contributor
0 Kudos

There would be a lot less work & maintenance involved if you used the receiver FCC you had asked about the other day.

Regards,

Ryan Crosby

Former Member
0 Kudos

have to write simple udf:

public String calculate1(String var1, Container container) throws StreamTransformationException{

return var1 = "''" +  var1 + "''" ;   ( here we have to provide 2 single quotes in double quotes bz if provide double quotes in double quotes then ll get error )

ex input is:

DYP0SAP

ex output is :

''DYP0SAP''
former_member184681
Active Contributor
0 Kudos

Hi,

Well, you don't have to use two single quotes instead of one double quote (apart from it not being acceptable on the receiver side, in most cases; the fact that it looks identical to a human doesn't really mean that computers interpret it as equal). Simply precede the quote with a slash, like this: \" and the quote will not be interpreted as a special character, so you won't get any error. So for instance if you use:

System.out.println("\"");

it outputs a double quote, as required here.

Regards,

Greg

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

I don't know, isn't it easier to copy an existing field mapping with the double quotes and then paste it 40 times and then just replace the copied fields with the correct one?

Regards,

Mark

former_member184681
Active Contributor
0 Kudos

Hi,

Use this UDF, with execution type all values of queue:

for (int i = 0; i < input.length; i++) {

    if (!(input[i].equals(ResultList.CC) OR (input[i].equals(ResultList.SUPPRESS)) {

       result.addValue("\"" + input[i] + "\"");

    }

}

Hope this helps,

Greg

Former Member
0 Kudos

Hi,

The following udf gave me the following error.

  • com/sap/xi/tf/_WMS_DPD_MANIFEST_to_DPD_MANIFEST_SEND_.java[596] ')' expected
    if (!(input[i].equals(ResultList.CC) OR (input[i].equals(ResultList.SUPPRESS)) {
    ^
  • com/sap/xi/tf/_WMS_DPD_MANIFEST_to_DPD_MANIFEST_SEND_.java[601] ')' expected
    ^
  • com/sap/xi/tf/_WMS_DPD_MANIFEST_to_DPD_MANIFEST_SEND_.java[602] illegal start of expression
    }
    ^
    3 errors
former_member184681
Active Contributor
0 Kudos

You're right, there was a problem with some closing parenthesis, here is a corrected code:

for (int i = 0; i < input.length; i++) {

    if (!(input[i].equals(ResultList.CC) OR input[i].equals(ResultList.SUPPRESS))) {

       result.addValue("\"" + input[i] + "\"");

    }

}

Regards,

Greg

Former Member
0 Kudos

sorry, didnt work.

  • if (!(input[i].equals(ResultList.CC) OR input[i].equals(ResultList.SUPPRESS))) {
    ^
  • com/sap/xi/tf/_WMS_DPD_MANIFEST_to_DPD_MANIFEST_SEND_.java[600] ')' expected
    ^
  • com/sap/xi/tf/_WMS_DPD_MANIFEST_to_DPD_MANIFEST_SEND_.java[601] illegal start of expression
    }
    ^
    3 errors
former_member184681
Active Contributor
0 Kudos

Looks like a long time since I have last written Java code... I've completely forgotten that Java uses || for OR in conditions. This code should work well for you, I've just compiled it:

for (int i = 0; i < input.length; i++) {

    if (!(input[i].equals(ResultList.CC) || input[i].equals(ResultList.SUPPRESS))) {

       result.addValue("\"" + input[i] + "\"");

    }

}

Remember to set the execution type to all values of queue. And sorry for the confusion...

Regards,

Greg