You are on page 1of 2

Using BTEQ to Export Data BTEQ allows data to be exported directly from Teradata to a file on a mainframe or network-attached computer.

In addition, the BTEQ export function has several export formats that a user can ch oose depending on the desired output. Generally, users will export data to a flat file format that is composed of a variety of characteristics. These characteristics include: field mode, indicator mode, or dif mode. Below is an ex panded explanation of the different mode options. Format of the EXPORT command: .EXPORT <mode> {FILE | DDNAME } = <filename> [, LIMIT=n] Record Mode: (also called DATA mode): This is set by .EXPORT DATA. This will bri ng data back as a flat file. Each parcel will contain a complete record. Since it is not a report, there are no he aders or white space between the data contained in each column and the data is written to the file (e.g., disk drive f ile) in native format. For example, this means that INTEGER data is written as a 4-byte binary field. Therefore, it canno t be read and understood using a normal text editor. Field Mode (also called REPORT mode): This is set by .EXPORT REPORT. This is the default mode for BTEQ and brings the data back as if it was a standard SQL SELECT statement. The output of this BTEQ export would return the column headers for the fields, white space, expanded packed or binary data (for humans to read) and can be understood using a text editor. Indicator Mode: This is set by .EXPORT INDICDATA. This mode writes the data in d ata mode, but also provides host operating systems with the means of recognizing missing or unknown data (NULL) f ields. This is important if the data is to be loaded into another Relational Database System (RDBMS). The issue is that there is no standard character defined to represent either a n umeric or character NULL. So, every system uses a zero for a numeric NULL and a space or blank for a character NULL. If this data is simply loaded into another RDBMS, it is no longer a NULL, but a zero or space. To remedy this situation, INDICATA puts a bitmap at the front of every record wr itten to the disk. This bitmap contains one bit per field/column. When a Teradata column contains a NULL, the bit for th at field is turned on by setting it to a "1". Likewise, if the data is not NULL, the bit remains a zero. Therefore, the l oading utility reads these bits as indicators of NULL data and identifies the column(s) as NULL when data is loaded back into the table, where appropriate. Page 3 of 91 Teradata Utilities-Breaking the Barriers, First Edition Since both DATA and INDICDATA store each column on disk in native format with kn own lengths and characteristics, they are the fastest method of transferring data. However, it becomes imperative that you be consistent. When it is exported as DATA, it must be imported as DATA and the same is true for INDICDATA . Again, this internal processing is automatic and potentially important. Yet, on a network-attached system, being consistent is our only responsibility. However, on a mainframe system, you must account for these bits when defining the LRECL in the Job Control Language (JCL). Otherwise, your length is too short

and the job will end with an error. To determine the correct length, the following information is important. As ment ioned earlier, one bit is needed per field output onto disk. However, computers allocate data in bytes, not bits. Therefore , if one bit is needed a minimum of eight (8 bits per byte) are allocated. Therefore, for every eight fields, the LR ECL becomes 1 byte longer and must be added. In other words, for nine columns selected, 2 bytes are added even though only nine bits are needed. With this being stated, there is one indicator bit per field selected. INDICDATA mode gives the Host computer the ability to allocate bits in the form of a byte. Therefore, if one bit is require d by the host system, INDICDATA mode will automatically allocate eight of them. This means that from one to eight columns being referenced in the SELECT will add one byte to the length of the record. When selecting nine to sixteen columns , the output record will be two bytes longer. When executing on non-mainframe systems, the record length is automatically main tained. However, when exporting to a mainframe, the JCL (LRECL) must account for this addition length. DIF Mode: Known as Data Interchange Format, which allows users to export data fr om Teradata to be directly utilized for spreadsheet applications like Excel, FoxPro and Lotus. The optional limit is to tell BTEQ to stop returning rows after a specific numbe r (n)

You might also like