cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help on UDF

Former Member
0 Kudos

Hi all,

we are working on a UDF to remove "blank or SUPPRESS lines" from context.

we found below useful code, But, it is not yet in working condition.

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

              {

              if (!a[i].equals(ResultList.SUPPRESS) || !a[i].equals(""))

              {

              result.addValue(a[i]);

              }

              }

Can someone pls help with the steps & any changes needed on above code....


Accepted Solutions (0)

Answers (1)

Answers (1)

baskar_gopalakrishnan2
Active Contributor
0 Kudos

I dont know your requirement completely. But I see a error. Since you use string array , you need to use a.length not length().  Do as below..

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

   {

              if (!a[i].equals(ResultList.SUPPRESS) || !a[i].equals(""))

              {

              result.addValue(a[i]);

              }

    }

You might also want to see Bill's reply very similar to your requirement on this thread

http://scn.sap.com/thread/3203963

Former Member
0 Kudos

Hi.

Try this.

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

{

if (!a[i].equalsIgnoreCase(ResultList.SUPPRESS) || !a[i].equals(""))

{

result.addValue(a[i]);

}

}

Former Member
0 Kudos

Thank you baskar.

Our requirement is to remove blank contexts from below screenshot & output only those contexts , which has values. In case of below example, am expecting output value of "GB1-IRVAT-TX" .

By changing a.length from a.length() , it is error free code now. But, still not giving desired results.

Below is the source code snapshot,

Thank you for your help....

Former Member
0 Kudos

Hi.

Please add trim() to remove blanks.

....!a[i].trim().equals(""))

Regards

Lucho.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Please try this logic.

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

{

    if(a[i] != null && !a[i].equals("") && !a[i].equals(Resultset.SUPPRESS))

    {

      result.addValue(a[i]);

    }

}

Former Member
0 Kudos

Hi Baskar,

Your if condition,

  if(a[i] != null && !a[i].equals("") && !a[i].equals(Resultset.SUPPRESS))

would go thru, only if all && conditions are met.

which is not true. Only 1 of the above conditions is true @ any given time.

I tried the above code as well. But, no results....

But, even OR condition is also not giving desired results...

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

              {

          if (!a[i].equalsIgnoreCase(ResultList.SUPPRESS) || !a[i].equals(""))

              {

              result.addValue(a[i]);

              }

              }

Not sure, what is going wrong....


former_member184681
Active Contributor
0 Kudos

Hi,

The trim function mentioned by Lucho is the key to your requirement. Also, bear in mind that the following conditions are equivalent:

not (A or B or C)

not A and not B and not C

After all, here is the code for your requirement:

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

  if (!a[i].equals(ResultList.SUPPRESS) && !a[i].trim().equals("")) {

    result.addValue(a[i]);

  }

}

The condition you had:

!a[i].equalsIgnoreCase(ResultList.SUPPRESS) || !a[i].equals("")

is always true, since a[i] is always either different than SUPPRESS, or different from empty .

Regards,

Greg

Ryan-Crosby
Active Contributor
0 Kudos

Hi Santosh,

This code bit would solve your problem if included with the following import:

import java.util.regex.*;

For each string value make sure the value is not null, then the regular expression matching will toss out any empty string or blank only values.

Regards,

Ryan Crosby