Data Conversion. Robelle Suprtool 4.6.01, STExport, Suprlink
Реклама
Реклама
94
• Suprtool Commands
>extract city-up = $upper(city)
>extract full-name = $upper(first + last)
Downshifting Strings ($Lower)
If you want to downshift all characters of a string expression to lowercase, use the built-in function $lower. This function can be used to downshift a single field, a complicated string expression, or any subpart of an expression. Both ASCII and
Roman-8 characters are downshifted by $lower. For example,
>extract city-lower-case = $lower(city)
>extract city-state = $lower(city + state)
Trimming Spaces Using $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.
Data Conversion
You can convert numeric fields from one data-type to another. Any nonbyte field type is considered to be numeric. You can also lengthen or truncate character fields.
The general syntax for doing conversions is:
Target-Field
The target-field determines the byte-length, data-type, and repeat-count for the expression. The expression is extracted during the output phase and cannot be used by other Suprtool commands that accept fields (e.g., Sort). To avoid confusion, it is best to define a new field name for the target-field instead of using an existing field name.
The following example shows defining a new target-field as a double integer. The
Extract command target-field then takes the definition from the Define command and extracts data from the source-field (display-field).
>in oldfile
>def salesqty,1,4,double
>ext order-no / order-date
>ext salesqty = display-field
Packed and Display Fields
When the target of an extract conversion is a packed- or display-type field, Suprtool always converts positive values to a neutral packed- or display-value. To ensure that expressions with positive values have a positive result, use the $signed function:
>extract packed_field = $signed(int_field)
>extract display_field = $signed(dbl_field / 10)
Truncation errors can occur when Suprtool converts from nonfloating-point to floating-point. See the discussion under Numeric Truncation above.
Suprtool 4.6 for HP-UX: Suprtool
Suprtool 4.6 for HP-UX: Suprtool
Byte Fields
Use the Extract command to shorten or lengthen byte-type fields.
If the target-field is longer than the source-field, Suprtool fills the trailing space in the target-field with spaces.
Byte to Numeric Conversion
Suprtool cannot explicitly convert from a byte field to a numeric field such as a double integer. The Extract command, however, does allow conversion from a display field to a double integer (or any other numeric field).
You can define a byte field to be a display field if all of the characters in the field contain a number. For example if you have a six-character byte field that looks like this:
012345 you can define it in the following manner:
>def display-field,1,6,display
This field can then be converted to any of the other numeric types that Suprtool supports.
If the field is six characters and contains blanks, you would have to pad the field with zeros so that Suprtool can manipulate the field as a display field.
Restrictions
You can only use one expression in each Extract command, and the expression must be the last item. If you want to extract several expressions or more fields after an expression, you need to use several Extract commands.
Incorrect
>extract name, i=sales + tips, c=cost, dept
Correct
>extract name, i=sales + commission
>extract c=cost
>extract dept
Extracting Bits
The Extract command can be used to define individual bits from one data item as separate fields.
>def order-shipped,1,2,int
>def order-paid ,1,2,int
>ext order-shipped=status-field.(0:1)
>ext order-paid=status-field.(1:1)
This makes it easier to check the status of certain bits within a given field.
EBCDIC Conversions
Use the $etoa or $atoe functions to convert specific fields from EBCDIC to ASCII or vice versa. Each of these functions accepts a single parameter that is a byte-type field:
Extract $ETOA(char-field)
Suprtool Commands
• 95
Extract $ATOE(char-field)
There are several restrictions on the $etoa and $atoe functions:
• They do not work with either the ASCII or PRN output options.
• You cannot extract an EBCDIC constant. The following example would produce an error message:
>extract $etoa(char-field) = 'abcdef'
• You cannot extract a range of fields using $etoa or $atoe.
Notes
The Extract command is valid only with
• Output xxx,data
• Output xxx,data,num
• Output xxx,query
• Output xxx,link
• Output xxx,ascii
• Output xxx,prn
The Extract occurs logically after the sort phase, if any, but prior to the final Output,
Put, or List. An If command can refer to fields of the input record that are not included in the extracted output record. The sort keys can be fields that are not among those extracted.
If the extracted record length is shorter than the input record length, Suprtool attempts to speed up sorts by doing the extract before sorting. Suprtool can only do the extract before sorting if the output option is DATA (the default), QUERY, or
LINK, and all of the sort keys are included in the Extracted fields.
One advantage of not using the Extract command is that the output file from
Suprtool has exactly the same format as the input dataset which created the file. You can then use the =setname option of the Input command to define all of the fields in the output file. Even if you change your database structure, many of your job streams that use Suprtool and the =setname option will not have to be changed.
96
• Suprtool Commands
Suprtool 4.6 for HP-UX: Suprtool
Изтегляне
Реклама