cancel
Showing results for 
Search instead for 
Did you mean: 

how can i convert a string to boolean

Former Member
0 Kudos

hai,

iam in need of converting a " string set" in a idoc to a boolean type . is there any simple procedure in graphical mapping to do this ?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Vivek,

You want to convert to boolean to check it in a condition?

e.g,., if (StringSet)

Thanks,

Swapna

Former Member
0 Kudos

swapna,

the boolean type is the final o/p type and its not used for any other condition checking or other purpose ...

Former Member
0 Kudos

Hi Vivek,

If your requirement is just to map string value (containing true or false as values) to a output field of type boolean.

In Graphical Mapping, just map the source field directly to target field.No Conversion is needed and it works.

Stringvalue -> TargetField

Thanks,

Swapna.

Edited by: Swapna Seelam on Jul 22, 2008 8:35 AM

Former Member
0 Kudos

thanks for the answer but in real time scenarios , if in case the user gives yes / no then it may lead to problems . so i think it would be better to use theudf itself

Former Member
0 Kudos

Hi Vivek,

From your query, I was of the impression that you are getting true or false as values and you need to convert to boolean.

If it is a real-time scenario with users having an opton to enter their text, then even to use a UDF, you need to know what all are the possible ways the user can send a true value (true, yes, correct,right).A little fast then may be even just 'S' :).

And just one info Boolean.parseBoolean(strName); it does return boolean value, but for UDF the return type is String, so you do not need this. You just have to get the list of possible values and then say

if(String.equalsIgnoreCase("true") || String.equalsIgnoreCase("yes") )

{

return "true";

}

or may be even value-mapping.

Thanks,

Swapna.

Edited by: Swapna Seelam on Jul 22, 2008 1:33 PM

Edited by: Swapna Seelam on Jul 22, 2008 1:36 PM

Answers (2)

Answers (2)

prateek
Active Contributor
0 Kudos

In UDF of graphical mapping, u may use the following code:

String strName = "true";

Boolean bool=new Boolean(strName);

boolean b=bool.booleanValue();

OR

boolean b = Boolean.parseBoolean(strName);

System.out.println (b);

Regards,

Prateek

Former Member
0 Kudos

Well you can use a java code to achieve the same, but I am not sure as to what exactly your requirement is. The reason being the UDF will eventually output a string only.

String str;

boolean b;

b=Boolean.parseBoolean(str);

// Do your validations with b and then finally return a string

String finalStr = new Boolean(b).toString();

BR