Constructing a Frame SCL Program

Overview

A typical SCL program for a frame consists of
  • labeled sections
  • statements
  • routines and functions
  • SCL variables
This section describes how you can combine these elements to create the programs that control SAS/AF frames.

SCL Labeled Sections

A section in SCL begins with a label and ends with a RETURN statement. SCL programs for FRAME entries use reserved sections to process program initialization, main processing, and termination.
INIT:
  /* ...statements to initialize the application... */
return;

MAIN:
  /* ...statements to process user input... */
return;

TERM:
  /* ...statements to terminate the application... */
return;
In addition, you can add sections labeled with object names for each component that you add to the frame. The labeled section for a component executes when an action is performed on the component, such as selecting the component or changing its value. For example, if you have a push button named okButton on your frame, you could have the following labeled section in your SCL:
okButton:
      dcl list message={'Are you sure you want to exit?'};
      response=messagebox(message, '!', 'YN', 'Confirm Exit','N',”);
      rc=dellist(message);
return;
The code in the okButton section automatically executes when the push button is selected.
In general,
  • INIT executes once before the frame is displayed to the user.
  • MAIN executes immediately after the corresponding object-label section has executed. If a corresponding object-label section does not exist, then MAIN executes each time a user activates any object on the frame.
  • TERM executes when either your program or the user issues an END command or a CANCEL command.
For a detailed explanation of how labeled sections are processed, see How SCL Programs Execute for FRAME Entries.

SCL Statements

The labeled sections in frame SCL programs consist of one or more executable statements that control program flow. (Declarative statements, such as DECLARE or ARRAY, can occur anywhere in the program and do not have to exist in labeled sections.)
You can also use the following SAS language statements in SCL programs:
  • LENGTH and ARRAY statements
  • assignment statements that use standard arithmetic, comparison, logical, and concatenation operators
  • IF-THEN/ELSE and SELECT statements
  • DO groups and all forms of DO loops
  • LINK and RETURN statements
  • comment indicators, including /* comment */ and * comment;
For details on SCL statements, refer to the SAS Component Language: Reference.

SCL Routines and Functions

SCL provides a rich set of routines and functions that perform some action, such as the DISPLAY routine or the OPENSASFILEDIALOG function. For detailed information about these functions, refer to the SAS Component Language: Reference.
In addition, SCL supports nearly all of the functions of the Base SAS language. For details on the Base SAS functions, see SAS Language Reference: Dictionary.

SCL Variables

Each variable used in an SCL entry represents a specific data type. SCL supports the following data types:
Character
declared with the keyword CHAR
Numeric
declared with the keyword NUM
SCL List
declared with the keyword LIST
Object
declared with the keyword OBJECT or with a specific four-level class name
SCL provides several automatically defined system variables, such as
  • _FRAME_, a generic object that contains the identifier of the current active frame
  • _MSG_, a character variable that enables you to set the text to display in the frame's message area
  • _STATUS_, a character variable that you can query to see whether a user has cancelled or ended from a frame so that your application can either halt execution immediately or resume processing.
See the SAS Component Language: Reference for a complete list of system variables and their data types.
Automatic system variables like _FRAME_ and _STATUS_ are declared internally, so you can use them without having to declare them in your SCL. Objects created on a frame are also declared automatically, and as long as you compile the frame's SCL entry from the frame, the SCL compiler recognizes them.
All other variables must be defined using the DECLARE statement. Consider the following code:
DECLARE  NUM       
 n1 n2,
         NUM         n3[15],
         CHAR        c1,
         CHAR(10)    c2,
         LIST        myList = {};
         OBJECT      obj1 objs[5],
         classname   obj2;
  • The DECLARE keyword begins the variable declaration statement. You can also use the abbreviation DCL.
  • NUM, CHAR, LIST, and OBJECT are reserved keywords that indicate the data type of the variables that follow the keyword.
  • The variable declared as n3[15] defines a 15-item array of numeric values.
  • CHAR(n) is a notation that enables you to define the length of a character variable, where n, a value up to 32767, is its length. By default, character variables are 200 characters long. In the declaration above, c1 is a character variable with a length of 200, and c2 is a character variable with a length of 10.
  • OBJECT indicates that the variable contains an object identifier, which enables the SCL compiler to recognize dot notation for method calls or attribute references. The variable declared as objs[5] is a five-item array of object identifiers.
  • classname indicates that the variable contains the object identifier of a specific class such as sashelp.classes.cataloglist_c.class.

Dot Notation and SCL

SCL provides dot notation for direct access to component properties. Dot notation is intended to save time, improve code readability, and reduce the amount of coding necessary. It also improves the performance of your applications by providing additional compile-time validation. For example, you can use it to check the method's argument type. You can also use it to execute methods and to access component attributes without having to use SEND or NOTIFY routines.
You can use dot notation in any of the following forms:
object.method(<arguments>);
return-value=object.method(<arguments>);
object.attribute=value;
value=object.attribute;
if (object.method(<arguments>)) then ...
if (object.attribute) then ...
where
object
specifies an object or an automatic system variable (such as _CFRAME_, _FRAME_, or _SELF_) whose type is object.
method
specifies the name of the method to execute.
arguments
specifies one or more arguments based on the appropriate method signature.
return value
specifies the value returned by a method (if any).
attribute
specifies an attribute that exists on object.
value
specifies a value assigned to or queried from the attribute.
Dot notation can be used to set or query attributes. For example, suppose object1 is a text entry control:
/*Setting the text color */
   object1.textColor='yellow';

/* Querying the text color.                  */
/* object1's textColor attribute is returned */
/* to the local SCL variable 'color'         */
   color = object1.textColor;
Dot notation also is used to call methods. For example,
object._cursor();
is equivalent to
call send(object, '_cursor');
For compatibility with legacy programs, you can continue to use CALL SEND and CALL NOTIFY to invoke methods.
You can use dot notation to call methods on objects in several ways, provided the method contains the appropriate signature information. For example,
/* With a return variable */
   cost=object1.getPrice(itemnum);

/* Without a return variable */
   object1.getPrice(itemnum, cost);

/* In an IF statement */
   if object1.getPrice(itemnum) > 100 then
do...
Note: Objects that are created on a frame and automatic system variables (such as _FRAME_ ) are automatically declared as objects. You can refer to these objects in dot notation without having to declare them in your SCL programs. To use dot notation with legacy objects that you add to a frame, you must first select “Use object name as ID in SCL” for those objects in the Properties window.
For more information about dot notation, refer to the SAS Component Language: Reference and the SAS/AF online Help.