Customizing a Procedure With Variables

In this section:

Reference:

You can customize a procedure and control its execution with variables. This is done dynamically by supplying a value of a variable at run time. You can supply a value of a variable in the following ways:

Dialogue Manager variables cannot be used to customize commands in a WebFOCUS Report StyleSheet.

For information on the types of variables and how to use them, see Creating and Working With Local and Global Variables.


Top of page

x
Reference: Rules for Supplying Variable Values

The following rules apply to values for variables:



Example: Customizing a Procedure With Variable Values

This example illustrates the use of the -DEFAULT and -SET commands to supply values for variables. The end user supplies the value B10 for &CODE1, B20 for &CODE2, and SMITH for &REGIONMGR as prompted by an HTML form.

Note: In this example, the output was formatted to eliminate page numbering and grids. For information on formatting your output, see the Creating Reports With WebFOCUS Language manual.

The numbers to the left of the example apply to the notes that follow:

1. -DEFAULT &VERB=SUM
2. -SET &CITY=IF &CODE1 GT 'B09' THEN 'STAMFORD' ELSE 'UNIONDALE';
3. -TYPE REGIONAL MANAGER FOR &CITY
    SET PAGE=OFF
4.     TABLE FILE SALES
       HEADING CENTER
       "MONTHLY REPORT FOR &CITY"
       "PRODUCT CODES FROM &CODE1 TO &CODE2"
       " "
       &VERB UNIT_SOLD AND RETURNS AND COMPUTE
       RATIO/D5.1 = 100 * (RETURNS/UNIT_SOLD);
       BY PROD_CODE
       IF PROD_CODE IS-FROM &CODE1 TO &CODE2
       FOOTING CENTER
5.     "REGION MANAGER: &REGIONMGR"
       "CALCULATED AS OF &DATE"
       ON TABLE SET STYLE *
       TYPE=REPORT, GRID=OFF,$
       END
6. -RUN

The procedure executes as follows:

  1. The -DEFAULT command sets the value of &VERB to SUM.
  2. The -SET command supplies the value for &CITY depending on the value the end user entered in the form for &CODE1. Because the end user entered B10 as the value for &CODE1, &CITY becomes STAMFORD.
  3. When the end user runs the report, WebFOCUS writes a message that incorporates the value for &CITY:
    REGIONAL MANAGER FOR STAMFORD

    The output from -TYPE is not displayed on the HTML page. Instead, it is written to the HTML source file. To display the message, the end user must view the source file of the document.

  4. The stack contains the following lines:
    TABLE FILE SALES
    HEADING CENTER
    "MONTHLY REPORT FOR STAMFORD"
    "PRODUCT CODES FROM B10 TO B20"
    " "
    SUM UNIT_SOLD AND RETURNS AND COMPUTE
    RATIO/D5.1 = 100 * (RETURNS/UNIT_SOLD);
    BY PROD_CODE
    IF PROD_CODE IS-FROM B10 TO B20
    FOOTING CENTER
    "REGION MANAGER: SMITH"
    "CALCULATED AS OF 07/08/93"
    END
  5. The end user supplied the value for &REGIONMGR on the form. WebFOCUS supplies the current date at run time.
  6. The -RUN command causes execution of all commands in the stack. The output from the report request is as follows:
    MONTHLY REPORT FOR STAMFORD
    PRODUCT CODES FROM B10 TO B20
    PROD_CODE
    UNIT_SOLD
    RETURNS
    RATIO
    B10
    103
    13
    12.6
    B12
    69
    4
    5.8
    B17
    49
    4
    8.2
    B20
    40
    1
    2.5
    REGION MANAGER: SMITH
    CALCULATED AS OF 07/08/93


x
Supplying a Default Variable Value

How to:

-DEFAULT commands set default values for local or global variables. Supplying default values to variables in a stored procedure helps ensure that it runs correctly.

Note that -DEFAULTS is a synonym for -DEFAULT.

You can issue multiple -DEFAULT commands for a variable. If the variable is global, these -DEFAULT commands can be issued in separate FOCEXECs. At any point before another method is used to establish a value for the variable, the most recently issued -DEFAULT command will be in effect.

