SCL Fundamentals |
SCL variables have most of the same attributes as variables in the Base SAS language:
However, SCL variables do not have labels.
SCL provides three categories of variables:
are linked to a control (widget) or field in a window. They pass values between an SCL program and the associated window.
are defined in an SCL program. They hold temporary values that users do not need to see.
are provided by SCL. They hold information about the status of an application.
Window Variables |
Most SCL programs are associated with a window for interacting with users. An SCL program for a window has variables that are associated with the controls and fields in the window. These variables are called window variables, and they are the means by which users and SCL programs communicate with each other. You can use these variables in the SCL program without explicitly declaring them.
The name of a window variable is the same as the name that is assigned to the control or field. The SCL program for the window cannot change that name.
A window variable also has a data type, which can be character, numeric, or an object data type. The type is determined by the value of the Type attribute, which is displayed in the Properties window (for a control) or in the Attributes window (for a field). For more information about data types that are used in SAS/AF applications, see the SAS/AF online Help and SAS Guide to Applications Development.
Lengths of window variables are determined as follows:
Numeric and object variables are stored internally as doubles.
Character variables have a maximum length that equals the width of the corresponding field in the application window. For example, if a field occupies 20 columns in the window, then the maximum length of the associated window variable is 20.
Nonwindow Variables |
SCL programs can define and use variables that do not have associated controls or fields in the window. These variables are called nonwindow variables, and they are used to hold values that users do not need to see. SCL programs that do not have an associated window use only nonwindow variables. Nonwindow variables are also referred to as program variables. Because nonwindow variables are used only within an SCL program, they have no informat or format.
The name of a nonwindow variable is determined by the first assignment statement that uses the variable, unless the variable is explicitly defined with a DECLARE or LENGTH statement. Names of nonwindow variables can be up to 32 characters long.
Nonwindow variables are numeric unless they are explicitly declared as a different data type.
Lengths of nonwindow variables are determined as follows:
Character variables have a default length of 200. However, you can use the DECLARE statement to change the length from a minimum length of 1 to a maximum of 32K.
The scope of a variable determines when a value can be assigned to it and when its value is available for use. In general, variables in an SCL program have program scope. That is, their scope is local to the program. They are available for use within the SCL program but not to other parts of SAS software. When the program finishes, the variables no longer exist, so their values are no longer available.
SCL provides a feature for defining variables as local to a DO or SELECT block. To define a variable with this type of scope, use a DECLARE statement inside a DO or SELECT block. Any variable that you declare in this way exists only for the duration of that DO or SELECT block, and its value is available only during that time. For example, the following program uses two variables named SECOND. One variable is numeric by virtue of the first assignment statement. The other is a character variable that is local to the DO block. After the DO block ends, only the numeric SECOND variable is available.
INIT: first=10; second=5; put 'Before the DO block: ' first= second=; do; /* Declare variable THIRD and new */ /* variable SECOND, which is local to */ /* the DO block and is CHAR data type */ declare char(3) second third; second='Jan'; third ='Mar'; /* FIRST is available because */ /* it comes from parent scope. */ put 'Inside the DO block: ' first= second= third=; end; /* THIRD is not available because */ /* it ended when the DO block ended. */ put 'After the DO block: ' first= second= third=; return;
The example produces the following output:
Before the DO block: first=10 second=5 Inside the DO block: first=10 second=Jan third=Mar After the DO block: first=10 second=5 third=.
Although program variables are available only while an SCL program is running, SCL provides features for passing variables to other programs and also for receiving returned values. For more information, see ENTRY and METHOD.
You can also use global macro variables to make variables available outside the SCL program. See Using Macro Variables in SCL Programs for details.
System Variables |
System variables are created automatically when an SCL program compiles. These variables communicate information between an SCL program and an application, and you can use them in programs. System variables can be Character, Numeric, or Object data type variables. The Object data type facilitates compile-time checking for SCL programs that use dot notation to invoke methods and to access attributes for objects. Although the system variables _CFRAME_, _FRAME_, and _SELF_ are designated as object variables in Version 8 and later, applications that were built with earlier releases and that use these variables will continue to work.
Do not declare the _SELF_, _FRAME_, _CFRAME_, _METHOD_, or _EVENT_ system variables inside a CLASS or USECLASS block. SCL automatically sets these values when it is running methods that are defined in CLASS or USECLASS blocks. Redefining any of these system variables can introduce unexpected behavior.
With the exceptions of _EVENT_, _METHOD_, and _VALUE_, you can simply reference a system variable in an SCL program without explicitly declaring it.
reports whether a window variable contains a value or sets a variable value to blank.
contains the identifier of the FRAME entry that is currently executing, when a control is executing a method. Otherwise, it stores the identifier of the FRAME entry that is executing.
contains the value of the first column on the left in an extended table object in a FRAME entry. It is used to control horizontal scrolling.
contains the number of the current row in an extended table.
returns the type of event that occurred on a control. It is useful only during a _select method. At other times, it may not exist as an attribute or it is blank. _EVENT_ can have one of the following values:
" | |
C | |
D | |
P | |
S |
_EVENT_ must be explicitly declared in an SCL program. For example:
declare char(1) _event_;
contains the identifier of the FRAME entry that contains a control, when the object is a FRAME entry control. Otherwise, it contains the identifier of the FRAME entry that is currently executing. You can use this variable to send methods to a FRAME entry from a control's method. For example, a control method can send a _refresh method to the FRAME entry, causing the FRAME entry to refresh its display.
contains the name of the method that is currently executing.
_METHOD_ must be explicitly declared in an SCL program. In the declaration statement, specify the maximum length for the name of a method. For example:
declare char(40) _method_;
assigns text to display on the message line, or contains the text to be displayed on the window's message line the next time the window is refreshed.
contains the identifier of the object that is currently executing a method.
contains a code for the status of program execution. You can check for the value of _STATUS_, and you can also set its value.
contains the value of a control.
When _VALUE_ contains the value of a character control, it must be explicitly declared in an SCL program. In the declaration statement, specify the maximum length for a character window control. For example:
declare char(80) _value_;
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.