cancel
Showing results for 
Search instead for 
Did you mean: 

Udf help required for the counting subline items

former_member452321
Participant
0 Kudos

I have line items and subline items in the same context as below. All are in same context

0001
0002
000201
000202
000203
0005
000501
000502
i need to count subline items for each main line item
ex
first line item 0001 has no sub line items so i should set N to target
second main line item has three subline line items so it should set to Y
subline items 000201,000202,000501 all set to blank.
if any main line item has 0 or 1 subline items we should set to N else Y

all subline items length will always 6 and main line items length 4
Thanks for your help

Accepted Solutions (1)

Accepted Solutions (1)

juan_vasquez2
Active Participant
0 Kudos

Hello Mahesh

Try with this code

{
   for (int i=0; i<vec.length; i++)
   {
      if (vec[i].length()==4)
      {
         int count=0;
         for (int j=0; j<vec.length; j++)
         {
            if (vec[j].length()==6)
            {
               if (vec[j].substring(0,4).equals(vec[i]))
               {
                  count=count+1;
               }
            }
         }
         if (count > 1)
            result.addValue("Y");      //when is not 0, and is not 1
         else
            result.addValue("N");      //when is 0 or 1
      }
      else
         result.addValue("");          //subline item set blank
   }
}

Regards

Juan

former_member452321
Participant
0 Kudos

Hi Juan,

Thank you for your help The data is coming this format also with alphanumeric format .

data 1

0001

0001AA

0001AB

0001AB

in this case if we are getting 6 char alphanumeric we should display N for alphanumeric values Expected result for this

N (since it doesn't not have 000101,000102 like - count 0 )

N for all 6 char alphanumeric we don't to match 0001 and 0001AA

data2

0001AA

0001AB

0001AC

0001AD

0001AD

0001AE

Above case it should display N for all of these

Again Thank you very much for your help

Answers (2)

Answers (2)

former_member452321
Participant
0 Kudos

cusersnrp0232889desktopoutput.txt

Thank you for your help Juan . I tried as per your code. I am looking for out put as attached cusersnrp0232889desktopcapture.png below

juan_vasquez2
Active Participant
0 Kudos

hello Mahesh Kumar

you need to evaluate your queue in two for() anidated

first one conditioned with length 4

other inside to find related elements and count

something like this

{
   for (int i=0; i<vec.length; i++)
   {
      if (vec[i].length()==4)
      {
         int count=0;
         for (int j=0; j<vec.length; j++)
         {
            if (vec[j].length()==6)
            {
               if (vec[j].substring(0,4).equals(vec[i]))
               {
                  count=count+1;
               }
            }
         }
      }
   }
}

Regards