Example of Calling the Loader with Perl Script
If a command is changed at runtime, for example,
because user inputs are part of the command, syntax errors can easily
occur.
The SQL method only provides SQL error codes. You need exceptions to intercept
syntax errors in the DATALOAD command.
Start
a database session
Log on to the database instance
Load data to the table using Loader commands and
intercept exceptions
Log off
An incorrect data path in the following example can lead to a syntax error or data access error.
# Reference to the Perl Library
# -------------------------------
use SAP::DBTECH::loader;
# Parse the call arguments
# --------------------------
$user_name = $ARGV[0];
$password = $ARGV[1];
$database_name = $ARGV[2];
$data_path = $ARGV[3];
$server_node = "localhost";
# Create a database session for the Loader
# -------------------------------------------
$session = loader::Loader ($server_node, $database_name);
# Log on to the database instance
# --------------------------------
$session->cmd("use user $user_name $password;");
# Example of Exception Handling
# -----------------------------
eval{
$loadrc=$session->sql ("DATALOAD TABLE customer
".
"cno 1-4 ".
"name 6-12 ".
"zip 14-18 ".
"city 20-31 ".
"INFILE
$data_path\customer.dat" );
print "$loadrc\n";}
if ($@){
print "command failed: $@\n";
}
# End the database session
# ----------------------------
undef $session