However, as soon as a value for the variable is established using any other method (for example, by issuing a -SET command, retrieving a value input by the user, or reading a value from a file), subsequent -DEFAULT commands issued for that variable are ignored.

If you want to initialize a variable and prevent it from being used for WebFOCUS parameter prompting, you can use the -DEFAULTH command to initialize the variable. Variables initialized with -DEFAULTH, are not returned in the XML describe information used for parameter prompting. Since these variables are not displayed by the parameter prompting features, they are hidden from the user.



x
Syntax: How to Supply a Default Value
-DEFAULT[S] &[&]name=value , [&[&]name=value] [;]

where:

&name

Is the name of the variable.

value

Is the default value assigned to the variable.

;

Is an optional punctuation character.

Note: -DEFAULTS is a synonym for -DEFAULT.



x
Syntax: How to Supply a Default Value for a Hidden Variable
-DEFAULTH &[&]name=value , [&[&]name=value]

where:

&name

Is the name of the variable. This variable is not returned in the XML describe information used for parameter prompting and is, therefore, hidden from the user.

value

Is the default value assigned to the variable.



Example: Supplying a Default Value

In the following example, -DEFAULT sets a default value for &PLANT:

-DEFAULT &PLANT=BOS
TABLE FILE CENTHR
     .
     .
     .

Top of page

x
Supplying Variable Values in an Expression

How to:

Reference:

You can assign a value to the variable by computing the value in an expression or assigning a literal value to a variable with the -SET command. You can also use the IN FILE phrase to test whether a character value exists in a file and populate a variable with the result. The value of the variable is set to 1 if the test value exists in the file and 0 (zero) if it does not.

If you want to set a variable value to a number, the only supported characters you can use are numeric digits, a leading minus sign, and a period to represent following decimal places. These are the only valid characters that Dialogue Manager supports in a number, regardless of EDIT options or the value of CDN.



x
Syntax: How to Assign a Value in an Expression
-SET &[&]name= {expression|value};
-SET &[&]var3= &var1 IN FILE filename1 [OR &var2 IN FILE filename2 ...];

where:

&name

Is the name of the variable.

expression

Is a valid expression. Expressions can occupy several lines, so you should end the command with a semicolon.

value

Is a literal value, or arithmetic or logical expression assigned to the variable. If the literal value contains commas or embedded blanks, you must enclose the value in single quotation marks. If the value contains a single quote, place two single quotes where you want one to appear.

&[&]var3

Is a variable that is populated with the value 1 if the result of the expression on the right side of the equal sign is true, or with the value 0 if the result is false.

&var1

Is the variable that contains the value to be searched for in filename1.

&var2

Is the variable that contains the value to be searched for in filename2.



x
Reference: Usage Notes for IN FILE


x
Syntax: How to Specify Precision for Dialogue Manager Calculations

The DMPRECISION setting enables Dialogue Manager -SET commands to display and store accurate numeric variable values.

Without this setting, results of numeric calculations are returned as integer numbers, although the calculations themselves employ double-precision arithmetic. To return a number with decimal precision without this setting, you have to enter the calculation as input into function FTOA, where you can specify the number of decimal places returned.

The SET DMPRECISION command gives users the option of either accepting the default truncation of the decimal portion of output from arithmetic calculations, or specifying up to nine decimal places for rounding.

SET DMPRECISION = {OFF|n}

where:

OFF

Specifies truncation without rounding after the decimal point. OFF is the default value.

n

Is a positive number from 0-9, indicating the point of rounding. Note that n=0 results in a rounded integer value.

Note:



Example: Using SET DMPRECISION

The following table below shows the result of dividing 20 by 3 with varying DMPRECISION (DMP) settings:

SET DMPRECISION =

Result

OFF

6

0

7

1

6.7

2

6.67

9

6.666666667



Example: Setting a Variable Value in an Expression

In the following example, -SET assigns the value 14Z or 14B to the variable &STORECODE, as determined by the logical IF expression. The value of &CODE is supplied by the end user.

