LocalScope Attribute
Data Type: scope
4GL Access: R
The LocalScope attribute contains the scope object that determines the currently in-scope local variables and procedures in the frame, procedure, or method being executed.
This is particularly useful in frames, where variables and procedures may be declared at the field script level, and variables may be declared at the event level.
For example, both QueryObject and StringObject text attributes can contain embedded variable names (see the StringObject.ExpandParm method (see
ExpandParm Method) for a description of embedded variable names), and both accept scope as a parameter to method calls to provide the context in which the variables are to be evaluated. However, if one or more of the embedded variables is declared in the current event block or the field script to which this event block belongs, they will not be visible in the frame’s scope, but they will be visible in the frame’s local scope, enabling the variables to be evaluated successfully.
LocalScope is typically used in conjunction with the ProcExec Parent attribute, enabling the code to navigate back to the calling frame to access its LocalScope. You can use a similar approach to introduce enhanced tracing facilities into development and runtime applications.
The only alternative to this approach is to include the local scope as a parameter in all intervening procedure and method calls that potentially could result in a QueryObject or StringObject using embedded variables. Setting a global variable to reference the scope instead is not recommended because outcomes are unpredictable (the references will remain when the current scope expires) and cannot be supported.
Example—LocalScope Attribute:
A customer detail frame contains a customername field for the end user to specify the existing customer they are about to register for an upgrade. But there is a testquery option for the end user to check that everything is acceptable before sending customer’s details.
ON CLICK runtestquerybtn =
DECLARE
customername = varchar(256) NOT NULL DEFAULT 'John Doe';
ENDDECLARE
BEGIN
rc = customer.Register();
IF rc = SYSTEM_IS_DOWN THEN
Customer.ExpressGracefulRegrets();
RESUME;
ENDIF;
...
END
...
METHOD Register (
DECLARE
caller = ProcExec DEFAULT NULL;
ENDDECLARE
)=
BEGIN
/*
** Set the whereclause of the previously defined QueryObject
*/
query.RunTimeWhere = 'customer_name = :customername';
/*
** Get the relevant scope
*/
caller = curMethod.Parent;
WHILE caller.IsA(FrameExec) = FALSE DO
caller = caller.Parent;
ENDWHILE;
query.Scope = caller.LocalScope;
/*
** Run the query
*/
query.Open(querymode=QM_CACHE) ;
/*
** Respond to "system up" check
*/
IF query.MaxRow != SYSTEM_IS_UP THEN
RETURN SYSTEM_IS_DOWN;
ENDIF;
/*
** Continue with registration
*/
...
RETURN ER_OK;
END;
Last modified date: 06/25/2024