Re: Retrieve unique values and its occurrence from a correlation variable (249 Views)
Reply
Occasional Advisor
Satzz
Posts: 12
Registered: ‎09-24-2012
Message 1 of 6 (297 Views)
Accepted Solution

Retrieve unique values and its occurrence from a correlation variable

[ Edited ]

Hello all,

lets say web_reg_save_param function returns a,a,b,c,c.

i need unique values from this result with its occurence.

i have searched for an option in LR.(LR Function)

But i didn't get anything.

please let me know if anything is available other than the tedious logic.

please help me with a solution as soon as possible.

 

 

thanks in advance

satz

Please use plain text.
Frequent Advisor
xtom
Posts: 52
Registered: ‎06-06-2012
Message 2 of 6 (277 Views)

Re: Retrieve unique values and its occurrence from a correlation variable


1) You need to correlate all occurrences of the value in an array:
 web_reg_save_param("<YourVariable>",
  "LB=<YourLB>",
  "RB=<YourRB>",
  "Ord=ALL",
  LAST);

 

2) Then you need to decide which element you want to use
 sprintf(<YourSpecificVariable>,
  "{<YourVariable>_%d}",
  <the array element you want to use, but do not exceed the range; try the value 1> );

 

3) Cretae a new variable with the content of the wanted element
 lr_save_string(lr_eval_string(<YourSpecificVariable>), "<YourCorrelatedValueToUse>");

 

4) From now on you can use the new string in commands and requests
 lr_output_message("The winner is %s ", lr_eval_string("{<YourCorrelatedValueToUse>}"));

 

The steps 2 and 3 are necessary only if you want to have some random in the selection. In this case the number would be a variable value or a parameter value or something similar. But the number of the array element can also be given directly:
 lr_save_string(lr_eval_string("{<YourVariable>_1}"), "<YourCorrelatedValueToUse>" );


 Regards

Thomas

Please use plain text.
Occasional Advisor
Satzz
Posts: 12
Registered: ‎09-24-2012
Message 3 of 6 (274 Views)

Re: Retrieve unique values and its occurrence from a correlation variable

Thanks thomas..

but this is not what i am looking for.

 

To describe in detail;

consider a correlation_parameter which has obtained the following values from the response.

11,11,33,44,55

i need all unique values from the set with any of their occurence.

Expected output:

11- 1 or 2

33 - 3

44 - 4

55 - 5

 

hope this describes you in detail

 

 

Please use plain text.
Frequent Advisor
xtom
Posts: 52
Registered: ‎06-06-2012
Message 4 of 6 (268 Views)

Re: Retrieve unique values and its occurrence from a correlation variable

Hello!

 

I do not know if this can be done using only correlation. I think you need to execute some string operations on the correlated value to get the result you want.

 

Regards

Thomas

Please use plain text.
Valued Contributor
Ajay_U
Posts: 108
Registered: ‎04-30-2012
Message 5 of 6 (264 Views)

Re: Retrieve unique values and its occurrence from a correlation variable

If you have idea on using VTS (Virtual table server) with LoadRunner ..you can do this easily, Refere to VTS functions to write unique values to the columns.

 

Thanks, Ajay

Please use plain text.
Advisor
remo1259
Posts: 16
Registered: ‎06-29-2012
Message 6 of 6 (249 Views)

Re: Retrieve unique values and its occurrence from a correlation variable

Hello Satzz!!

 

 

You can use the below code which will return you unique values. But make sure u change the size(It should be lenght of your array which is captured from web_reg_save_param) according to your values returned.


 int arr[]={11,11,33,44,55};
 int *p;
 int i,j,k,size,n;
 /*
 web_reg_save_param("Array",
  "LB=LeftBoundary",
  "RB=RightBoundary",
  "NotFound=ERROR",
  "IgnoreRedirections=Yes",
  LAST);
*/
 size=5; //Get the length of your array here
 p=arr;

 for(i=0;i<size;i++){
    for(j=0;j<size;j++){
         if(i==j){
             continue;
         }
         else if(*(p+i)==*(p+j)){
             k=j;
             size--;
             while(k < size){
                 *(p+k)=*(p+k+1);
                 k++;
              }
              j=0;
          }
      }
  }
  lr_output_message("\nThe array after removing duplicates is: ");
  for(i=0;i < size;i++){
    lr_output_message("Occurence %d,Value %d",i,arr[i]);
  }


Thanks,
Remo

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation