FLOAD Sample&Problem
FLOAD Sample&Problem
Let’s look at an actual FastLoad script that you might see in the real
world. In the script below, every comment line is placed inside the
normal Teradata comment syntax, [/*. . . . */]. FastLoad and SQL
commands are written in upper case in order to make them stand out.
In reality, Teradata utilities, like Teradata itself, are by default not
case sensitive. You will also note that when column names are listed
vertically we recommend placing the comma separator in front of the
following column. Coding this way makes reading or debugging the
script easier for everyone. The purpose of this script is to update the
Employee_Profile table in the SQL01 database. The input file used for
the load is named EMPS.TXT. Below the sample script each step will be
described in detail.
Normally it is not a good idea to put the DROP and CREATE statements
in a FastLoad script. The reason is that when any of the tables that
FastLoad is using are dropped, the script cannot be restarted. It can
only be rerun from the beginning. Since FastLoad has restart logic built
into it, a restart is normally the better solution if the initial load
attempt should fail. However, for purposes of this example, it shows
the table structure and the description of the data being read.
SESSIONS 100; /*or, the number of sessions supportable*/ Specify the number of
sessions to logon.
TENACITY 4; /* the default is no tenacity, means no retry */ Tenacity is set to 4 hr;
SLEEP 10; /* the default is 6, means retry in 6 minutes */ Wait 10 Min between
retries.
LOGON CW/SQL01,SQL01;
SHOW VERSIONS; /* Shows the Utility’s release number */ Display the version of
FastLoad.
/* Set the Record type to a comma delimited for FastLoad */ Starts with the second
RECORD 2; record.
SET RECORD VARTEXT ‘,’; Specifies if record layout
is vartext with a comma
delimiter.
Notice that all fields are
defined as VARCHAR.
When using VARTEXT,
the fields do not contain
the length field like in
these formats: text,
FastLoad, or
unformatted.
FILE= EMPS.TXT; Defines the flat file
name.
/* Optional to show the layout of the input */ SHOW Specifies table to load
and lock.
/* Begin the Load and Insert Process into the */
/* Employee_Profile Table */
BEGIN LOADING SQL01.Employee_Profile Names the error tables.
ERRORFILES SQL01.Emp_Err1, SQL01.Emp_Err2 Sets the number of rows
CHECKPOINT 100000; at which to pause &
record progress in the
restart log before loading
further.
Defines the insert
statement to use for
loading the rows.
Figure 4-3
Step Two: Next, you LOGON to the Teradata system. You will quickly
see that the utility commands in FastLoad are similar to those in BTEQ.
FastLoad commands were designed from the underlying commands in
BTEQ. However, unlike BTEQ, most of the FastLoad commands do not
allow a dot [“.”] in front of them and therefore need a semi-colon. At
this point we chose to have Teradata tell us which version of FastLoad
is being used for the load. Why would we recommend this? We do
because as FastLoad’s capabilities get enhanced with newer versions,
the syntax of the scripts may have to be revisited.
Step Three: If the input file is not a FastLoad format, before you
describe the INPUT FILE structure in the DEFINE statement, you must
first set the RECORD layout type for the file being passed by FastLoad.
We have used VARTEXT in our example with a comma delimiter. The
other options are FastLoad, TEXT, UNFORMATTED OR VARTEXT. You
need to know this about your input file ahead of time.
Step Four: Next, comes the DEFINE statement. FastLoad must know
the structure and the name of the flat file to be used as the input FILE,
or source file for the load.
Step Seven: All that goes up must come down. And all the sessions
must LOGOFF. This will be the last utility command in your script. At
this point the table lock is released and if there are no rows in the
error tables, they are dropped automatically. However, if a single row
is in one of them, you are responsible to check it, take the appropriate
action and drop the table manually.
**** 17:53:53 RDBMS error 2719: FASTLOAD END LOADING cannot be inside the Data Loading
phase.
sessions 2;
errlimit 25;
logon dbc/dbc,dbc;
DATABASE pramod;
CREATE TABLE employee (
EmpNo SMALLINT FORMAT '9(5)' BETWEEN 10001 AND 32001 NOT NULL,
Name VARCHAR (12),
DeptNo SMALLINT FORMAT '999' BETWEEN 100 AND 900,
PhoneNo SMALLINT FORMAT '9999' BETWEEN 1000 AND 9999,
JobTitle VARCHAR(12),
Salary DECIMAL(8,2) FORMAT 'ZZZ,ZZ9.99' BETWEEN 1.00 AND 999000.00,
YrsExp BYTEINT FORMAT 'Z9' BETWEEN -99 AND 99,
DOB DATE FORMAT 'MMMbDDbYYYY',
Sex CHAR(1) UPPERCASE,
Race CHAR(1) UPPERCASE,
MStat CHAR(1) UPPERCASE,
EdLev BYTEINT FORMAT 'Z9' BETWEEN 0 AND 22,
HCap BYTEINT FORMAT 'Z9' BETWEEN -99 AND 99 )
UNIQUE PRIMARY INDEX( EmpNo );
define
delim0(char(1)),
EmpNo(char(9)), delim1(char(1)),
Name(char(12)), delim2(char(1)),
DeptNo(char(3)), delim3(char(1)),
PhoneNo(char(4)), delim4(char(1)),
JobTitle(char(12)), delim5(char(1)),
Salary(char(9)), delim6(char(1)),
YrsExp(char(2)), delim7(char(1)),
DOB(char(11)), delim8(char(1)),
Sex(char(1)), delim9(char(1)),
Race(char(1)), delim10(char(1)),
MStat(char(1)), delim11(char(1)),
EdLev(char(2)), delim12(char(1)),
HCap(char(2)), delim13(char(1)),
newlinechar(char(1))
file=C:\insert.input.txt;
show;
begin loading employee errorfiles error_1, error_2;
insert into employee (
:EmpNo,
:Name,
:DeptNo,
:PhoneNo,
:JobTitle,
:Salary,
:YrsExp,
:DOB,
:Sex,
:Race,
:MStat,
:EdLev,
:HCap
);
end loading;
logoff;
Thanks
Pramod.
Find A Job or Post a Job Opening Click Here.
cici (MIS) 3 Jun
03
19:19
Try to use
SET RECORD VARTEXT;
instead of UNFORMATTED
mpramods (TechnicalUser) 4 Jun
03
10:39
Hi cici,
I used SET FORMAT VARTEXT instead of unformatted and got the following error. The target
table is still empty.
Is is possible that somebody would try to run my fastload script and let me know how to solve
the problem. I have the script and input flat file listed above.
define
dummy(varchar(1)),
EmpNo(varchar(9)),
Name(varchar(12)),
DeptNo(varchar(3)),
PhoneNo(varchar(4)),
JobTitle(varchar(12)),
Salary(varchar(9)),
YrsExp(varchar(2)),
DOB(varchar(11)),
Sex(varchar(1)),
Race(varchar(1)),
MStat(varchar(1)),
EdLev(varchar(2)),
HCap(varchar(2))
That's it ;-)
Dieter
mpramods (TechnicalUser) 5 Jun
03
11:53
Hi Dieter,
I made changes in the script as per your suggestions. But still I am getting the following error.
Are there any other changes that need to be made. Your help is appreciated.
Thanks,
mpramods
dnoeth (Instructor) 5 Jun
03
12:10
The last record in your input file is producing that error, but if you use .SET RECORD VARTEXT
it's usually a different one "Not enough fields..."
Dieter
mpramods (TechnicalUser) 5 Jun
03
12:44
Thanks for the fast reply Dieter,
Here is my script and input file.
sessions 2;
errlimit 25;
logon dbc/dbc,dbc;
DATABASE pramod;
CREATE TABLE employee (
EmpNo SMALLINT FORMAT '9(5)' BETWEEN 10001 AND 32001 NOT NULL,
Name VARCHAR (12),
DeptNo SMALLINT FORMAT '999' BETWEEN 100 AND 900,
PhoneNo SMALLINT FORMAT '9999' BETWEEN 1000 AND 9999,
JobTitle VARCHAR(12),
Salary DECIMAL(8,2) FORMAT 'ZZZ,ZZ9.99' BETWEEN 1.00 AND 999000.00,
YrsExp BYTEINT FORMAT 'Z9' BETWEEN -99 AND 99,
DOB DATE FORMAT 'MMMbDDbYYYY',
Sex CHAR(1) UPPERCASE,
Race CHAR(1) UPPERCASE,
MStat CHAR(1) UPPERCASE,
EdLev BYTEINT FORMAT 'Z9' BETWEEN 0 AND 22,
HCap BYTEINT FORMAT 'Z9' BETWEEN -99 AND 99 )
UNIQUE PRIMARY INDEX( EmpNo );
define
dummy(varchar(1)),
EmpNo(varchar(9)),
Name(varchar(12)),
DeptNo(varchar(3)),
PhoneNo(varchar(4)),
JobTitle(varchar(12)),
Salary(varchar(9)),
YrsExp(varchar(2)),
DOB(varchar(11)),
Sex(varchar(1)),
Race(varchar(1)),
MStat(varchar(1)),
EdLev(varchar(2)),
HCap(varchar(2))
file=C:\insert.input.txt;
show;
If it's still not working, then i can't help you anymore ;-(
Dieter
mpramods (TechnicalUser) 5 Jun
03
20:12
Hi,
I am still not able to run the script. If anybody could help me with this, the help would be
appreciated.
Thanks
mpramods