-SET &STORECODE = IF &CODE GT C2 THEN '14Z' ELSE '14B';
   TABLE FILE SALES
   SUM UNIT_SOLD AND RETURNS
   BY PROD_CODE
   IF PROD_CODE GE &CODE
   BY STORE_CODE
   IF STORE_CODE IS &STORECODE
   END


Example: Testing Whether a Variable Value Is in a File

The following FOCEXEC creates an alphanumeric HOLD file called COUNTRY1 with the names of countries from the CAR file. It then sets the variable &C equal to FRANCE. The IN FILE phrase returns the value 1 to &IN1 if FRANCE is in the HOLD file and 0 if it is not:

TABLE FILE CAR                                   
PRINT COUNTRY                                    
ON TABLE HOLD AS COUNTRY1 FORMAT ALPHA           
END                                              
-RUN                                             
-SET &C = 'FRANCE';                              
-SET &IN1 = &C IN FILE COUNTRY1;                
-TYPE THE VALUE IS &IN1

The output shows that FRANCE is in the file COUNTRY1:

THE VALUE IS 1 

Top of page

x
Supplying Variable Values From Another Procedure

How to:

Reference:

You can supply values for variables in an EXEC command used in a procedure to call another procedure. In Developer Studio, this can also be done with the Execute component. See Calling Another Procedure With EXEC for more information on the use of this technique to control application flow.

Values are assigned using a name and value pair, and multiple pairs must be separated by commas. If the list of pairs exceeds the maximum width of the line, insert a comma as the last character on the line and continue the list on the following line. You do not have to enter the pairs in the order in which they are encountered in the procedure.

With EXEC you can supply values for some, but not all, variables used in the procedure. In that case, values not provided in the EXEC command must be supplied using another Dialogue Manager command. For an example, see Supplying Values With Another Procedure.

If the variable is positional (that is, if it is a numbered variable), you do not need to specify the variable name in the EXEC command. WebFOCUS matches the EXEC values to the positional variables as they are encountered in the procedure. Therefore, it is critical to enter the appropriate value for each variable in order. For an example on supplying positional variable values, see Using Positional Variables.



x
Reference: Rules for Using Named and Positional Variables With EXEC

You can mix named and positional variables freely in the EXEC command by following these rules:

The following command is valid for named variables and positional variables:

EX HRINFO SALARY=72000, 5, BOS, STATUS=EMPLOYED


x
Syntax: How to Supply a Variable Value With Another Procedure
EX[EC] procedure name=value

where:

procedure

Is the name of the procedure that will contain the name/value values.

name

Is the variable name.

value

Is the value you are giving to the variable.

Note: When EXEC is used in Managed Reporting, it is important to note that there is a difference between EX and EXEC. EX statements coded in a procedure are processed by the WebFOCUS Client, which looks for the procedure in the Managed Reporting repository. Procedures that are referenced with an EXEC statement are not processed by the WebFOCUS Client, they are only passed to the WebFOCUS Reporting Server for processing, and these procedures are not looked for in the Managed Reporting repository.



Example: Supplying Values With Another Procedure

Consider the following procedure named SLRPT:

TABLE FILE SALES
HEADING CENTER
"MONTHLY REPORT FOR &CITY"
SUM UNIT_SOLD AND RETURNS AND COMPUTE
RATIO/D5.2 = 100 * (RETURNS/UNIT_SOLD);
BY PROD_CODE
IF PROD_CODE IS-FROM &CODE1 TO &CODE2
BY CITY
IF CITY EQ &CITY
END

You can call this procedure from another procedure and supply values for the variables as parameters using the EX command as follows:

EX SLRPT CITY=STAMFORD, CODE1=B10, CODE2=B20


Example: Using Positional Variables

Consider the following example:

TABLE FILE SALES
HEADING CENTER
"MONTHLY REPORT FOR &1"
SUM UNIT_SOLD AND RETURNS AND COMPUTE
RATIO/D5.2 = 100 * (RETURNS/UNIT_SOLD);
BY PROD_CODE
IF PROD_CODE IS-FROM &2 TO &3
BY CITY
IF CITY EQ &1
END

The EX command that calls the procedure is as follows:

EX SLRPT STAMFORD, B10, B20

This command will substitute STAMFORD for the first positional variable, B10 for the second, and B20 for the third.


Top of page

x
Reading Variable Values From and Writing Variable Values to an External File

In this section:

How to:

Reference:

You can read variable values from an external file, or write variable values to an external file with the -READ and -WRITE commands.

The external file can be a fixed-format file (in which the data is in fixed columns) or a free-format file (in which the data is comma delimited).

When using a -READ or -WRITE command, the external file must be included in a FILEDEF command in your procedure. A -RUN command must then separate the FILEDEF command and the -READ or -WRITE command.

You can also read a file using the -READFILE command. The -READFILE command reads a file by first reading its Master File and creating Dialogue Manager amper variables based on the ACTUAL formats for each field in the Master File. It then reads the file and, if necessary, converts the fields from numeric values to alphanumeric strings before returning them to the created variables. Display options in the USAGE formats are not propagated to the variables. The names of the amper variables are the field names prefixed with an ampersand (&).



x
Syntax: How to Retrieve a Variable Value From an External File
-READ filename[,] [NOCLOSE] &name[.format.][,][&name][.format.]

where:

filename[,]

Is the name of the external file, which must be defined to the operating system. A space after filename denotes a fixed-format file, while a comma denotes a free-format file.

  • On UNIX and Windows platforms, a FILEDEF for the external file is required.
  • On z/OS, the external file must be allocated in the JCL or dynamically allocated by WebFOCUS with the ALLOCATE command.
NOCLOSE

Keeps the external file open until the -READ operation is complete. Files kept open with NOCLOSE can be closed using the command -CLOSE filename or a subsequent -WRITE command.

&name[,]

Is the variable name. For free-format files, you may separate the variable names with commas. If the list of variables is longer than one line, end the first line with a comma and begin the next line with a dash followed by a blank. For fixed-format files, including comma-delimited files, begin the next line with a dash, a blank, and a comma.

Free-format

-READ EXTFILE, &CITY, &CODE1,- &CODE2

Fixed-format

-READ EXTFILE &CITY.A8. &CODE1.A3.,- ,&CODE2.A3.
.format.

Is the format of the variable. For a free-format file, specifying this value is optional. For a fixed-format file, format is the length or the type and the length. The type is either A (alphanumeric), which is the default, or I (numeric). The format value must be delimited by periods. The format is ignored for comma-delimited files.

Note: Instead of using .format., you can specify the length of a variable using -SET and enclosing the corresponding number of blanks in single quotes. For example:

-SET &CITY='        ';
-SET &CODE1='   '; 
-SET &CODE2='   ';


x
Syntax: How to Write a Variable Value to an External File
-WRITE filename [NOCLOSE] text

where:

filename

Is the name of the file being written to or read from. On UNIX and Windows platforms, filename must specify the absolute path and file name for the called procedure.

NOCLOSE

Keeps the external file open until the -WRITE operation is complete. A file kept open with NOCLOSE can be closed using the command -CLOSE filename.

text

Is any combination of variables and text.



Example: Reading a Value From an External File

Assume that EXTFILE is a fixed-format file containing the following data:

STAMFORDB10B20

To detect the end of a file, the following code tests the system variable &IORETURN. When no records remain to be read, a value equal to zero will not be found.

-READ EXTFILE &CITY.A8. &CODE1.A3. &CODE2.A3.
-IF &IORETURN NE 0 GOTO RESUME;
   TABLE FILE SALES
   SUM UNIT_SOLD
   BY CITY
   IF CITY IS &CITY
   BY PROD_CODE
   IF PROD_CODE IS-FROM &CODE1 TO &CODE2
    END
-RESUME
 .
 .
 .


Example: Reading From and Writing to an External File

The following example reads from and writes to text files and uses FILEDEF commands in a procedure. The numbers on the left apply to the notes that follow. In the example, the user supplies a value for &CITY in an HTML form:

1. -TOP
2.    FILEDEF PASS DISK D:PASS.DAT
   -RUN
