Controlling the Execution of SCL Programs

Introduction

There are several ways to control application execution in an SCL program for a frame. You can
  • conditionally change the program flow, or branch to other sections of SCL
  • submit SAS and SQL statements (see the SAS Component Language: Reference for details)
  • use the SYSTEM function to issue a host operating system command that performs system-specific data management tasks or invokes an application other than SAS
  • use the CONTROL statement with the ALWAYS option or the ENTER option to process custom commands
You can use conditional SCL statements to alter the flow of a program. For example, to conditionally return control to the window:
object1:
   /* ...SCL statements... */
   if condition
      then return;
   /* ...SCL statements... */
return;
You can use the LINK statement to branch to a common labeled section in the same SCL program. For example:
object1:
   /* ...SCL statements... */
   link computeValue;
   /* ...SCL statements... */
return;

object2:
   /* ...SCL statements... */
   link computeValue;
return;

computeValue:
   /* ...SCL statements... */
return;
The labeled section computeValue may or may not correspond to an object of the same name. Labeled sections are not required for all objects on a frame; likewise, a labeled section can exist with or without an associated frame object. The computeValue section executes each time
  • object1 is activated or modified
  • object2 is activated or modified
  • an object named computeValue is activated or modified (if it exists on the frame)
For additional information on controlling application flow with SCL, refer to the topics on submitting SAS statements and using macro variables in the SAS Component Language: Reference.

Processing Custom Commands in SCL Programs

You can add custom command processing to your frame SCL programs to control program flow. A custom command can be any name that does not correspond to an AF window command or SAS global command and that you implement in the MAIN section of your frame SCL program. A user issues commands by typing on a command line, by pressing a function key with a defined command, or by selecting items on the frame, including menu selections or commands that are associated with visual controls.
To implement a custom command, you must
  • select a unique command name (that is, one that differs from all AF window commands and SAS global commands).
  • add a CONTROL statement to change the default behavior for command processing during SCL program execution. Alternatively, you can set the frame's commandProcessing attribute to Run main.
  • add code to the MAIN section of the frame's SCL program to read the custom command from the command line, process the custom command, and prevent the SAS command processor from evaluating the custom command.
The CONTROL statement controls the execution of labeled sections in an SCL program. Typically, you add this statement to the INIT section of your program.
  • Use CONTROL ALLCMDS to execute the MAIN section when a procedure-specific or custom command is issued, or when a user presses the ENTER key, even if an error flag is in effect for an object on the frame.
  • Use CONTROL ALWAYS to execute the MAIN section when a custom command is issued or when a user presses the ENTER key, even if an error flag is in effect for an object on the frame.
  • Use CONTROL ENTER to execute the MAIN section when a custom command is issued or when a user presses the ENTER key, unless an error flag is in effect for an object on the frame.
You can use the WORD function to return the command for processing, using the syntax
  
command=word(n <,case>);
where command is the word that is currently in the command buffer, n is the position (either 1, 2, or 3) of the word in the command, and case is an optional parameter that converts the word to either uppercase ('U') or lowercase ('L').
You can use the NEXTCMD routine to remove the current command from the command buffer, using the syntax
call nextcmd();
If you do not remove a custom command from the command buffer, SAS issues an error message.
For example, consider a frame that contains a toolbar object on which each button is set to issue a different command. These commands can be a mixture of valid SAS commands or custom commands that you implement in the MAIN section of the frame's SCL program:
dcl char(8) command;
   INIT:
      control always;
      return;
   MAIN:
      command=word(1, 'u');
      select command;
         when ('CUSTOM1')
            /* ...code to process the CUSTOM1 command... */
            call nextcmd();
         when ('CUSTOM2')
            /* ...code to process the CUSTOM2 command... */
            call nextcmd();
         otherwise;
   end;
   return;