Previous Page | Next Page

The Structure of SCL Programs

Using Labeled Sections in SCL Programs

SCL programs execute in phases, such as the initialization phase and the termination phase. During each phase, control of the entry can pass to a different segment of an SCL program. The segments of the program are identified by labels; that is, the SCL program is divided into labeled sections.

Labeled sections are program segments that are designed to be called only within the program in which they are defined. Labeled sections begin with a label and end with a RETURN statement. A label may be one of the reserved labels such as INIT or MAIN; it may correspond to a field name, window-variable name, or object name in your application; or it may simply identify a module that is called repetitively, such as a module that sorts data.

Labeled sections are a good solution when you are working within one SCL program because they can help divide the program into smaller, simpler pieces.

For example, the following SCL program contains an INIT section that is executed before the application window is displayed; two sections that correspond to window variables, NAME and ADDRESS; and a MAIN section that is executed each time the user updates a field in the window.

init:
   ...some SCL statements...
   return;

name:
   ...some SCL statements... 
   return;

address:
   ...some SCL statements...
   return;

main:
   ...some SCL statements...
   return;


Reserved Labels

There are five reserved labels:

FSEINIT

An FSEINIT section, which is valid in FSEDIT and FSBROWSE applications only, contains any statements that are needed to initialize the application. These statements are executed one time only when the user invokes the FSEDIT or FSBROWSE procedure and before the first row is displayed.

INIT

The INIT section is executed before the application window is displayed to the user. Typically, you use the INIT section to initialize variables, to import values through macro variables, to open tables, and to define initial messages to display when the window is opened. In FSEDIT and FSBROWSE applications, as well as Data Table and Data Form controls, the INIT section is executed before each SAS table row is displayed.

MAIN

The MAIN section is executed each time the user modifies a field in the window and presses ENTER.

TERM

The TERM section is executed when the user issues the END command. You might use the TERM section to close tables, to export values of macro variables, and to construct and submit statements for execution. In FSEDIT applications, Data Table controls, and Data Form controls, the TERM section is executed after each SAS table row is displayed, provided that the MAIN section has been executed for the row.

FSETERM

The FSETERM section is valid in FSEDIT applications only. This section executes once after the user issues the END command and terminates the FSEDIT procedure.

In FSVIEW applications, you write individual formulas consisting of one or more lines of SCL code for each computed variable, rather than complete SCL programs. These formulas are stored in FORMULA entries. The FSVIEW procedure automatically adds a label before the formula and a RETURN statement after the formula. The label is the same as the name of the variable whose value you are calculating.

An SCL program for FSEDIT or FSBROWSE applications must contain at least one of the following reserved labels: INIT, MAIN, or TERM. If a program does not include at least one of these three reserved labels, the procedure never passes control to your SCL program. If a program does not contain all three of these reserved labels, you get one or more warning messages when you compile the program.

The FSEINIT and FSETERM labels are optional. The compiler does not issue any warnings if these labels are not present.

Neither SCL programs for FRAME entries nor programs in SCL entries that contain method block definitions require any reserved sections.

For more information about the FSVIEW, FSEDIT, and FSBROWSE procedures, see SAS/FSP Procedures Guide. For more information about FRAME applications, see SAS Guide to Applications Development.


Window Variable Sections

SCL provides a special type of labeled section, called a window variable section, that automatically executes when a user takes an action in a particular control or field. For example, window variable sections might be used to verify values that users enter in controls or fields. An SCL program can include labeled sections for any number of window variables.

The sequence for executing window variable sections is determined by the physical position of the window element. Window variable sections execute sequentially for each window element, from left to right and from top to bottom. A window variable section must be labeled with the name of the associated window variable. For more information about window variables, see SAS Guide to Applications Development.


Correcting Errors in Window Variables

To correct an error in a window variable, you can allow users to correct the error in the window, or you can include a CONTROL ERROR statement along with statements in the window variable section that make a correction, as shown in the following example:

INIT:
    control error;
return;

Name:
   if error(Name) then do;
      erroroff Name;
      Name=default-value-assigned-elsewhere;
      _msg_=
          'Value was invalid and has been reset.';
   end;
return;

Using a window variable section in this manner reduces overhead because the program's MAIN section executes only after the window variable sections for all modified window variables have executed correctly.

If a program also uses CONTROL ERROR, CONTROL ALWAYS, or CONTROL ALLCMDS, then the MAIN section executes after the window variable sections even if an error has been introduced. For more information about the CONTROL statement, see CONTROL.

Previous Page | Next Page | Top of Page