3. -WRITE PASS &CITY
      TABLE FILE SALES
      HEADING CENTER
      "LOWEST MONTHLY SALES FOR &CITY"
      " "
      PRINT DATE PROD_CODE
      BY LOWEST 1 UNIT_SOLD
      BY STORE_CODE
      BY CITY
      WHERE CITY EQ '&CITY'
      FOOTING CENTER
      "CALCULATED AS OF &DATE"
      ON TABLE SAVE AS INFO
      END
4. -RUN
5.  FILEDEF LOG DISK D:LOG.DAT
   -RUN
      MODIFY FILE SALES
      COMPUTE
      TODAY/I6=&YMD;
      CITY='&CITY';
      FIXFORM X5 STORE_CODE/A3 X15 DATE/A4 PROD_CODE/A3
      MATCH STORE_CODE DATE PROD_CODE
      ON MATCH TYPE ON LOG
      "<STORE_CODE><DATE><PROD_CODE><TODAY>"
      ON MATCH DELETE
      ON NOMATCH REJECT
      DATA ON INFO
      END
6. -RUN
      EX SLRPT3
7. -RUN
8. -GOTO TOP
9. -QUIT

The procedure SLRPT3, which is invoked from the calling procedure, contains the following lines:

10. -READ PASS &CITY.A8.
      TABLE FILE SALES
      HEADING CENTER
      "MONTHLY REPORT FOR &CITY"
      "LOWEST SALES DELETED"
      " "
      PRINT PROD_CODE UNIT_SOLD RETURNS DAMAGED
      BY STORE_CODE
      BY CITY
      WHERE CITY EQ '&CITY'
      FOOTING CENTER
      "CALCULATED AS OF &DATE"
      END
11. -RUN

The procedure processes as follows:

  1. -TOP marks the beginning of the procedure.
  2. The FILEDEF command defines a file named PASS.
  3. The -WRITE command writes the value of &CITY to the text file named PASS. In this case, assume that the value written is STAMFORD.
  4. The -RUN command executes the stacked report request. In this case, a text file named INFO is created with the SAVE command. This is a sequential file, containing the result of the report request.
  5. The FILEDEF command defines a log file for the subsequent MODIFY request.
  6. The -RUN statement executes the stacked MODIFY request. The data comes directly from the INFO file created in the prior report request and is entered using the FIXFORM statement. The product with the lowest value in UNIT_SOLD is deleted from the data source and logged to a log file.
  7. The next -RUN command executes the procedure called SLRPT3.
  8. The -GOTO TOP statement passes control to the start of the procedure.
  9. -QUIT ends processing.
  10. The -READ command reads the value for &CITY from the text file PASS. In this case, the value passed is STAMFORD.
  11. The -RUN command executes the report request and control is returned to the calling procedure.


x
Syntax: How to Read Master File Fields Into Dialogue Manager Variables
-READFILE [app/]mastername

where:

app

Is the application directory in which the file resides.

mastername

Is the name of the Master File to be read.



x
Reference: Usage Notes for -READFILE


Example: Reading Fields From a Data Source Into Dialogue Manager Variables Using -READFILE

The following request creates a binary HOLD file, then uses -READFILE to read the first record from the HOLD file and type the values that were retrieved into Dialogue Manager variables. Note that the names of the variables are the field names prefixed with an ampersand:

TABLE FILE EMPLOYEE                           
PRINT LAST_NAME FIRST_NAME DEPARTMENT CURR_SAL
BY EMP_ID                                     
ON TABLE HOLD AS READF1 FORMAT BINARY         
END                                           
-RUN                                          
-READFILE READF1                              
-TYPE LAST_NAME  IS &LAST_NAME                
-TYPE FIRST_NAME IS &FIRST_NAME               
-TYPE DEPARTMENT IS &DEPARTMENT               
-TYPE CURR_SAL   IS &CURR_SAL                 
-TYPE EMP_ID     IS &EMP_ID

The output is:

>   NUMBER OF RECORDS IN TABLE=       12  LINES=     12 
                                                        
 HOLDING BINARY FILE...                                             
