Presentation is loading. Please wait.

Presentation is loading. Please wait.

Inside Module 7 Exporting Data to the World Page

Similar presentations


Presentation on theme: "Inside Module 7 Exporting Data to the World Page"— Presentation transcript:

1 Inside Module 7 Exporting Data to the World Page
Exporting data to other applications 2 STExport converts the data 4 Running STExport 5 Dates and Decimals 8 Specifying fieldnames 10 Creating Web pages 12 Summary of formatting commands 17 Resetting defaults 18 XML command 19 Clean your data 23 The ability to migrate data from databases and files to other platforms is a common requirement. Past methods of exporting data relied on fixed formats which did not always permit the data to be imported easily into other applications, and which required considerable work from programmers. STExport is the newest module of the popular and powerful Suprtool database utility. In this module, you will learn how to use STExport to export data from your HP 3000 or HP 9000 to just about any other platform—all without your having to write a custom program. STExport is fully documented in the Suprtool User Manual and the Suprtool Quick Reference Guide.

2 Exporting Data to other Applications
Extract the data using Suprtool and Suprlink Convert the files using STExport Transfer the file to the PC Import the delimited file In the previous modules, you have learnt how to use Suprtool and Suprlink’s powerful selection, extracting and linking features to create an output file containing the data you need. In many cases, this file would be used as input to a host-based reporting tool like Quiz, or a Cobol program, which would generate the report the user requires. But what if the reporting tool is on a different machine, with a different operating system? In those cases, the file would require some further conversion, to make it legible by the destination application. Importing to a PC application is similar in concept to almost any job where Suprtool is used to feed data to a program. The only extra step would be using STExport to reformat the output before transferring the file to the PC. Suprtool Suprlink STExport

3 Data needs to be converted
Image and Eloquence data has: - Fixed-width fields - Binary storage formats (J2, K2, P28, etc) - Structure defined in Root File. PC Applications require: - Variable-length fields - ASCII values for numerics - Field delimiters - Field name declarations For many years, Suprtool has been able to create output files in Lotus’ PRN format directly: > output salesumm,PRN This creates a comma-delimited file, with double-quotes around the character fields, and binary fields converted to ASCII. This format can still be loaded directly into a number of PC applications. However, some applications require that the data be formatted slightly differently. For example, IMAGE stores trailing blanks on character fields. So that field would include the trailing blanks within the quotes in the PRN file. If the PC application is used to generate form letters, the blanks would be included between the addressee’s first and last names. Much of Suprtool is built around the assumption that it works with fixed-length records. So STExport was added as a separate module in version 3.8, to handle reformatting of data into formats that can be loaded directly into applications on PCs and other platforms.

4 STExport converts the data
STExport reads self-describing files Outputs ASCII files Allows you to specify: field delimiters to use date format fieldnames in first record numeric format fixed or variable length quotes on character fields HTML - table or preformatted XML output STExport reads self-describing (“link”) files, and reformats the data into an ASCII output file: Numeric fields (Integers, Packed, etc) are converted to their character representations Character fields are enclosed in quotation marks Trailing blanks are (optionally) removed from character fields Leading zeros are (optionally) removed from numeric fields The fields are separated with delimiters Date fields can be reformatted Numeric fields with implied decimals have a decimal point inserted Output records can be variable-length Either of two HTML (HyperText Markup Language) formats can be generated Simple XML support Data can be cleaned up The first record can contain field names ....and more...

5 Ways to run STExport On MPE
From the MPE prompt :run stexport.pub.robelle From Suprtool >export From inside of Suprtool >export input custsd >export output custexp >export exit In=20. Out=20. CPU-Sec=1. Wall-Sec=1. On HP-UX /opt/robelle/bin/stexport On MPE Just like Suprlink, the STExport command interface can be invoked directly from the MPE prompt, or from the Suprtool command line. Alternatively, commands can be passed to STExport from the Suprtool command line, without invoking STExport’s command interface directly. This last method is particularly useful when using input redirection: :Run suprtool.pub.robelle < mycmds This method also adds all STExport commands into Suprtool’s command stack, instead of STExport’s stack, so they can be reinvoked with Suprtool’s REDO functions. (STExport has its own, separate, REDO stack) On HP-UX STExport can only be run as a stand-alone program. The Export command is not supported from inside Suprtool.

