To create a connection, enter the corresponding arguments from the following examples on the command line.
Use the following command to call the sample.pl Perl script and log on to the DEMODB database as DBM operator OLEG with password MONDAY.
perl sample.pl OLEG MONDAY DEMODB
Syntax
# To reference Perl libraries: # ------------------------------ use SAP::DBTech::dbm; # Parse the call arguments # -------------------------- my $user_name = $ARGV [0]; my $password = $ARGV [1]; my $database_name = $ARGV [2]; # To create a DBM session: # --------------------------------------- my $session = new DBM ('', $database_name, '', "$user_name,$password"); # To log off: # ------------------------------------- $session->release ();
The following examples show a shortened login process:
Syntax
session = sapdb.dbm.DBM ("", $ARGV [2], $ARGV [0] . "," . $ARGV [1])
You can use the cmd method to execute DBM commands. The result is a character string that can be further processed using Perl.
Syntax
# To reference Perl libraries: # ------------------------------ use SAP::DBTech::dbm; # To create a DBM session: # ------------------------------------------------------ my $session = new DBM ('', $ARGV [2], '', $ARGV [0] . ',' . $ARGV [1]); # To execute the DBM command that lists all database # s. The result is a character string. output = session.cmd ('db_enum') my $dbstate = 'offline'; my $lastdb = ''; # Individual databases are separated by line breaks. foreach my $line (split /\n/, $output){ # Data fields are separated by tab characters. my ($name, $instroot, $release, $kind, $state) = split /\t/, $line; if ($name ne $lastdb) { # Several lines exist for each database, # max. one line for each of the following kernel variants: # fast and slow. if ($lastdb ne '') { print "$lastdb\t$dbstate\n"; } $lastdb = $name; $dbstate = 'offline'; } # The database is active if one of the core variants # is displayed as 'running'. if ($state eq 'running') { $dbstate = $state; } } print "$lastdb\t$dbstate\n"; $session->release ();
If an error occurs within a cmd method, an exception is generated. You can intercept this exception with eval and query it with the $@ system variable.
Syntax
# To reference Perl libraries: # ------------------------------ use SAP::DBTech::dbm; # To create a DBM session: # ----------------------------------------- my $session = new DBM ('', $ARGV [2], '', $ARGV [0] . ',' . $ARGV [1]); foreach my $cmd (('db_state', 'invalid command')) { eval { my $result = $session->cmd ($cmd); # To output the result: print "$cmd: OK $result\n"; }; if ($@) { # To output the error message: print "$CMD: ERR $@\n"; } } $session->release ();