LAST_NAME  IS STEVENS                                   
FIRST_NAME IS ALFRED                                    
DEPARTMENT IS PRODUCTION                                
CURR_SAL   IS     11000.00                              
EMP_ID     IS 071382660



x
Closing an External File

The -CLOSE command closes an external file opened with the -READ or -WRITE command with the NOCLOSE option. The NOCLOSE option keeps a file open until the -READ or -WRITE operation is complete.



x
Syntax: How to Close an External File
-CLOSE filename

where:

filename

Is a symbolic name associated with a physical file known to the operating system.


Top of page

x
Supplying Variable Values From Report Painter in Developer Studio

In Developer Studio, in place of Dialogue Manager, the Report Painter provides an intuitive means of embedding variables into your report.

Dialogue Manager commands within TABLE commands will be eliminated. However, Dialogue Manager commands used before or after TABLE and END commands will be retained.

You can also use HTML Composer to create forms in which users can supply variable values for your procedure. For details on HTML Composer, see the Designing a User Interface for a Web Application With HTML Composer manual.



Example: Supplying Variable Values From the Report Painter

The following example illustrates how to create procedures containing values from the Report Painter:

  1. Create a new procedure.
  2. Click and hold a component connector (yellow diamond), then click the Report button on the Component Connector toolbox.

    The File Description List For Report window displays.

  3. Choose EMPLOYEE from the list, and click Paint.

    The Report Painter opens.

  4. Double-click PCT_INC, then SALARY in the Employee window.

    The fields display in the Report Painter.

  5. Click By from the toolbar.
  6. Double-click DEPARTMENT in the list of fields in the Employee window.
  7. Click the Select menu, then select Where/If.

    The Where/If window displays.

  8. Click Assist.

    The Expression Builder displays.

  9. Select SALARY in the Name field, Is LESS THAN in the Relations field, and Parameter (& Variable) in the Compare Type section.

    The Parameter field displays in the Expression Builder.

  10. Enter SALPROMPT, and click OK.

    The Expressions Builder displays with SALARY LT &SALPROMPT in the Expressions field.

  11. Click OK.

    The Where/If window is active.

  12. Click OK.
  13. Click the Run icon to run your request.

    A pop-up window displays with a field for the value of SALPROMPT.

  14. Enter 100000, and click OK.

    The report output displays in the browser.


Top of page

x
Supplying Dates as Variable Values

In this section:

You can use variables to supply dates to Dialogue Manager. A date supplied to Dialogue Manager cannot be more than 20 characters long, including spaces. Dialogue Manager variables only accept full-format dates (that is, MDY or MDYY, in any order).



Example: Setting the Difference Between Two Dates

In the following example, the variable &DELAY is set to the difference in days between &LATER and &NOW and the result is returned to your browser.

-SET &NOW = 'JUN 30 2002';
-SET &LATER = '2002 25 AUG';
-SET &DELAY = &LATER - &NOW;
-TYPE &DELAY


x
Using Variables With Cross-Century Dates

If you are working with cross-century dates that do not include a four-digit year, variables are available which allow you to identify the century. For details, see the legacy repository.


Top of page

x
Performing a Calculation on a Variable

How to:

You can use -SET to define a value for a substituted variable based on the results of a logical or arithmetic expression or a combination.



x
Syntax: How to Perform a Calculation on a Variable
-SET &name = expression;

where:

&name

Is a user-supplied variable that has its value assigned with the expression.

expression

Is an expression following the rules outlined in the Creating Reports With WebFOCUS Language manual, but with limitations as defined in this topic. The semicolon (;) after the expression is required to terminate the -SET command.



Example: Altering a Variable Value

The following example demonstrates the use of -SET to alter variable values based on tests.

-SET &REL = IF &CHOICE EQ A THEN 'GT' ELSE 'LT'; 
   TABLE FILE SALES
   PRINT PROD_CODE UNIT_SOLD RETAIL_PRICE
   BY STORE_CODE BY DATE
   IF RETAIL_PRICE &REL 1.00
   END

Assuming the user enters the letter A, -SET assigns the string value GT to &REL. Then, the value GT is passed to the &REL variable in the procedure, so that the expanded FOCUS command at execution time is:

