Parameter Arrays

Some functions find matches inside data and save the results in a parameter. When more than one match is located, some of these functions save data in multiple parameters, numbered to emulate an array.

The members of the array are named with the base parameter name, an underscore, and an ordinal number. The number of items found is stored in a parameter named with the base parameter name, an underscore and "count".

For example:

  1. A function is passed an output parameter name, "myparam".
  2. The function returns 10 values.
  3. The function creates 10 parameters and assigns the return values to them. The parameter names are myparam_1, myparam_2, myparam_3, ..., myparam_10.
  4. The function creates parameter myparam_count, and assigns it the value 10.

Some of the functions that can create parameter arrays are lr_save_param_regexp, web_reg_save_param_ex, web_reg_save_param_xpath, web_reg_save_param_regexp, and sapgui_call_method_of_active_object_ex.

Concept Link IconSee Also

Example of Parameter Array Use

In this example, lr_save_param_regexp is used to search a buffer and find all the substrings containing "XX", any two characters, and "YY".


    char * bufferToSearch =
    int matchCt, ord;
    char *arrayMemberValue;

    lr_save_param_regexp (
               LAST );

    matchCt = lr_paramarr_len("reMatchesParam");

    lr_message("%d match(es) found.", matchCt);

    for (ord=1; ord <= matchCt; ord++){

               arrayMemberValue =
                   lr_paramarr_idx("reMatchesParam", ord);

               lr_message("Member %d value: %s",
                   ord, arrayMemberValue);


    return 0;

4 match(es) found.
Member 1 value: XX11YY
Member 2 value: XX22YY
Member 3 value: XX33YY
Member 4 value: XX44YY

Example of Populating a Parameter Array

You can create a parameter array by populating the elements <name>_n. For example:
    lr_save_string("value1", "MyTestParamArray_1");
    lr_save_string("value2", "MyTestParamArray_2");

This code uses lr_save_string and strtok to extract values frin a string and populate the array.

token = (char*) strtok(buffer, "\n"); // Get the first token 
if (token == NULL) { 
	lr_error_message ("No tokens found in string!"); 
	return -1; 
i = 0;
while (token != NULL) { // While valid tokens are returned 
	sprintf(param_buf, "MyTestParamArray_%d", i);
	lr_save_string(token, param_buf);
	token = (char*) strtok(NULL, "\n"); 

lr_save_int(i, "MyTestParamArray_count");
// Print all values of the parameter array.
for (i=1; i<=lr_paramarr_len("MyTestParamArray"); i++) {
		lr_output_message("Parameter value: %s", lr_paramarr_idx("MyTestParamArray", i));