cancel
Showing results for 
Search instead for 
Did you mean: 

Count function.

Former Member
0 Kudos

Hi Folks,

I have a quick question for you guys. Can any body help me in my mapping.

My problem is ...

I am having a field in sender structure which can hold values like A, B, and C. I just like to know the count the existance of that perticular field which hold the value "C".

note that this field may exists in multiple contexts and multiple times in each context.

Example below.

<Node>

*****<Node>

***********<Node1>

****************<Field1 - A>

****************<Field1 - B>

****************<Field1 - B>

****************<Field1 - C>

****************<Field1 - C>

****************<Field1 - A>

***********<Node1>

****************<Field1 - A>

****************<Field1 - B>

****************<Field1 - C>

****************<Field1 - C>

****************<Field1 - C>

****************<Field1 - A>

***********<Node1>

****************<Field1 - A>

****************<Field1 - B>

****************<Field1 - A>

****************<Field1 - A>

****************<Field1 - B>

****************<Field1 - A>

If i got the sender structure like this i need the out put as

<Node>

*****<Field1 - 2>

*****<Field1 - 3>

*****<Field1 - 0>

Please let me know any body have inputs.

Regards,

Ramana.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Are you sure the field name is same within one context ? I'm doubtful about that.

But if your structure is

<Node>

*****<Node>

***********<Node1>

****************<Field1 - A>

**********</Node1>

<Node1>

<Field1 - C>

</Node1>

<Node>

<Node>

Using if without else, check the value is 'C'

in the then part use the counter function, with increment by 1.

one thing here is that you cannot have field1 in the same context 3 times. You might have to create something like this.

<Node>

<field1>2</field1>

</Node>

<Node>

<field1>3</field1>

</Node>

<Node>

<field1>03</field1>

</Node>

And as many times the Node appears. In short for each Node, you will count how many times the Field1 has value C

Hope this helps.

regards,

Advait

Answers (2)

Answers (2)

Former Member
0 Kudos

HI Ramana

Try a UDF

int a=0,b=0,c=0;

String out="";

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

if (field1<i>.equals("A")){

a++;

System.out.println(""+a);

}

if(field1<i>.equals("B")){

b++;

}

if(field1<i>.equals("C")){

c++;

}

}

if(field1.equals("A"))

return a;

if(field1.equals("B"))

return b;

if(field1.equals("C"))

return c;

Thanks

Gaurav

return

Former Member
0 Kudos

using if condition(without else), check if field1 value is "C". Then the output will contain the fields that are true. Use Count to obtain the required count ( at the required context)

Former Member
0 Kudos

Hi Siva,

while using the count function "How it knows to count the outputs with true or false. i already tried with this logic but its giving uncertain values.