IF RETAIL_PRICE GT 1.00

Top of page

x
Changing a Variable Value With the DECODE Function

You can use the DECODE function to change a variable to an associated value.



Example: Changing the Value of a Variable

In this example, the variable refers to a movie rating:

&SELECT. ENTER A,B,C,D,E. 
-SET &RATING = DECODE &SELECT (A G B PG13 C R D NR E PG);
TABLE FILE MOVIES
PRINT TITLE BY RATING
IF RATING EQ &RATING
END

For more information on DECODE, see the Using Functions manual.


Top of page

x
Screening a Variable Value

How to:

To ensure that a supplied value is valid and being used properly in a procedure, you can test it for presence, type, and length. For example, you would not want to perform a numerical computation on a variable for which alphanumeric data has been supplied.

You screen a value by adding a suffix to the variable value:



x
Syntax: How to Screen a Variable Value
-IF &name{suffix} expression GOTO label...;

where:

&name

Is a user-supplied variable.

suffix

Is one of the following:

.EXIST tests for the presence of a value. If a value is not present, a zero (0) is passed to the expression. Otherwise, a non-zero value is passed.

.LENGTH tests for the length of a value. If a value is not present, a zero (0) is passed to the expression. Otherwise, the number of characters in the value is passed.

.TYPE tests for the type of a value. The letter N (numeric) is passed to the expression if the value can be interpreted as a number up to 109-1 and stored in four bytes as a floating point format. In Dialogue Manager, the result of an arithmetic operation with numeric fields is truncated to an integer after the whole result of an expression is calculated. If the value could not be interpreted as numeric, the letter A (alphanumeric) is passed to the expression.

.EVAL replaces a variable with its value.

expression

Is a valid expression that uses &name with the specified suffix as an variable.

GOTO label

Specifies a label to branch to.



Example: Testing for the Presence of a Variable

If a value is not supplied in the following example, &OPTION.EXIST is equal to zero and control is passed to the label -CANTRUN. The -HTMLFORM displays a message that the procedure cannot run. If a value is supplied, control passes to the label -PRODSALES.

-IF &OPTION.EXIST GOTO HRINFO ELSE GOTO CANTRUN; 
     .
     .
     .
-HRINFO
   TABLE FILE CENTHR
     .
     .
     .
   END
-EXIT
-CANTRUN 
-HTMLFORM BEGIN
<HTML>
<BODY>
TOTAL REPORT CAN'T BE RUN WITHOUT AN OPTION.
</BODY>
</HTML>
-HTMLFORM END
-EXIT


Example: Testing for the Length of a Variable With an HTML Format Message

If the length of the value supplied for &OPTION is more than one character, control passes to the label -FORMAT. Control then continues to the command -HTMLFORM, which displays a message, informing the user that only a single character can be entered.

-IF &OPTION.LENGTH GT 1 GOTO FORMAT ELSE
-GOTO PRODSALES;
     .
     .
     .
-PRODSALES
   TABLE FILE SALES
     .
     .
     .
   END
-EXIT
-FORMAT
-HTMLFORM BEGIN
<HTML>
<BODY>
ONLY A SINGLE CHARACTER IS ALLOWED.
</BODY>
</HTML>
-HTMLFORM END


Example: Testing for the Length of a Variable

If the length of &OPTION is greater than one character, control passes to the label -FORMAT. The -HTMLFORM command then displays a message informing the user that only a single character can be entered.

-TOP
-IF &OPTION.LENGTH GT 1 GOTO FORMAT ELSE
-GOTO PRODSALES;
     .
     .
     .
-PRODSALES
   TABLE FILE SALES
     .
     .
     .
   END
-EXIT
-FORMAT
-HTMLFORM BEGIN
<HTML>
<BODY>
PLEASE ENTER ONLY ONE CHARACTER.
</BODY>
</HTML>
-HTMLFORM 
END


Example: Testing for the Type of a Value

If &OPTION is not alphanumeric, control passes to the label -NOALPHA. -HTMLFORM displays an HTML page that informs the user that only alphanumeric characters are allowed.

