Perl: Example No. 5 

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.

Set up a user session
Log on to the database instance
Use
REPMServer command(s) to load data into table 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 SAP DB Perl Library

# -------------------------------

use SAP::DBTECH::repman;

 

# Parse the call arguments

# --------------------------

$user = $ARGV[0];

$pwd = $ARGV[1];

$dbname = $ARGV[2];

$data_path = $ARGV[3];

$host = "localhost";

 

# Start a user session with the REPMServer

# -------------------------------------------

$session = repman::RepMan ($host, $dbname);

 

# Log on to the database instance

# --------------------------------

$session->cmd("use user $user $pwd;");

 

# Example of exception handling

# --------------------------------------------------

eval{

$loadrc=$session->sql ("DATALOAD TABLE customer ".

                        "cno       1-4".

                        "surname  6-12".

                        "zip       14-18".

                        "place       20-31".

"INFILE $data_path\customer.dat" );

print "$loadrc\n";}

if ($@){

print "command failed: $@\n";

}

 

# End the database session

# ----------------------------

undef $session