on 2009 Sep 04 10:53 AM
Hi friends,
I was trying to write an udf to delete the duplicate values from same context but couldn't get any success.
Source Data
V1
V1
V2
V2
V3
Context Change
V1
V1
V6
V9
I want Result As:
V1
V2
V3
Context Change
V1
V6
V9
I Cannot use CollapseContext because I need to maintain the ContextChange as it is.
Thanks in advance.
Regards,
Sarvesh
Hi Sarvesh,
Try this
boolean flag = false;
int k=0;
String[] output = new String [input1.length] ;
if (input1.length != 0) {
output[k] = input[0];
k++;
for (int i = 1;i<input1.length;i++) {
for (int j = 0; j<output1.length; j++) {
if (input1<i> == output[j]) {
flag=true;
break;
}
else {
flag=false;
}
}
if (!flag) {
output[k] = input<i>;
k++;
}
flag = false;
}
for (int l=0; l<output.length;l++) result.addValue(output[l];
}
input1 is the input and output is the actual output
Regards
Suraj
Edited by: S.R.Suraj on Sep 4, 2009 6:20 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suraj,
There were some little issues in udf which I fixed, but it gives me result as it is without any change. No duplicates were removed.
boolean flag = false;
int k=0;
String[] output = new String [input1.length];
if (input1.length != 0) {
output[k] = input1[0];
k++;
for (int i = 1;i<input1.length;i++) {
for (int j = 0; j<output.length; j++) {
if (input1<i> == output[j]) {
flag=true;
break;
}
else {
flag=false;
}
}
if (!flag) {
output[k] = input1<i>;
k++;
}
flag = false;
}
for (int l=0; l<output.length;l++)
result.addValue( output[l] );
}
> The signature of my code which I tested was
> public void Test (String[] input, ResultList result, Container container) throws StreamTransformationException{
> }
But when I created udf, my signature looks like as shown below and still I am not getting the results.
>public void Test(String[] input,ResultList result,Container container){
What I did,
1. Created udf of type Cache: Context
2. Given Argument as input
Now when I paste your code, it gives error about input1 & output1, so I changed it to input & output. But still no luck.
I am working on XI3.0 SP 22.
Secondly not necessary that every context will have duplicates. So it could be like this also..
V1
ContextChange
V2
V2
V3
ContextChange
V4
ContextChange
V5
V5
See my mapping steps here..
http://www.flickr.com/photos/23639237@N02/3886352697/sizes/o/
Suraj,
I made the input argument as input1. and now it is throwing error. Can not resolve input & output1.
So because of this error, last time I changed input1 to input & output1 to output.
In your code somewhere you have used input and somewhere input1 and also somewhere output & output1.
Can you please review your code again and send the udf again to avoide the confusion.
Regards,
Sarvesh
Hi Sarvesh,
Check this code and let me know
public void Samp(String[] a, ResultList result, Container container) throws StreamTransformationException
{
int k=0;
String b[]= new String[100];
for (int i=0;i<a.length;i++)
{
char flag=0;
if(a<i>.equals(ResultList.CC))
{
result.addValue(ResultList.CC);
flag=1;
}
else
{
for(int j=i1;j<a.length;j+)
{
if(a<i>.equals(a[j]))
{
flag= 1;
}
}
}
if (flag==0)
{
b[k]=a<i>;
result.addValue(b[k]);
k++;
}
}
Regards
Ramesh
Edited by: Venkataramesh Boppana on Sep 4, 2009 10:32 PM
Hi Sarvesh,
Use this code (this is tested in the MEssage Mappiing)
public void calculate(String[] input, ResultList result, Container container) throws StreamTransformationException{
boolean flag = false;
int k=0;
String[] output = new String [input.length];
if (input.length != 0) {
output[k] = input[0];
k++;
for (int i = 1;i<input.length;i++) {
for (int j = 0; j<output.length; j++) {
if (input<i> == output[j]) {
flag=true;
break;
}
else {
flag=false;
}
}
if (!flag) {
output[k] = input<i>;
k++;
}
flag = false;
}
for (int l=0; l<output.length;l++)
result.addValue( output[l] );
}
}
Regards
Suraj
Hi Suraj & Ramesh,
Thanks for your help, but still result in not populating..
I think the udf, which you people have provided is not working because in my system when I create the udf it create a different signature then your's. May be because I am on XI3.0 SP22 and you are on PI.
Your's Signature:
public void calculate(String[] input, ResultList result, Container container) throws StreamTransformationException{
My Signature:
public void calculate(String[] var1, ResultList result, Container container){
So whenever I use your codes it throws below error.
'class' or 'interface' expected.
Any way I created below UDF and it is working fine, but the problem is here I need to assign the array memory to v_current in advance which is not good.
And when I try to give
String[] v_current = new String [var1.lenght];
then in case of single value in context throws the error "ArrayIndexOutOfBound".
Can you suggest some better solution.
My code is:
String[] v_current = new String [100];
int k = 0;
v_current[k] = "";
for(int i = 0; i<var1.length; i++)
{
if( var1.length == 1 )
{
result.addValue( var1<i> );
}
else if( var1<i>.compareTo(v_current[k]) != 0)
{
result.addValue( var1<i> );
k++;
}
v_current[k] = var1<i>;
}
Regards,
Sarvesh.
Hi,
Try to modify your code like this
String[] v_current = new String [var1.length];
for(int i = 0; i<var1.length-1; i++)
{
if( (var1.length -1) == 1 )
{
result.addValue( var1<i> );
}
else if( var1<i>.compareTo(v_current[k]) != 0)
{
result.addValue( var1<i> );
k++;
}
v_current[k] = var1<i>;
}
PS: When there is one value the actual array length is '2' because of the presence of "context"
Regards
Suraj
Hi Sarvesh,
I tried both these code and they were working. In the second code you are definitely missing some parenthesis. Give a complete check:
public void sdn(String[] var1, ResultList result, Container container) throws StreamTransformationException{
int len =var1.length;
String[] v_current = new String [len];
int k = 0;
v_current[k] = "";
for(int i = 0; i<var1.length; i++)
{
if( var1.length == 1 )
{
result.addValue( var1<i> );
}
else if( var1<i>.compareTo(v_current[k]) != 0)
{
result.addValue( var1<i> );
k++;
}
v_current[k] = var1<i>;
}
}
AND
public void calculate(String[] input, ResultList result, Container container) throws StreamTransformationException{
boolean flag = false;
int k=0;
int len = input.length;
String[] output = new String [100];
if (input.length != 0) {
output[k] = input[0];
k++;
for (int i = 1;i<input.length;i++) {
for (int j = 0; j<output.length; j++) {
if (input<i> == output[j]) {
flag=true;
break;
}
else {
flag=false;
}
}
if (!flag) {
output[k] = input<i>;
k++;
}
flag = false;
}
for (int l=0; l<output.length;l++)
result.addValue( output[l] );
}
}
Regards
Suraj
Edited by: S.R.Suraj on Sep 7, 2009 6:12 AM
Hi Suraj,
below is the code which is working perfectly in system..
Hint: No need to increment v_current.
String[] v_current = new String [var1.length];
v_current[0] = "";
for(int i = 0; i<var1.length ; i++)
{
if( var1.length == 1 )
{
result.addValue( var1<i> );
}
else if( var1<i>.compareTo(v_current[0]) != 0)
{
result.addValue( var1<i> );
v_current[0] = var1<i>;
}
}
Regards,
Sarvesh
User | Count |
---|---|
70 | |
10 | |
10 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.