-IF &OPTION.TYPE NE A GOTO NOALPHA ELSE
- GOTO HRINFO;
      .
      .
      .
-HRINFO
   TABLE FILE CENTHR
      .
      .
      .
   END
-EXIT
-NOALPHA
-HTMLFORM BEGIN
<HTML>
<BODY>
ENTER A LETTER ONLY.
</BODY>
</HTML>
-HTMLFORM

Top of page

x
Evaluating a Variable Immediately

How to:

The .EVAL operator enables you to evaluate the value of a variable immediately, making it possible to change a procedure dynamically. The .EVAL operator is particularly useful in modifying code at run time.



x
Syntax: How to Evaluate a Variable Immediately
[&]&variable.EVAL

where:

variable

Is a local or global variable.

When the command procedure is executed, the expression is replaced with the value of the specified variable before any other action is performed. Without the .EVAL operator, a variable cannot be used in place of some commands.



Example: Using .EVAL to Allow WebFOCUS to Interpret a Variable

The code

-SET &A='-TYPE';
&A HELLO

produces an error message which shows that WebFOCUS does not recognize the value of &A:

Appending the .EVAL operator to the &A variable makes it possible for WebFOCUS to interpret the variable correctly. Adding the .EVAL operator as follows

-SET &A='-TYPE';
&A.EVAL HELLO

produces the following output:



Example: Evaluating a Variable Immediately

The following example illustrates how to use the .EVAL operator in a record selection expression. The numbers to the left apply to the notes that follow the procedure:

1. -SET &R='IF SALARY GT 60000';
2. -IF &Y EQ 'YES' THEN GOTO START;
3. -SET &R = '-*';
   -START
4.   TABLE FILE CENTHR
     PRINT SALARY 
     BY PLANT BY LNAME
5.   &R.EVAL
     END

The procedure executes as follows:

  1. The procedure sets the value of &R to 'IF SALARY GT 60000'.
  2. If &Y is YES, the procedure branches to the START label, bypassing the second -SET command.
  3. If &Y is NO, the procedure continues to the second -SET command, which sets &R to '-*', which is a comment.

    The report request is stacked.

  4. The procedure evaluates the value of &R. If the end user wanted a record selection test, the value of &R is 'IF SALARY GT 60000' and this line is stacked.
  5. If the end user did not want a record selection test, the value of &R is '-*' and this line is ignored.

Top of page

x
Counting With an Indexed Variable

How to:

You can append the value of one variable to the value of another variable, creating an indexed variable. This feature applies to both local and global variables.

If the indexed value is numeric, the effect is similar to that of an array in traditional computer programming languages. For example, if the value of index &K varies from 1 to 10, the variable &AMOUNT.&K refers to one of ten variables, from &AMOUNT1 to &AMOUNT10.

A numeric index can be used as a counter, and it can be set, incremented, and tested in a procedure.



x
Syntax: How to Create an Indexed Variable
-SET &name.&index[.&index...] = expression;

where:

&name

Is a variable.

.&index

Is a numeric or alphanumeric variable whose value is appended to &name. The period is required.

When more than one index is used, all index values are concatenated and the string appends to the name of the variable.

For example, &V.&I.&J.&K is equivalent to &V1120 when &I=1, &J=12, and &K=0.

expression

Is a valid expression. For information on the kinds of expressions you can write, see the Creating Reports With WebFOCUS Language manual.



Example: Using an Indexed Variable in a Loop

An indexed variable can be used in a loop. The following example creates the equivalent of a DO loop used in traditional programming languages:

-SET &N = 0;
-LOOP
-SET &N = &N+1;
-IF &N GT 12 GOTO OUT;
-SET &MONTH.&N=&N;
-TYPE &MONTH.&N 
-GOTO LOOP
-OUT

In this example, &MONTH is the indexed variable and &N is the index. The value of the index is supplied through the command -SET. The first -SET initializes the index to 0, and the second -SET increments the index each time the procedure goes through the loop.

If the value of an index is not defined prior to reference, a blank value is assumed. As a result, the name and value of the indexed variable will not change.

Indexed variables are included in the system limit of 384 variables.


WebFOCUS