String Expressions. Robelle Suprtool 4.6.01, STExport, Suprlink
विज्ञापन
विज्ञापन
110
• Suprtool Commands
>if $truncate(stddev / 100 * 1.07) > 200
This function will also work in the Extract command:
>def newdev,1,4,double
>ext newdev = $truncate(stddev / 100 * 1.07)
String Expressions
You can do comparisons with byte-type fields in numerous ways using Suprtool.
These powerful features minimize the number of tasks you must execute in order to select the data you need. The fewer the number of tasks, the faster your data is delivered to the users and applications that need it.
You can combine byte-type fields together and use the built-in string functions to create string expressions. String expressions involve the + operator and the other string functions such as $lower, $upper, $trim, $ltrim and $rtrim.
Fixed vs. Variable Length Strings
String comparisons are done using fixed- and variable-length strings. For most users, there should be no difference between the two types of strings. When doing string comparisons, Suprtool always pads shorter strings with spaces, with the one exception of comparing two fixed-length fields (see "Byte Fields" below).
String expressions involving the + operator or the $upper, $lower, $trim, $ltrim and
$rtrim built-in functions are done using variable-length strings. Suprtool keeps track of the length of every string, and all operations are done using the actual string length. For fields, the length of the string is the length of the field. If you do not want to retain all of the spaces in a field, use one of the built-in trimming functions.
When creating string expressions, string constants are created with the exact length of the constant. For example, the string constant "abc" is three characters long and the string "a" is one.
Byte Fields
For historical reasons, comparing two byte-type fields to each other is a special case.
If the two fields are exactly the same length, Suprtool compares them completely. If one field is shorter, the comparison is done for the length of the shortest field.
Suprtool does not check for spaces in the trailing characters of the longer field. For example,
>define short, 1,10 {ten character field}
>define long ,11,15 {fifteen character field}
>if short = long
In this example, Suprtool compares the ten bytes in the short field with the first ten bytes of the long field, but ignores the last five bytes of the long field. If the expression on either side of the equal sign consisted of more than one field (using the
+ operator) or involved any of the string functions, ($upper, $lower, $trim, $ltrim or
$rtrim), Suprtool would have compared both sides of the equal sign by padding the shorter field with spaces. It is only the case where you are directly comparing one byte-type field to another that Suprtool uses the length of the shortest field for the comparison.
You cannot compare a byte-field to a numeric-type field. If you have a byte-field that consists entirely of numeric digits, redefine the field as a display-type and use the redefined field name in the If command.
Suprtool 4.6 for HP-UX: Suprtool
Suprtool 4.6 for HP-UX: Suprtool
Character Type
Byte-type fields can also be checked to see whether they contain only Alpha,
Numeric, Alphanumeric, or Special characters. The complete field is compared against the specified character types.
Type Characters
Alpha A-Z, a-z (52 characters)
Special
Alphanumeric anything else (194 characters, including spaces, punctuation, Roman-8 letters, binary junk)
A-Z, a-z, 0-9 (62 characters)
For the test result to be true, all the characters in the field must be of the specified character type. To test a substring, use the Define command to define a subfield.
>if field = alpha
>if field <> numeric
Examples:
String Class
"1234" numeric
"12.3" no class, contains both numeric and special
"ABCD" alpha
"B JONES" no class, contains both alpha and special
" " special
"A1B2" alphanumeric
Pattern Matching
Suprtool can also select records based on a pattern of characters, rather than an exact string of characters. For example, use the following to select all records with
"ROBERT" anywhere in the Name field,
>if name == "@ROBERT@"
The double equals (==) is the operator for pattern matching. The at signs (@) means anything before or after "ROBERT" is acceptable, including nothing.
For character fields, there are two comparison operators for patterns: "==" (matches), and "><" (does not match). The pattern is specified as a quoted string, using the special characters listed below. Embedded spaces are allowed in the pattern and must be matched in the target field.
These are the special characters:
Character Meaning
@
#
Zero, or more, characters of any type.
A single numeric character.
Suprtool Commands
• 111
112
• Suprtool Commands
^
!
?
~
&
A single alphabetic or numeric character.
Zero, or more, blank characters.
Escape character to match the next character explicitly (&@ looks for the @ character).
Reserved for future use.
Reserved for future use.
Any other character must be matched, one for one.
>if name=="@BIRD@" {does name contain BIRD anywhere?}
>if name=='@JIM@BIRD@' {does name contain JIM, perhaps …}
{… other characters, then BIRD?}
>if name><"@#@" {does name not contain numerics?}
>if name=='@qedit@','@suprtool@' {qedit or suprtool?}
For more information, see Special Characters in the Glossary.
Trimming Spaces ($Trim, $Ltrim, $Rtrim)
Use one of three built-in string functions to remove leading or trailing spaces from a string expression. The three functions are:
$Trim: Remove leading and trailing spaces from the string expression.
Because Suprtool pads shorter strings with spaces when doing comparisons, trimming spaces is most useful when creating a combined string with several fields.
For example, you might want to combine a person's first and last name (including a space between the two):
>if $trim(first) + " " + $trim(last) = "Joe Smith"
Mixed Case ($Upper and $Lower)
By default, Suprtool does an exact match when comparing two string expressions. If the expressions vary in the capitalization of characters, Suprtool finds them to be different. To do caseless string comparisons or pattern matches, use the $upper or
$lower functions. Both ASCII and Roman-8 characters are shifted by $upper and
$lower. For example,
>if $upper(city) = "VANCOUVER"
>if $lower(city) = "edmonton"
Note that if you use the $upper or $lower functions, Suprtool does not upshift or downshift any constants used in the comparison. You must explicitly specify the constants in the correct case or you can use $upper or $lower with the constant:
>if $upper(city) = $upper("vancouver")
Use the $upper or $lower functions for caseless pattern matching. As with other comparison operators, you must specify constants in the correct case when doing pattern matching:
>if $upper(city) == "VAN@"
>if $lower(city) == "ed@"
You can use $upper and $lower with string expressions that combine many fields and string functions as shown in the following example:
Suprtool 4.6 for HP-UX: Suprtool
डाउनलोड
विज्ञापन