Skip to Content
avatar image
Former Member

Count function.

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 30, 2008 at 05:12 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 30, 2008 at 05:06 PM

    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)

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

  • avatar image
    Former Member
    Sep 30, 2008 at 06:44 PM

    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

    Add comment
    10|10000 characters needed characters exceeded