LoadRunner Support Forum
Showing results for 
Search instead for 
Do you mean 

Retrieve unique values and its occurrence from a correlation variable

SOLVED
Go to Solution
Occasional Advisor

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

1 ACCEPTED SOLUTIONS
Highlighted
Advisor

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

5 REPLIES
Frequent Advisor

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

Occasional Advisor

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

 

 

Frequent Advisor

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

Valued Contributor

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

Highlighted
Advisor

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