4. Designing and Writing OpenROAD Server Applications : OpenROAD Parameter Data COM Object : DeclareAttribute Method : GetAttribute Method
 
Share this page                  
GetAttribute Method
The GetAttribute method retrieves the value of a named parameter that was passed by reference and modified by the called 4GL procedure. When a PDO is passed through ByRef to the RSO CallProc method, the data contained in the PDO may be modified by the 4GL procedure. The PDO GetAttribute method lets you extract modified data from the PDO.
Attribute names are constructed using 4GL “dot” syntax, the same as in the SetAttribute method:
HRESULT GetAttribute
    (
        [in] BSTR AttributeName,
        [out, retval] VARIANT * AttributeValue
    );
This method uses the following parameters:
AttributeName
Takes a string containing the name of the scalar attribute from which the value is to be retrieved. If the attribute is a nested attribute, its position in the hierarchical structure is expressed using OpenROAD 4GL “dot” syntax, just as in the SetAttribute method.
AttributeValue
Specifies a retval that receives a copy of the value currently stored in the VARIANT represented by that AttributeName. Because it is a retval, scripting languages return this using syntax that represents a function return value.
Set orPDO = Server.CreateObject (“OpenROAD.ParameterData”)
 orPDO.DeclareAttribute “p_id”, “INTEGER”
 orPDO.DeclareAttribute “uc_emp”, “USERCLASS”
 orPDO.DeclareAttribute “uc_emp.empname”, “STRING”
 orPDO.DeclareAttribute “uc_emp.hiredate”, “DATE”

orPDO.SetAttribute “p_id”, 11
...
orRSO.CallProc “gethiredate”, ,orPDO
...
vhiredate = orPDO.GetAttribute “hiredate”
Note:  The AttributeValue is always coerced to the data type declared for the attribute. Even though the value was already coerced to the declared data type by the SetAttribute method, the 4GL procedure may modify the data when a PDO is passed by reference to the CallProc. Because of the return mapping preferences, it may return a value that is not precisely the same type that was passed in.
For example, a FLOAT value mapped through ByRef to a DECIMAL 4GL parameter comes back as a DECIMAL VARIANT value. Coercing on the GetAttribute promotes the most predictable behavior for all scripting languages. It is possible—though highly unlikely—for this output coercion to fail because of different range limitations of similar types.
Three special cases are supported that bypass this coercion requirement: VT_EMPTY, VT_NULL, and the OpenROAD blank DATE (an empty string stored in a DATE attribute). Those special case values are retrieved from the associated VARIANT without coercion.
Depending on the scripting language in use, the assignment statement used for the GetAttribute call may not be able to process those special case values (VT_EMPTY, VT_NULL, empty string). Therefore, special methods (IsEmpty, IsNull, IsBlankDate) are provided to safely test an attribute value for special cases before attempting to get and assign the value to a program variable.
Note:  The GetAttribute method can retrieve scalar attributes only. To check whether a structured attribute (that is, a user class or user class array) is empty or null, you must use the IsEmpty or IsNull methods.