Previous Page | Next Page

SCL Fundamentals

SCL Variables

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:

window variables

are linked to a control (widget) or field in a window. They pass values between an SCL program and the associated window.

nonwindow variables

are defined in an SCL program. They hold temporary values that users do not need to see.

system variables

are provided by SCL. They hold information about the status of an application.

As in the Base SAS language, you can group variables into arrays to make it easier to apply the same process to all the variables in a group. Arrays in SCL are described in SCL Arrays.

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.


Name

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.


Data Type

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.


Length

Lengths of window variables are determined as follows:

SCL programs can use methods to alter the lengths of window variables for some FRAME entry controls. Otherwise, you cannot alter the length of a window variable in an SCL program. Specifying a length for a window variable in a DECLARE or LENGTH statement produces an error message when you compile the program.

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.


Name

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.


Data Type

Nonwindow variables are numeric unless they are explicitly declared as a different data type.


Length

Lengths of nonwindow variables are determined as follows:

You can use the DECLARE or LENGTH statement to specify a different maximum length for nonwindow character variables. This can significantly reduce memory requirements if your program uses many nonwindow variables.

Scope

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.

_BLANK_

reports whether a window variable contains a value or sets a variable value to blank.

Type: Character

_CFRAME_

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.

Type: Object

_CURCOL_

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.

Type: Numeric

_CURROW_

contains the number of the current row in an extended table.

Type: Numeric

_ERROR_

contains a code for the application's error status.

Type: Numeric

_EVENT_

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:

"

modification or selection

C

command

D

double click

P

pop-up menu request

S

selection or single click.

_EVENT_ must be explicitly declared in an SCL program. For example:

declare char(1) _event_;

Type: Character.

_FRAME_

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.

Type: Object

_METHOD_

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_;

Type: Character.

_MSG_

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.

Type: Character

_SELF_

contains the identifier of the object that is currently executing a method.

Type: Object

_STATUS_

contains a code for the status of program execution. You can check for the value of _STATUS_, and you can also set its value.

Type: Character

_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_;

Type: Character or Numeric.

Previous Page | Next Page | Top of Page