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.
The following rules apply to values for variables:
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 ®IONMGR 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 TIBCO 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: ®IONMGR" "CALCULATED AS OF &DATE" ON TABLE SET STYLE * TYPE=REPORT, GRID=OFF,$ END 6. -RUN
The procedure executes as follows:
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.
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
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 |
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.
-DEFAULT[S] &[&]name=value , [&[&]name=value] [;]
where:
Is the name of the variable.
Is the default value assigned to the variable.
Is an optional punctuation character.
Note: -DEFAULTS is a synonym for -DEFAULT.
-DEFAULTH &[&]name=value , [&[&]name=value]
where:
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.
Is the default value assigned to the variable.
In the following example, -DEFAULT sets a default value for &PLANT:
-DEFAULT &PLANT=BOS TABLE FILE CENTHR . . .
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.
-SET &[&]name= {expression|value};
-SET &[&]var3= &var1 IN FILE filename1 [OR &var2 IN FILE filename2 ...];
where:
Is the name of the variable.
Is a valid expression. Expressions can occupy several lines, so you should end the command with a semicolon.
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.
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.
Is the variable that contains the value to be searched for in filename1.
Is the variable that contains the value to be searched for in filename2.
-SET &VAR1 = 'ABC '; -SET &VAR2 = &VAR1 IN FILE FILE1;
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:
Specifies truncation without rounding after the decimal point. OFF is the default value.
Is a positive number from 0-9, indicating the point of rounding. Note that n=0 results in a rounded integer value.
Note:
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 |
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
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
How to: |
Reference: |
You can supply values for variables in an EXEC command used in a procedure to call another procedure. 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.
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.
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
EX[EC] procedure name=value
where:
Is the name of the procedure that will contain the name/value values.
Is the variable name.
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.
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
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.
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 (&).
-READ filename[,] [NOCLOSE] &name[.format.][,][&name][.format.]
where:
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.
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.
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 (- ,) or a dash and a comma (-,).
Free-format
-READ EXTFILE, &CITY, &CODE1,- &CODE2
Fixed-format
-READ EXTFILE &CITY.A8. &CODE1.A3.,- ,&CODE2.A3.
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.
-SET &CITY=' '; -SET &CODE1=' '; -SET &CODE2=' ';
-WRITE filename [NOCLOSE] text
where:
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.
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.
Is any combination of variables and text.
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 . . .
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:
-READFILE [app/]mastername
where:
Is the application directory in which the file resides.
Is the name of the Master File to be read.
(FOC339) DIALOGUE MANAGER -READ FAILED: CHECK FILEDEF OR ALLOCATION FOR: -READFILE filename
(FOC702) THE OPTION SPECIFIED IS NOT AVAILABLE WITH TEXT FIELDS: fieldname
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
How to: |
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.
-CLOSE filename
where:
Is a symbolic name associated with a physical file known to the operating system.
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).
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
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.
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.
-SET &name = expression;
where:
Is a user-supplied variable that has its value assigned with the expression.
Is an expression following the rules outlined in the Creating Reports With TIBCO WebFOCUS® Language manual, but with limitations as defined in this topic. The semicolon (;) after the expression is required to terminate the -SET command.
The following example demonstrates the use of -SET to alter variable values based on tests.
-SET &OPERATOR = 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 &OPERATOR 2.00 END
Assuming the user enters the letter A, -SET assigns the string value GT to &OPERATOR. Then, the value GT is passed to the &OPERATOR variable in the procedure, so that the expanded FOCUS command at execution time is:
IF RETAIL_PRICE GT 2.00
You can use the DECODE function to change a variable to an associated value.
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 TIBCO WebFOCUS® Using Functions manual.
In this section: |
To ensure that a supplied value is valid and being used properly in a procedure, you can test it for presence, type, and length. You can also verify that it has an acceptable format and that it falls within a specific range of values. For example, you would not want to perform a numeric computation on a variable for which alphanumeric data has been supplied.
How to: |
You screen a value by adding a suffix to the variable value:
A Dialogue Manager variable is a placeholder for a value that will be substituted at run time. In some situations, the value of the variable may not be resolved at the point where the command containing the variable is encountered, unless evaluation is forced by using the .EVAL operator. One example where .EVAL Is required is in a -IF statement, when the variable is embedded in a label (for example, GOTO AB&label.EVAL). The .EVAL operator is also required any time a variable is included within single quotation marks (').
-IF &name{suffix} expression GOTO label...;
where:
Is a user-supplied variable.
Is one of the following:
Is a valid expression that uses &name with the specified suffix as a variable.
Specifies a label to branch to.
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
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
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
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
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:
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:
The report request is stacked.
The DATE_SEPARATOR parameter defines a date separator character and the DATE_ORDER parameter defines the order of components for dates, based on your locale. The TIME_SEPARATOR parameter defines the time separator character for the &TOD variable. To use these settings with the Dialogue Manager system variables, (for example, &DATE, &TOD, &YMD, &DATEfmt, and &DATXfmt) append the suffix .DATE_LOCALE to the system variable. This allows system variables that are localized to coexist with non-localized system variables.
The following applies the DATE_ORDER and DATE_SEPARATOR parameters to the &DATE system variable.
SET DATE_SEPARATOR = DASH SET DATE_ORDER = DMY -TYPE NON-LOCALIZED: &DATE -TYPE LOCALIZED: &DATE.DATE_LOCALE
The output is:
NON-LOCALIZED: 04/07/17 LOCALIZED: 07-04-17
How to: |
You can validate a parameter value without accessing the data by using the REGEX mask. The REGEX mask specifies a regular expression to be used as the validation string. A regular expression is a sequence of special characters and literal characters that you can combine to form a search pattern.
Many references for regular expressions exist on the web. For a basic summary, see the section Summary of Regular Expressions in Chapter 2, Security, of the TIBCO WebFOCUS® Reporting Server Administration manual.
The following messages display in case of an error:
(FOC2909) INVALID REGULAR EXPRESSION: (FOC2910) RESPONSE DOES NOT MATCH THE REGULAR EXPRESSION:
&variable.(|VALIDATE=REGEX,REGEX='regexpression').
where:
Is the variable to validate.
Is the regular expression that specifies the acceptable values.
The following request validates a Social Security number in either xxxxxxxxx or xxx-xx-xxxx format:
-REPEAT NEXTFMT FOR &FMTCNT FROM 1 TO 2 -SET &EMPID1=DECODE &FMTCNT(1 '071382660' 2 '818-69-2173'); -SET &EMPID=IF &EMPID1.(|VALIDATE=REGEX,REGEX='^\d{3}\-?\d{2}\-?\d{4}$').Employee ID. CONTAINS '-' - THEN EDIT(&EMPID1,'999$99$9999') ELSE &EMPID1; TABLE FILE EMPLOYEE HEADING " " "Testing EMPID = &EMPID1</1" PRINT EID CSAL WHERE EID EQ '&EMPID.EVAL' ON TABLE SET PAGE NOPAGE ON TABLE SET STYLE * GRID=OFF,$ END -RUN -NEXTFMT
The output is
Testing EMPID = 071382660 EMP_ID CURR_SAL 071382660 $11,000.00 Testing EMPID = 818-69-2173 EMP_ID CURR_SAL 818692173 $27,062.00
In the following request, the second value for &EMPID1 is invalid because it does not conform to the REGEX mask:
-REPEAT NEXTFMT FOR &FMTCNT FROM 1 TO 2 -SET &EMPID1=DECODE &FMTCNT(1 '071382660' 2 '818-69-2173'); -TYPE EMPID1 = &EMPID1 -SET &EMPID=&EMPID1.(|VALIDATE=REGEX,REGEX='^\d{3}\d{2}\d{4}$').Employee ID.; -TYPE EMPID = &EMPID -NEXTFMT
The FOC2910 message in the output shows that the second value for &EMPID1 was rejected:
EMPID1 = 071382660 EMPID = 071382660 EMPID1 = 818-69-2173 ERROR AT OR NEAR LINE 7 IN PROCEDURE __WCFEX FOCEXEC * (FOC2910) RESPONSE DOES NOT MATCH THE REGULAR EXPRESSION: 818-69-2173 ERROR AT OR NEAR LINE 7 IN PROCEDURE __WCFEX FOCEXEC * (FOC295) A VALUE IS MISSING FOR: &EMPID1
In the following request, the REGEX mask is not a valid regular expression:
-SET &EMPID1='071382660'; -SET &EMPID=&EMPID1.(|VALIDATE=REGEX,REGEX='^\d{3}\d{2)}\d{4}$').Employee ID.;
The FOC2909 message in the output shows that the regular expression is not valid:
ERROR AT OR NEAR LINE 5 IN PROCEDURE __WCFEX FOCEXEC * (FOC2909) INVALID REGULAR EXPRESSION: ^\d{3}\d{2)}\d{4}$ ERROR AT OR NEAR LINE 5 IN PROCEDURE __WCFEX FOCEXEC * (FOC295) A VALUE IS MISSING FOR: &EMPID1
Reference: |
You can specify that a variable must adhere to a set of format conditions against which entered values can be compared. If the entered value does not have the specified format, a message displays informing the user that there are too many characters. The user can acknowledge the message and can try again to enter a valid value.
Alphanumeric formats are described by the letter A, followed by the number of characters. The number of characters can be from 1 to 3968.
Numeric formats are described by the letter I, followed by the number of digits to be entered. The number of digits can be from 1 to 10 (value must be less than 231-1), and the value supplied for the number can contain a decimal point.
The description of the format must be enclosed within periods (.).
If you test field names against input variable values, specify formats of the input variables. If you do not, and the supplied value exceeds the format specification from the Master File, the procedure is ended and error messages are displayed. To continue, the procedure must be executed again. However, if you do include the format, and the supplied value exceeds the format, the entered value will be rejected and the user is prompted again.
Note: Parameter values are internally stored in memory as alphanumeric codes. To perform arithmetic operations, the parameter value is converted to double precision floating point decimal and then the result is converted back to alphanumeric codes, dropping the decimal places. For this reason, do not perform tests that look for the decimal places in the numeric codes.
Consider the following format specification for the STATE and QTY_IN_STOCK fields.
TABLE FILE CENTORD BY QTY_IN_STOCK BY STATE BY PROD_NUM BY PRODNAME ON TABLE SUBHEAD "Inventory Report" WHERE STATE EQ '&STATE.A2.US State:.' WHERE QTY_IN_STOCK LT '&PRODNUM.I7.Quantity in Stock below:.' END
If, in the above example, the user enters more than two alphanumeric characters for the STATE value it is rejected, the message There are too many characters in your entry. is displayed, and the user is prompted again.
If, in the above example the user enters more than seven numeric characters for the QTY_IN_STOCK, the value is rejected, the message There are too many digits in your entry: (format is 'I7') is displayed, and the user is prompted again.
Reference: |
You can specify that a variable value must fall within a range of values against which entered values can be compared. If the entered value is not within the specified value range, a message displays informing the user that there are too many characters. The user can acknowledge the message and can try again to enter a valid value.
A value range is enclosed within parenthesis specifying (FROM value1 TO value2), where value1 is a numeric value less than value2. For example,
&QTY_IN_STOCK.(FROM 1 TO 10000)
Note: Parameter values are internally stored in memory as alphanumeric codes. To perform arithmetic operations, the parameter value is converted to double precision floating point decimal, and then the result is converted back to alphanumeric codes, dropping the decimal places. For this reason, do not perform tests that look for the decimal places in the numeric codes.
Consider the following value range specification for the &QTY_IN_STOCK variable.
TABLE FILE CENTINV PRINT QTY_IN_STOCK BY PROD_NUM BY PRODNAME ON TABLE SUBHEAD "Inventory Report" WHERE QTY_IN_STOCK LT &QTY_IN_STOCK.(FROM 1 TO 10000).Quantity in Stock below:. END
If, in the above example, the user enters a value less than 1 and more than 10000 for the Quantity in Stock below parameter value, the value is rejected and the message value entered is not within range 1 - 10000 is displayed.
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.
-SET &name.&index[.&index...] = expression;
where:
Is a variable.
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.
Is a valid expression. For information on the kinds of expressions you can write, see the Creating Reports With TIBCO WebFOCUS® Language manual.
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.