6 For example ...... >export $in custsd $out custexp $xeq
In=19. Out=19. CPU-Sec=1. Wall-Sec=2. $print custexp "Vancouver",200000,10010,"20","Wayne","Humphreys","BC",..... "Coquitlam",200000,10014,"20","Elizabeth","Welton","BC",..... "Richmond",200000,10011,"20","William","Kirk","BC",..... "Calgary",200000,10017,"20","Jack","Morrison","AL",..... "Edmonton",200000,10015,"20","James","Young","AL",...... "Coquitlam",200000,10012,"20","Percy","Ferguson","BC",..... "Surrey",200000,10020,"20","Walley","Nisbet","BC",..... Above is a simple STExport task, and some sample data from the output file. Note that STExport has: enclosed character fields in “double-quotes” inserted commas between the fields removed trailing blanks from character fields converted numeric fields to ASCII This format is sometimes known as CSV (Comma-Separated Values).

7 In Microsoft Excel Transfer to PC, File/Open in Microsoft Excel:
If the file created on the previous page is transferred to a PC, it can be loaded directly into Microsoft Excel (File/Open/filename.csv).

8 Dates and Decimals Use Suprtool’s ITEM command to qualify the fields:
>get d-sales >item deliv-date,date,YYYYMMDD >item product-price,decimal,2 >out salesd,link >x IN=8, OUT=8. CPU-Sec=1. Wall-Sec=1. >form salesd File: SALESD.HANS.TRAINING (SD Version B.00.00) Entry: Offset CUST-ACCOUNT Z DELIV-DATE I <<YYYYMMDD>> PRODUCT-NO Z PRODUCT-PRICE I << .2 >> PURCH-DATE I etc To get STExport to reformat dates, it needs to know which fields represent date values, and what the format of the input date field is. For example, a PHDate is stored as a J1 or K1 (Integer) field, with the first seven bits representing the year, four bits for the month, and five bits for the day. So the PHDate representation of 19th March, 1998 is a numeric value of In order to work with the logical value of this field, STExport must know that the numeric value represents a stored PHDate. Similarly, fields that contain implied decimals must be identified accordingly. This information must be in the self-describing file’s label when STExport opens the file, so must have been declared in that task that created the input file, by means of the ITEM command. On MPE, field information is stored in the file’s userlabels which are an integral part of the file. On HP-UX, field information is stored in a separate file ending with a .sd extension. In this example, there would be a data file, salesd, and a self-describing file, salesd.sd.

9 ...... continued Specify date format in STEXPORT: >export
$in salesd $date DDMMYY "/" $output * $x 10020,04/10/97, ,98.31, ,2,2753,22415 10003,16/10/97, ,98.31, ,1,1376,11207 10003,16/10/97, ,145.62, ,1,2039,16600 10003,16/10/97, ,192.20, ,1,2691,21910 10016,20/10/97, ,24.59, ,3,1033,8411 10016,20/10/97, ,139.85, ,1,1958,15942 10020,28/10/97, ,146.60, ,1,2052,16713 10010,20/10/97, ,69.92, ,1,979,7970 In=8. Out=8. CPU-Sec=1. Wall-Sec=1. Notice that the second field (deliv-date) has been formatted with the specified date format, while the fifth field (purch-date) has not. This is because only the deliv-date field was identified as a date field in the previous slide. If both date fields had been qualified as dates, they would both have been reformatted in the output file. Notice also that the fourth field (product-price) has a decimal point inserted before the last two digits. In some countries the comma is used as the radix (decimal place). Use Decimal Comma, and use the Delimiter command to choose a character other than comma as the field separator.

10 Specifying field names
Use HEADING command to add fieldnames in the first record: $heading '"Description","Model"' $heading add ',"Product Code"' $output * $xeq "Description","Model","Product Code" "Skil 3/8 Variable Speed Drill","#6523", "B&D Router","# ", "Skil Var. Sp. Auto-Scroll Saw","#4560", "Skil 8 1/2 Circular Saw","#5665", .....etc..... HEADING FIELDNAMES uses Image field names. Many PC applications have “smart” file import functions that can automatically rearrange imported records to place the correct values in the correct logical fields in the SQL tables (or columns in the case of spreadsheets). To identify the fields in the imported file, the application needs to find a “header” record showing the fieldnames. This header record needs to use the same delimiters as the data, and fieldnames enclosed in the same quotes as the data. STExport can insert it for you: $ heading fieldnames ... will use the field names from the input file. Or you can specify different field names explicitly: $ heading ‘“Account”’ $ heading add ‘,”Name”’ Note that the strings you define must include the appropriate quote and delimiter characters. STExport will automatically include the quotes and delimiters, if you use the “column” keyword: $ heading column “Account” $ heading column “Name”

11 Fixed-length output Force fixed-length with COLUMNS command
$input prodsd $columns fixed $out * $x "Description","Model","Product Code" "Skil 3/8 Variable Speed Drill","#6523" , "B&D Router" ,"# " , "Skil Var. Sp. Auto-Scroll Saw" ,"#4560" , "Skil 8 1/2 Circular Saw" ,"#5665" , "B&D Cordless Screwdriver" ,"# " , Also see SPACES and ZERO commands By default, STExport trims trailing spaces off character fields, and leading zeroes off numeric fields, to create variable-length output records. If your destination application expects the fields to start in a consistent location within the records, you can change this default by specifying: $ columns fixed Notice that the fields in the above example start at the same offset within the records, but trailing blanks have been removed within the quotes. You can force STExport to include trailing blanks and leading zeroes as follows: $ spaces trailing {character fields} $ zero leading {numeric fields} Note that the options for the COLUMNS command are FIXED and NONE (not VARIABLE as shown in the version 3.8 Quick Reference Guide and Manual)

12 Preparing Data For The Web
STExport can create HTML files Data can be formatted in a table HTML TABLE command Or it can be formatted like a List Standard listing HTML PREFORMATTED command Formatting is applied by STExport Numeric data is right justified, with decimal points Alpha data is left justified Dates are formatted as you specify

13 Preparing HTML Tables Use the HTML TABLE command $input reptfile $heading none $heading column "Account #" $heading column "Amount" $heading column "Date" $heading column "Product #" $heading column "Last Name" $heading column "First Name" $html table title "Orders" heading "BC Sales over $100" $output bcsales $xeq STExport remembers the heading settings from one task to the next. If a task needs the same column/field headings as the prior STExport task used, no Heading command is needed. If a task needs to establish its own column/field headings, use Heading None to disable any prior headings before defining any new ones. The HTML Title option sets the <TITLE> option in the HTML code, which usually appears in the browser's application title bar. The HTML Heading option sets the <H1> option in the HTML code, which will be shown at the top of the document. Transfer the output file to a web server using FTP, Reflection file transfer, or some other file transfer mechanism. The REPTFILE used in this example was created halfway through Module 6, Working with Suprlink.

14 Table With Column Headings
The table has one column per field, and one row per record <html> <head> <title>Orders</title> </head> <body> <h1>BC Sales over $100</h1> <table border=1> <tr><th>Account #<th>Amount<th>Date<th>Product #<th>Last Name<th>First Name</tr> <tr><td align=right>10003<td align=right>112.07<td align=right> <td align=right> <td>Melander<td>John</tr> <tr><td align=right>10003<td align=right>166.00<td align=right> <td align=right> <td>Melander<td>John</tr> <tr><td align=right>10003<td align=right>219.10<td align=right> <td align=right> <td>Melander<td>John</tr> <tr><td align=right>10020<td align=right>224.15<td align=right> <td align=right> <td>Nisbet<td>Walley</tr> <tr><td align=right>10020<td align=right>167.13<td align=right> <td align=right> <td>Nisbet<td>Walley</tr> </table> </body> </html>

15 Listing-style Data Use the PREFORMATTED option instead of TABLE
Because Preformatted supposes the information is in the proper format already, STExport puts the fields in fixed columns. However, if you define custom headings, you have to make sure the column headers are lined up properly with the data.

16 HTML Exercise Create an HTML Table that looks like this:
To create the data file that you will use as input to STExport, USE the following file of Suprtool commands: use custsale.usefiles This creates a temporary file in your group called CUSTSALE. The custsale use-file does some things that you might find interesting, such as linking four files together, and finding the earliest and latest transactions for a given customer.

17 Summary of formatting Commands
Command Options (default underlined) Columns Fixed None Date None <format> <“separator”> <invalid “ “> Decimal Period Comma Delimiter None Comma Tab “string” Floating Default Fixed Scientific Heading None Fieldnames “string” Column “string” HTML None Preformatted Table Quote None Double Single Sign None Floating Leading Trailing Spaces None Trailing Zero None Leading

18 Settings survive the task ....
Specified settings apply to subsequent tasks Suprtool resets most settings at the end of each task STExport resets input and output files, but remembers your settings Can specify once, and use many times. To reset commands, you must set a new preference: heading none floating default delimiter comma ...etc

19 XML Command XML Output version doctype file record
STExport now generates "well-formed" XML output with just a few commands. /opt/robelle/bin/stexport $input file1sd $xml $output myxml $xeq These four simple commands generates a file (see next page) that software packages such as XMLSpy consider to be "well-formed" XML. By default, STExport adds the simplest version tag at the beginning of the file, then it inserts a <file> and matching </file> at the beginning and at the end of the file. Then STExport encloses each record from the input file in a <record> and </record> tag. Finally, the Self-Describing tags are added around each field's data values and edited appropriately. Naturally, users would want options to customize and specify the various options and tags themselves, in order to generate a file that is acceptable to their tools. You can specify the "version" tag at the beginning of the XML file with the following command: xml version "?xml version='1.0' encoding='ISO '?"

20 XML data <?xml version='1.0' encoding='ISO-8859-1'?>
<Orders> <Details> <CITY>Los Altos</CITY> <CREDIT-RATING>100000</CREDIT-RATING> <CUST-ACCOUNT> </CUST-ACCOUNT> <CUST-STATUS>20</CUST-STATUS> <NAME-FIRST>Ralph</NAME-FIRST> <NAME-LAST>Perkins</NAME-LAST> <STATE-CODE>CA</STATE-CODE> <STREET-ADDRESS>Room 655</STREET-ADDRESS> <STREET-ADDRESS>Los Altos </STREET-ADDRESS> <ZIP-CODE>93002</ZIP-CODE> </Details> </Orders> STExport puts the "<" and ">" around what is specified in the version string. In addition, you can customize the "file" and "record" tags with the following simple commands: xml file "orders" record "orderdetail" You can enter multiple XML commands per task to set the XML options you require. The following commands produced the data above. $in file1sd $xml version "?xml version='1.0' encoding='ISO '?" $xml file "Orders" record "Details" $out myfile $xeq

21 Xml Tag Characters Special characters in Tags Set xmltagchar “.”
In XML, the tags surrounding the data can not have special characters other than hyphen, underscore and period ("-","_", "."). So, STExport replaces any of the invalid special characters with a "." by default. You can change the default character to something else with the following set command: $Set xmltagchar "_" STExport only allows the hyphen, underscore and period to be used with this command. A Document Type Declaration can be made at the beginning of the file via the !DOCTYPE specification. This typically tells whatever tool that is parsing the xml file where the DTD for the file resides. In STExport you can specify simple one-line doctype specs with the following command: xml doctype '!DOCTYPE address-book SYSTEM "address-book.dtd"' This writes the doctype specification at the top of the output file, directly after the XML version specification. All of STExport's XML command options (version, doctype, file and record) accept a string enclosed in quotes. The quotes may be either single or double, but keep in mind that if the string is to contain double quotes, then you should enclose the entire string with single quotes.

22 New Stuff Escape Command SQL import
Some Database Importers require an “escape” character STExport takes care of this for you Many SQL importers allow you to add an escape character in front of characters that may mean something else to the import program. For example, if the import program thinks that the delimiter character is a comma, the importer may treat a comma in an address field as an indication to move to the next field, which will throw off the import. Some import programs treat the next character as data as opposed to a delimiter if the character is preceded by an escape character, such as a slash. Thus when the field is analyzed by STExport the data that originally started as: "Niagara Falls,Ontario, Canada" would be transformed into: "Niagara Falls/,Ontario/, Canada" This function does not work on fixed columns and can be invoked with the escape command: escape delimiter quote eol "/“ The above command takes the defined delimiter, quote and Eol and escape with a "/", if found in any byte type field. End-of-line character is usually ASCII code 10 also known as Newline, Linefeed or LF.

23 Clean your Data Clean command
Replaces certain characters with whatever you choose Does all byte fields Sometimes non-printable characters or “bad data” get entered into byte type files. STExport can automatically clean all the byte type fields for a given SD file. STExport just needs to know what the replace character should be and which characters it needs to look for. $ in mysdfile $ clean "^9","^10","^0","^7" $ set cleanchar " " $ out myexport $ xeq The above task looks for all instances of Tab (“^9”), LineFeed (“^10”), Null (“^0”) and the Bell character(“^7”). STExport scans all byte-type fields for these characters and replaces them with a space as defined by the Set Cleanchar command. Since Cleanchar is set to space by default, the above task could simply be:

24 Summary STExport reformats data for other applications
Controlling STExport’s output layout Can be invoked in 3 ways on MPE Creating Web Pages Resetting defaults


Download ppt "Inside Module 7 Exporting Data to the World Page"

Similar presentations


Ads by Google