Presentation is loading. Please wait.

Presentation is loading. Please wait.

Inside Module 8 Extracting Data Page Using the Extract command 2

Similar presentations


Presentation on theme: "Inside Module 8 Extracting Data Page Using the Extract command 2"— Presentation transcript:

1 Inside Module 8 Extracting Data Page Using the Extract command 2
Coercion 3 $-functions 4 Extract from a table 7

2 Extract basics Extract command “extracts” the data from the input source Fields are “placed” in the output file in order of the extract commands Extract a range of fields Extracting constants The Extract command extracts the data from the input data source. You can extract a field from a database, flat file or self-describing file by just referencing the field name. > extract customer-no The fields are written to the data source in the order specified in the extract commands. You can extract a range of fields by using the range syntax: > extract customer-no \ sales-amt The above command tells Suprtool to extract all the fields between and including customer-no and sales-amt based on the input source layout. This features works with Image and Eloquence datasets and self- describing files. You can also extract constants such as: > extract city=“Niagara Falls” > extract sales-amt=0 > extract ^13,^10 { extract carriage return and line feed }

3 Coercion and Numeric Expressions
Extract also coerces data from the source to the target Changes from one data type to another Define display-field,1,8,display Extract display-field = double-field Simple Arithmetic functions Extract total = cost * qty Extract budget99 = actual Extract profit = sales-amt – cost Extract average = total / qty Extract day = ccyymmdd-date mod 100 The Extract command also has the power to “coerce” (change) numeric data from one data type to another. For example if you have a double field in your data source you can change it to a display type with the extract command: >extract display-field = double-field Suprtool will know how to handle this transformation and do it for you. Suprtool is also capable of processing arithmetic expressions for any numeric data type.

4 Date $- functions $date specify constant or relative date value in various formats $today current system date or calculate a date relative to the system date $stddate converts a date in any format to CCYYMMDD $days converts the date into a Julian format Suprtool also has many functions to manipulate or set the intended target field. One set of functions that you can use to set or change data are the Date functions. Some of these functions are: $date – specify any date in any number of ways. Can define relative dates based on current system date $today- used to extract a today’s date or relative to today e.g. $today(-1) $stddate – convert any date format to ccyymmdd $days – converts any date format to julian days for date arithmetic

5 String $- functions converts all alphabetic characters to uppercase
$lower converts all alphabetic characters to lowercase $trim removes leading and trailing spaces $ltrim removes leading spaces $rtrim removes trailing spaces Other functions can be used on strings are: $upper- converts characters to upper case $lower – converts characters to lower case $trim – trims leading and trailing spaces $ltrim – trims leading spaces $rtrim – trims trailing spaces

6 Numeric $- functions Returns absolute value of a number
$truncate Returns a number to the left of the decimal place Suprtool supports numeric functions as well. The $abs function returns the absolute value of a given number. For example, if the field credit- amount contains the value –547.83, then the $abs function returns The function also works on an expression such as: >def newcredit,1,4,double >ext newcredit = $abs(credit / 100 * 1.07) The $truncate function returns the number to the left of the decimal place. For example, if the field stddev contains the value , the $truncate function returns 547. Please note there is no rounding. Like the $abs function, $truncate also works on expressions as well as fields: > def newdev,1,4,double >ext newdev = $truncate(stddev * 1.07 / 100)

7 Extract from a table $lookup available in Extract but slightly different Must load the table with data Table mytable,key,file,sdfilename,data(tabledata) File must be self-describing Extract field = $lookup(mytable,key,tabledata) The Table command allows for data to be loaded along with matching key values. >table table-name,key-field,file,filename,data(field1,field2,...) An example of loading two data fields called cost and desc along with the key field of part into a table would be: >table partab,part,file,partin,data(cost,desc) You can specify up to 20 data fields as long as the total size of the key fields and data does not exceed 256 bytes. The Table file must be self- Describing (Link) in order to use the data option. When loading data into a table, Suprtool eliminates duplicate entries based on the key value, so the associated data values may not be loaded into the table. The Extract command can utilize the $lookup function to return data. The syntax for the $lookup function would look as follows: >extract target = $lookup(table-name,key-field,data-field) The Table name, key-field and data-field are all defined by the Table command, which must be input before the Extract command.

8 Extract from a Table Sample
>table newprices,prodno,file,bosslist,data(price,desc) >get part-master >if $lookup(newprices,prodno) >update >extract price = $lookup(newprices,prodno,price) >extract desc = $lookup(newprices,prodno,desc) >xeq A classic example: your boss comes to you with a list of new prices and descriptions for certain parts in the Part-Master dataset. The basic steps to do this are to load the new prices and descriptions into a Table, indexed by the product number (prodno), then Extract the price field from each record and replace it with a $lookup on the table. We do the If $lookup to select only the parts which have new prices, then Extract with $lookup to replace the existing price with a new one. The Update command forces a database update on each selected record and must come before the Extract command. If you do not specify the If $lookup, then records that did not qualify under the $lookup function in the extract field, would end up with zeroes for any numeric field and spaces for any byte type fields.

9 Summary Extract command Extract with coercion Numeric Expressions
Extract with $-functions Date functions String functions Numeric functions Extract from a table


Download ppt "Inside Module 8 Extracting Data Page Using the Extract command 2"

Similar presentations


Ads by Google