Contents SAS/IntrNet 8.2: Application Dispatcher Previous Next

Display Macro Variables

This application illustrates how values specified in form fields are passed to the Application Dispatcher programs.


The Input Component

This sample uses both the HTML Output Formatter and the HTML Data Set Formatter, two of the HTML Formatting Tools that are provided by SAS, to create an HTML-formatted table. These tools will produce all of the HTML output for this application! You control which tool is used by the value selected in the "Display Options" radio box near the bottom of the form. Below is the HTML source code for this radio box.

   <INPUT NAME="_PROGRAM" TYPE="RADIO" VALUE="sample.webvars.sas" CHECKED>
      Preformatted Text<BR>
   <INPUT NAME="_PROGRAM" TYPE="RADIO" VALUE="sample.webvtab.sas">HTML Table

The form also contains different types of controls that accept input. The name/value pairs for each of these fields are passed to the Broker. To view the HTML code for these controls, select the option from your Web browser that allows you to view the HTML source, or edit the HTML source directly.

There are also combo boxes that allow you to choose the type of service and the debug level.

The HTML code for this application is installed with the Dispatcher package in a default location at http://yourserver/sasweb/IntrNet8/dispatch/webvars.html.


The Program Component

Again, the SAS code to process this form is made easy by using the HTML Formatting Tools. These tools can be used in Dispatcher programs to provide power and flexibility while saving you a lot of programming effort.

Note that the "Display Options" radio box mentioned above controls which Formatting Tool is used to display the macro variables. This is accomplished by running a different program based on the selected radio button. For example, if you chose "Preformatted Text" for the display option, the name/value pair _program=sample.webvars.sas is passed to the Broker. This causes the program webvars.sas to execute. Similarly, selecting "HTML Table" will cause the program webvtab.sas to run. The webvars.sas program uses the Output Formatter to generate the HTML and the program webvtab.sas uses the Data Set Formatter. Both programs use the SQL procedure to extract the macro variables from the dictionary table named MACROS.

Displaying Data Using the Output Formatter

The Output Formatter is invoked by calling the macro %out2htm and supplying it with a set of arguments. To begin capturing SAS procedure output, specify the argument capture=on. When all of the SAS procedure output that you want has been generated, run %out2htm again, this time specifying the capture=off argument.

Here is the source code illustrating this technique, which was extracted from the Dispatcher program.

   %out2htm(capture=on);

   PROC SQL code goes here

   %out2htm(capture=off,
      htmlfref=_webout,
      openmode=replace,
      runmode=s,
      brtitle=Macro Variables,
      bgtype=color,
      bg=#ffeeee, 
      dcolor=black,
      septype=none);

The argument RUNMODE=S instructs the Output Formatter to print the required HTTP header before creating any output. You can use a DATA step to do this, but the RUNMODE argument is more convenient.

Another requirement of all Dispatcher programs is to make sure that the output is directed to the fileref _WEBOUT. The Formatting Tools accept the argument HTMLREF=. Supplying a value of _WEBOUT for this argument directs the Formatter output to the Web browser.

The complete code for this Dispatcher program is installed in the Application Server sample library in a file named WEBVARS.SAS.

Displaying Data Using the Data Set Formatter

The Data Set Formatter is invoked by calling the macro %ds2htm and supplying it with a set of arguments. Here is the source code illustrating this technique, which was extracted from the Dispatcher program.

   PROC SQL code goes here

   %ds2htm(htmlfref=_webout,
      openmode=replace,
      runmode=S,
      data=mvars,
      var=name value,
      caption=Macro Variables,
      septype=none,
      bgtype=color,
      bg=white,
      twidth=0,
      vhalign=left,
      csize=+2,
      center=Y,
      ccolor=red,
      brtitle=Macro Variables,
      clbgcolr=gray);

The argument RUNMODE=S instructs the Data Set Formatter to print the required HTTP header before creating any output. You can use a DATA step to do this, but the RUNMODE argument is more convenient.

Another requirement of all Dispatcher programs is to make sure that the output is directed to the fileref _WEBOUT. The Formatting Tools accept the argument HTMLREF=. Supplying a value of _WEBOUT for this argument directs the Formatter output to the Web browser.

The complete code for this Dispatcher program is installed in the Application Server sample library in a file named WEBVTAB.SAS.

Analysis and Discussion

When you submit the program for execution, the browser passes the name/value pairs for all controls to the Broker as NAME=VALUE. Note that some controls have the same name for multiple fields or items. For example, there are three input fields named TEXT:

   <INPUT TYPE="text" NAME="text" VALUE="First">
   <INPUT TYPE="text" NAME="text" VALUE="Second">
   <INPUT TYPE="text" NAME="text" VALUE="Third">

The Broker creates a unique variable name for each of the fields by adding an ordinal number to the field name because multiple macro variables cannot have the same name. In the case above, the following macro variables will be generated:

NameValue
TEXTFirst
TEXT03
TEXT1First
TEXT2Second
TEXT3Third

The macro variable TEXT contains the full text string of the first control named TEXT. The variable TEXT0 indicates how many fields named TEXT were selected or modified. In this case, all three fields contain data, so TEXT0 has a value of 3. The variables TEXT1, TEXT2, and TEXT3 contain the value of the text string of the three text fields, in the order they are created in the HTML document.

For further information about how the Broker handles multiple name/value pairs, refer to Multiple Value Pairs.


Contents SAS/IntrNet 8.2: Application Dispatcher Previous Next