cancel
Showing results for 
Search instead for 
Did you mean: 

User defined func: Unavble to merge two arrays in result list

Former Member
0 Kudos

Hi

I am trying to merge two arrays on the basis of "FEE" element in the input file;

Actually there is an Attribute Name and Value pair array coming in the input file which has 5 pairs already(Notification + 100 , oversize + 8 etc.) see example below;

<m0:Fees>ZB9</m0:Fees>

<m:Attribute>

<m0:Attributename>NOTIFICATION</m0:Attributename>

<m0:Attributevalue>100</m0:Attributevalue>

</m:Attribute>

<m:Attribute>

<m0:Attributename>OVERSIZE</m0:Attributename>

<m0:Attributevalue>8</m0:Attributevalue>

</m:Attribute>

<m:Attribute>

<m0:Attributename>OVERWEIGHT</m0:Attributename>

<m0:Attributevalue>108</m0:Attributevalue>

</m:Attribute>

<m:Attribute>

<m0:Attributename>SIGNATURE</m0:Attributename>

<m0:Attributevalue>294</m0:Attributevalue>

</m:Attribute>

<m:Attribute>

<m0:Attributename>RTS</m0:Attributename>

<m0:Attributevalue>8</m0:Attributevalue>

</m:Attribute>

The condition is:

CASE 1. If the FEE doesn't exist in the file then only the Atrribute Name and Value in added to the Array

CASE 2 If FEE exist then add all the Atrribute Name and Value pairs as well as in the last index of Array add String "Fee" in Attributename and String "ZB9" in Attributevalue.

CASE 1 is working fine.

but in CASE 2 even if i m taking an output array of length Attributename +1 and Attributevalue +1 and trying to add "Fee" and "ZB9" respectively, it never happens.

Please have a look at the code below;

//write your code here

