Passing records by reference to functions

When using the record-name.* notation, RECORD structures are passed to functions by copying all record members on the stack.

When the record is big, this can lead to performances issues when the function is called many times, or when chaining function calls passing complete records to each other. This is even more resource consuming, when using CHAR() types.

The next code example shows the execution time improvement when passing a record by reference:

TYPE t_customer RECORD
         cust_id INTEGER,
         cust_name CHAR(100),
         cust_addr CHAR(100),
         cust_comm CHAR(500)
     END RECORD

MAIN
    DEFINE x INTEGER
    DEFINE ts DATETIME HOUR TO FRACTION(5)
    DEFINE cust t_customer

    LET cust.cust_id = 101
    LET cust.cust_name = "Scott Pilgrim"
    LET cust.cust_addr = "5 Market Place"
    LET cust.cust_comm = "..."

    LET ts = CURRENT
    FOR x = 1 TO 1000000
        CALL func1( cust.* )
    END FOR
    DISPLAY CURRENT HOUR TO FRACTION(5) - ts

    LET ts = CURRENT
    FOR x = 1 TO 1000000
        CALL func2( cust )
    END FOR
    DISPLAY CURRENT HOUR TO FRACTION(5) - ts

END MAIN

FUNCTION func1( rec t_customer )
    CALL func11( rec.* )
END FUNCTION
FUNCTION func11( rec t_customer )
    CALL func111( rec.* )
END FUNCTION
FUNCTION func111( rec t_customer )
END FUNCTION

FUNCTION func2( rec t_customer INOUT )
    CALL func21( rec )
END FUNCTION
FUNCTION func21( rec t_customer INOUT )
    CALL func211( rec )
END FUNCTION
FUNCTION func211( rec t_customer INOUT )
END FUNCTION
The above program produces following output:
  0:00:03.70940
  0:00:00.57024
Note: Records passed by reference can be modified by the function.

For more details, see Passing records by reference