Highlighted
Valued Contributor.
4451 views

Retrieve unique values and its occurrence from a correlation variable

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.

satz

1 Solution

Accepted Solutions
Highlighted
Absent Member.

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
Highlighted
Absent Member.

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

Highlighted
Valued Contributor.

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

Highlighted
Absent Member.

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

Highlighted
Super Contributor.

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
Absent Member.

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

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.