public void ud_Attributename(String[] Fees,String[] Attributename,ResultList result,Container container){

String attribute_copy[]=new String[Attributename.length+1];

String attribute_name[]=new String[Attributename.length];

String array_copy1[]=new String[Attributename.length+1];

//int len =Attributename.length;

if(Fees[0]!=null)

{

if(Fees[0].equals("ZB0"))

Fees[0]="01";

else if(Fees[0].equals("ZB5"))

Fees[0]="02";

else if(Fees[0].equals("ZB6"))

Fees[0]="03";

else if(Fees[0].equals("ZB9"))

Fees[0]="04";

}

try{

if((Fees[0]=="01")||(Fees[0]=="02")||(Fees[0]=="03")||(Fees[0]=="04"))

{

for(int x=0;x<=Attributename.length;x++)

{

if(x==Attributename.length)

{

array_copy1[x]="Fee";

}

else{

array_copy1[x]=Attributename[x];

}

result.addValue(array_copy1[x]);

}

else

{

for(int i=0;i<=len;i++)

{

attribute_name<i>=Attributename[i+1];

result.addValue(attribute_name<i>);

}

}

}catch(Exception e)

{e.printStackTrace();}

}

Same way i've used for Attributevalue.

But the result is

<ATTRIBUTEPAIR>

<PAIR>

<NAME>NOTIFICATION</NAME>

<VALUE>04</VALUE>

</PAIR>

<PAIR>

<NAME>OVERSIZE</NAME>

<VALUE>8</VALUE>

</PAIR>

<PAIR>

<NAME>OVERWEIGHT</NAME>

<VALUE>108</VALUE>

</PAIR>

<PAIR>

<NAME>SIGNATURE</NAME>

<VALUE>294</VALUE>

</PAIR>

<PAIR>

<NAME>RTS</NAME>

<VALUE>8</VALUE>

</PAIR>

</ATTRIBUTEPAIR>

Please suggest where i am wrong. ur help is very much appreciated.

Thnks in advance

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

1.the UDF is an advanced UDF for the entire queue

2. Input array has values

SUPPRESS

NOTIFICATION

NOTIFICATION

OVERSIZE

OVERSIZE

OVERWEIGHT

OVERWEIGHT

SIGNATURE

SIGNATURE

RTS

RTS

The I/P and O/P structure is

Input

LineItem - 0..Unbounded (root of fees and Attribute)

Fees - 0..1 (Note fee is the part of different structure)

Attribute - 0..unbounded (root of name and value)

Attributename - 0..1

Attributevalue - 0..1

Output

AttributePair - 0..Unbounded (root of pair)

Pair - 0..Unbounded (root of name and value)

Name - 0..1

Value - 0..1

lnirmala
Participant
0 Kudos

Hi Naina,

In your case the output structure is :

Output

AttributePair - 0..Unbounded (root of pair)

Pair - 0..Unbounded (root of name and value)

Name - 0..1

Value - 0..1

So even if the output queue contain all the values Fee and Notification come in the same context of Pair.Since Name can appear only once in the node Pair it will take only the first value "Fee".

Rgds,

Lekshmi.

lnirmala
Participant
0 Kudos

Hi Naina,

Try to add SplitByValue(each value) after your UDF,then it may work.

Rgds,

Lekshmi.

Answers (9)

Answers (9)

Former Member
0 Kudos

u are right Lekshmi

thnks

Former Member
0 Kudos

hey lekshmi

i tried this code and it worked for me

//write your code here

int len=Attribute.length;

if(Fees[0]!=null)

{

for(int i=0;i<len;i++)

{

result.addValue(Attribute<i>);

}

result.addValue(Attribute[0]);

}

else

{

for(int i=0;i<len;i++)

{

result.addValue(Attribute<i>);

}

}

thank u so much

Former Member
0 Kudos

dint get it.......i mean i wrote a UDF

public void ud_Pair(String[] Fees,String[] Attribute,ResultList result,Container container){

int len=Attribute.length+1;

if(Fees[0]!=null)

{

for(int i=0;i<=len;i++)

{

result.addValue(Attribute<i>); // this shud generate 1 more pair node then the actual Attribute nodes on left

}

}

else

{

for(int i=0;i<len;i++)

{

result.addValue(Attribute<i>);

}

}

but it gives array index out of bound exception

lnirmala
Participant
0 Kudos

Hi Naina,

I dont think you need any new UDF over there.As per my understanding you want to generate the root node Pair as many number of attributeName or attributeValue in the output.

So instead of writing a new UDF u can give Fee element and AttributeName as input to your earlier UDF which will give all the set of attribute names,then use removeContexts function and map it to Pair node.So based on the number of attributevalue it will generate the Pair node.

Rgds,

Lekshmi.

Former Member
0 Kudos

hi

basically i knw wat is the problem now....source node ATTRIBUTE is directly linked to target node PAIR....whereas FEES is another node so it creates only that many target node as there are in ATTRIBUTE

The I/P and O/P structure is

Input

LineItem - 0..Unbounded (root of fees and Attribute)

Fees - 0..1 (Note fee is the part of different structure)

Attribute - 0..unbounded (root of name and value)

Attributename - 0..1

Attributevalue - 0..1

Output

AttributePair - 0..Unbounded (root of pair)

Pair - 0..Unbounded (root of name and value)

Name - 0..1

Value - 0..1

How may i get one more PAIR node on right side to accommodate Fee and its value ??

lnirmala
Participant
0 Kudos

Hi Naina,

To generate the Pair node with same number of attribute name and attribute values you use the same UDF.

Fees----


|

AttributeValue-----|UDFRemoveContexts--Pair

This should solve your issue.

Rgds,

Lekshmi.

Former Member
0 Kudos

thnks Lekshmi it worked....but the problem is.....the last element i.e RTS is missing now

the result is now

<ATTRIBUTEPAIR>

<REF_HANDLE>0001</REF_HANDLE>

<PAIR>

<NAME>FEE</NAME>

<VALUE>ZB9</VALUE>

</PAIR>

<PAIR>

<NAME>NOTIFICATION</NAME>

<VALUE>04</VALUE>

</PAIR>

<PAIR>

<NAME>OVERSIZE</NAME>

<VALUE>8</VALUE>

</PAIR>

<PAIR>

<NAME>OVERWEIGHT</NAME>

<VALUE>108</VALUE>

</PAIR>

<PAIR>

<NAME>SIGNATURE</NAME>

<VALUE>294</VALUE>

</PAIR>

</ATTRIBUTEPAIR>

so the last element RTS and its value 8 is missing.

Although it is coming in the display queue

SUPPRESS

FEE

FEE

NOTIFICATION

NOTIFICATION

OVERSIZE

OVERSIZE

OVERWEIGHT

OVERWEIGHT

SIGNATURE

SIGNATURE

RTS

RTS

Former Member
0 Kudos

this is i am doing now

//write your code here

String attribute_copy[]=new String[Attributename.length+1];

String attribute_name[]=new String[Attributename.length];

String attribute_name1[]={"Fee"};

//String[] Attributename.copyTo(attribute_name1,0);

//String[] attribute_name1 = (String[]) Attributename.Clone();

//String fees;

String array_copy1[]=new String[Attributename.length];

int len =Attributename.length;

for(int y=0;y<len;y++){

array_copy1[y]=Attributename[y];

}

if(Fees[0]!=null)

{

if(Fees[0].equals("ZB0"))

Fees[0]="01";

else if(Fees[0].equals("ZB5"))

Fees[0]="02";

else if(Fees[0].equals("ZB6"))

Fees[0]="03";

else if(Fees[0].equals("ZB9"))

Fees[0]="04";

else if(Fees[0].equals("ZA1"))

Fees[0]="05";

else if(Fees[0].equals("ZA2"))

Fees[0]="06";

}

try{

if((Fees[0]=="01")||(Fees[0]=="02")||(Fees[0]=="03")||(Fees[0]=="04")||(Fees[0]=="05")||(Fees[0]=="06"))

{

int j=0;

for(int a=0;a<=len;a++)

{

if(j==0&&attribute_copy[j]==null)

{

attribute_copy[j]="Fee";

}

else

{

//int b=-1;

for(int i=0;i<=len;i++)

{

if(i==j)

{

//i=i-1;

attribute_copy[j]=array_copy1[i-1];

break;

}

else{

continue;}

}

}

result.addValue(attribute_copy[j]);

j+=1;

}

}

else

{

for(int i=0;i<=len;i++)

{

attribute_name<i>=Attributename[i+1];

result.addValue(attribute_name<i>);

}

}

}catch(Exception e)

{e.printStackTrace();}

and the result in queue is

SUPPRESS

[FEE]

[NOTIFICATION]

[NOTIFICATION]

[OVERSIZE]

[OVERSIZE]

[OVERWEIGHT]

[OVERWEIGHT]

[SIGNATURE]

[SIGNATURE]

[RTS]

[RTS]

but in the output i m getting

<ATTRIBUTEPAIR>

<REF_HANDLE>0001</REF_HANDLE>

<PAIR>

<NAME>Fee</NAME>

<VALUE>04</VALUE>

</PAIR>

<PAIR>

<NAME>OVERSIZE</NAME>

<VALUE>8</VALUE>

</PAIR>

<PAIR>

<NAME>OVERWEIGHT</NAME>

<VALUE>108</VALUE>

</PAIR>

<PAIR>

<NAME>SIGNATURE</NAME>

<VALUE>294</VALUE>

</PAIR>

<PAIR>

<NAME>RTS</NAME>

<VALUE>8</VALUE>

</PAIR>

</ATTRIBUTEPAIR>

Notification is missing.

Former Member
0 Kudos

yes lakshmi i am getting correct output in display queue. But not in the final output. its very strange.

Suraj - the result is same.

former_member187339
Active Contributor
0 Kudos

Hi,

A little change in one section of the code


if(Fees[0]!=null){
		if(Fees[0].equalsIgnoreCase("ZB0"))
			fees_value="01";
		else if(Fees[0].equalsIgnoreCase("ZB5"))
			fees_value="02";
		else if(Fees[0].equalsIgnoreCase("ZB6"))
			fees_value="03";
		else if(Fees[0].equalsIgnoreCase("ZB9"))
			fees_value="04";
	}

And few checkpoints for you.

1. This udf shoudl be an advanced UDF for the entire queue (and not context)

2. The Input array shoudl not have any context change ie the display queue should give values as

NOTIFICATION

OVERSIZE

OVERWEIGHT

SIGNATURE

RTS

3. Hope you need an output display queue as per your example as

NOTIFICATION

OVERSIZE

OVERWEIGHT

SIGNATURE

RTS

FEES

Can you paste here the input and output of your display queue (after using this UDF)

Regards

Suraj

lnirmala
Participant
0 Kudos

Hi Naina,

Could you pls give the exact source and target data type structure?

It looks like the UDF is working fine but the target structure is not designed to accomodate the occurences.

First check the source and target structures.

Rgds,

Lekshmi.

lnirmala
Participant
0 Kudos

Hi Naina,

Just a small doubt here...are you getting any exceptions while executing this UDF?

If no then what is the output when you right click on the UDF and go for Display queue??Are you getting desired output in the display queue?

Rgds,

Lekshmi.

former_member187339
Active Contributor
0 Kudos

Hi Naina,

If I understood your requirement completely then this code shoudl work:


public void ud_Attributename(String[] Fees,String[] Attributename,ResultList result,Container container){
	
	String fees_value = null;
	if(Fees[0]!=null){
		if(Fees[0].equals("ZB0"))
			fees_value="01";
		else if(Fees[0].equals("ZB5"))
			fees_value="02";
		else if(Fees[0].equals("ZB6"))
			fees_value="03";
		else if(Fees[0].equals("ZB9"))
			fees_value="04";
	}

	try{
		if((fees_value.equalsIgnoreCase("01")||(fees_value.equalsIgnoreCase("02")||(fees_value.equalsIgnoreCase("03")||(fees_value.equalsIgnoreCase("04"))	{
			for(int x=0;x<=Attributename.length;x++){
				result.addValue(Attributename[x]);
			}
		result.addValue("Fee");	
		}			
		else{
			for(int i=0;i<=len;i++){
				attribute_name<i>=Attributename[i+1];
				result.addValue(attribute_name<i>);
			}
		}
	}
	catch(Exception e){
			e.printStackTrace();
	}

Regards

Suraj