public function testFuncDataCall1()
 {
     echo "testFuncDataCall1\n";
     try {
         $conn = new sapnwrfc($this->config);
         $attr = $conn->connection_attributes();
         var_dump($attr);
         // we must have a valid connection
         $this->assertNotNull($conn);
         $func = $conn->function_lookup("Z_TEST_DATA");
         $this->assertEquals($func->name, "Z_TEST_DATA");
         $parms = array('CHAR' => "German: öäüÖÄÜß", 'INT1' => 123, 'INT2' => 1234, 'INT4' => 123456, 'FLOAT' => 123456.0, 'NUMC' => "12345", 'DATE' => "20060709", 'TIME' => "200607", 'BCD' => '200607.123', 'ISTRUCT' => array('ZCHAR' => "German: öäüÖÄÜß", 'ZINT1' => 54, 'ZINT2' => 134, 'ZIT4' => 123456, 'ZFLT' => 123456.0, 'ZNUMC' => '12345', 'ZDATE' => '20060709', 'ZTIME' => '200607', 'ZBCD' => '200607.123'), 'DATA' => array(array('ZCHAR' => "German: öäüÖÄÜß", 'ZINT1' => 54, 'ZINT2' => 134, 'ZIT4' => 123456, 'ZFLT' => 123456.0, 'ZNUMC' => '12345', 'ZDATE' => '20060709', 'ZTIME' => '200607', 'ZBCD' => '200607.123'), array('ZCHAR' => "Slovenian: čćšČĆŠ", 'ZINT1' => 54, 'ZINT2' => 134, 'ZIT4' => 123456, 'ZFLT' => 123456.0, 'ZNUMC' => '12345', 'ZDATE' => '20060709', 'ZTIME' => '200607', 'ZBCD' => '200607.123')));
         $results = $func->invoke($parms);
         var_dump($results);
         $this->assertEquals(trim($results['ECHAR']), $parms['CHAR']);
         $this->assertEquals($results['EINT1'], $parms['INT1']);
         $this->assertEquals($results['EINT2'], $parms['INT2']);
         $this->assertEquals($results['EINT4'], $parms['INT4']);
         $this->assertEquals($results['EFLOAT'], $parms['FLOAT']);
         $this->assertEquals($results['ENUMC'], $parms['NUMC']);
         $this->assertEquals($results['EDATE'], $parms['DATE']);
         $this->assertEquals($results['ETIME'], $parms['TIME']);
         $this->assertEquals($results['EBCD'], $parms['BCD']);
         $this->assertEquals(chop($results['DATA'][0]['ZCHAR']), $parms['DATA'][0]['ZCHAR']);
         $this->assertEquals(chop($results['DATA'][1]['ZCHAR']), $parms['DATA'][1]['ZCHAR']);
         sleep(10);
         sapnwrfc_removefunction($attr['sysId'], 'Z_TEST_DATA');
         $func = $conn->function_lookup("Z_TEST_DATA");
         $parms = array('ICHAR' => "German: öäüÖÄÜß", 'INT1' => 123, 'INT2' => 1234, 'INT4' => 123456, 'FLOAT' => 123456.0, 'NUMC' => "12345", 'DATE' => "20060709", 'TIME' => "200607", 'BCD' => '200607.123', 'ISTRUCT' => array('ZCHAR' => "German: öäüÖÄÜß", 'ZINT1' => 54, 'ZINT2' => 134, 'ZIT4' => 123456, 'ZFLT' => 123456.0, 'ZNUMC' => '12345', 'ZDATE' => '20060709', 'ZTIME' => '200607', 'ZBCD' => '200607.123'), 'DATA' => array(array('ZCHAR' => "German: öäüÖÄÜß", 'ZINT1' => 54, 'ZINT2' => 134, 'ZIT4' => 123456, 'ZFLT' => 123456.0, 'ZNUMC' => '12345', 'ZDATE' => '20060709', 'ZTIME' => '200607', 'ZBCD' => '200607.123'), array('ZCHAR' => "Slovenian: čćšČĆŠ", 'ZINT1' => 54, 'ZINT2' => 134, 'ZIT4' => 123456, 'ZFLT' => 123456.0, 'ZNUMC' => '12345', 'ZDATE' => '20060709', 'ZTIME' => '200607', 'ZBCD' => '200607.123')));
         $results = $func->invoke($parms);
         var_dump($results);
         $this->assertEquals(trim($results['ECHAR']), $parms['CHAR']);
         $this->assertEquals($results['EINT1'], $parms['INT1']);
         $this->assertEquals($results['EINT2'], $parms['INT2']);
         $this->assertEquals($results['EINT4'], $parms['INT4']);
         $this->assertEquals($results['EFLOAT'], $parms['FLOAT']);
         $this->assertEquals($results['ENUMC'], $parms['NUMC']);
         $this->assertEquals($results['EDATE'], $parms['DATE']);
         $this->assertEquals($results['ETIME'], $parms['TIME']);
         $this->assertEquals($results['EBCD'], $parms['BCD']);
         $this->assertEquals(chop($results['DATA'][0]['ZCHAR']), $parms['DATA'][0]['ZCHAR']);
         $this->assertEquals(chop($results['DATA'][1]['ZCHAR']), $parms['DATA'][1]['ZCHAR']);
         $this->assertEquals($conn->close(), true);
     } catch (Exception $e) {
         echo "Exception message: " . $e->getMessage();
         throw new Exception('Assertion failed.');
     }
 }
 public function testReadTable()
 {
     try {
         $conn = new sapnwrfc($this->config);
         $h = $conn->function_lookup('RFC_GET_TABLE_ENTRIES');
         $parms = array('BYPASS_BUFFER' => 'X', 'MAX_ENTRIES' => 1, 'TABLE_NAME' => 'T005ZR');
         $h->invoke($parms);
     } catch (sapnwrfcCallException $e) {
         //echo "Exception type: ".$e."\n";
         echo "Exception key: " . $e->key . "\n";
         echo "Exception code: " . $e->code . "\n";
         echo "Exception message: " . $e->getMessage() . "\n";
         $this->assertTrue(true);
     } catch (Exception $e) {
         echo "Exception type: " . $e . "\n";
         echo "Exception key: " . $e->key . "\n";
         echo "Exception code: " . $e->code . "\n";
         echo "Exception message: " . $e->getMessage() . "\n";
         throw new Exception('Connection failed.');
     }
     echo "I am a happy piece of code that carried on....\n";
 }
Example #3
0
 public function testConnectionCert()
 {
     try {
         $conn = new sapnwrfc($this->config);
         $ticket = $conn->get_sso_ticket();
         echo "ticket: {$ticket} \n";
     } catch (Exception $e) {
         echo "Exception type: " . $e . "\n";
         echo "Exception key: " . $e->key . "\n";
         echo "Exception code: " . $e->code . "\n";
         echo "Exception message: " . $e->getMessage();
         throw new Exception('Connection failed.');
     }
 }
<?php

/**
 * Get some system informations
 */
if (!extension_loaded('sapnwrfc')) {
    throw new \Exception('Extension "sapnwrfc" not loaded. Please see https://github.com/piersharding/php-sapnwrfc#installation');
}
// @see the available connection paraemters here
// http://help.sap.com/saphelp_nwpi711/helpdata/en/48/c7bb09da5e31ebe10000000a42189b/content.htm
$config = ['MSHOST' => '...', 'CLIENT' => '...', 'R3NAME' => '...', 'GROUP' => '...', 'CODEPAGE' => '...', 'LANG' => 'en', 'LCHECK' => true, 'TRACE' => true, 'user' => '...', 'passwd' => '...'];
$conn = new sapnwrfc($config);
$func = $conn->function_lookup('RFC_SYSTEM_INFO');
$result = $func->invoke([]);
// is an empty array
if (is_array($result)) {
    var_dump($result);
} else {
    echo 'Could not ping the SAP system';
}
$conn->close();
Example #5
0
<?php

/**
 * Ping the SAP system
 */
if (!extension_loaded('sapnwrfc')) {
    throw new \Exception('Extension "sapnwrfc" not loaded. Please see https://github.com/piersharding/php-sapnwrfc#installation');
}
// @see the available connection paraemters here
// http://help.sap.com/saphelp_nwpi711/helpdata/en/48/c7bb09da5e31ebe10000000a42189b/content.htm
$config = ['MSHOST' => '...', 'CLIENT' => '...', 'R3NAME' => '...', 'GROUP' => '...', 'CODEPAGE' => '...', 'LANG' => 'en', 'LCHECK' => true, 'TRACE' => true, 'user' => '...', 'passwd' => '...'];
$conn = new sapnwrfc($config);
if ($conn->ping() === true) {
    echo 'Successfully pinged the SAP system';
} else {
    echo 'Could not ping the SAP system';
}
$conn->close();
<?php

/**
 * Alternative ping the SAP system
 */
if (!extension_loaded('sapnwrfc')) {
    throw new \Exception('Extension "sapnwrfc" not loaded. Please see https://github.com/piersharding/php-sapnwrfc#installation');
}
// @see the available connection paraemters here
// http://help.sap.com/saphelp_nwpi711/helpdata/en/48/c7bb09da5e31ebe10000000a42189b/content.htm
$config = ['MSHOST' => '...', 'CLIENT' => '...', 'R3NAME' => '...', 'GROUP' => '...', 'CODEPAGE' => '...', 'LANG' => 'en', 'LCHECK' => true, 'TRACE' => true, 'user' => '...', 'passwd' => '...'];
// change the directory for logging
$cwd = getcwd();
chdir('my/log/dir');
try {
    $conn = new sapnwrfc($config);
} catch (Exception $ex) {
    throw $ex;
} finally {
    // change the cwd always back to the previous value
    chdir($cwd);
}
$func = $conn->function_lookup('RFC_PING');
$result = $func->invoke([]);
// is an empty array
if (is_array($result)) {
    echo 'Successfully pinged the SAP system';
} else {
    echo 'Could not ping the SAP system';
}
$conn->close();
<?php

/**
 * Call a RFC function
 */
if (!extension_loaded('sapnwrfc')) {
    throw new \Exception('Extension "sapnwrfc" not loaded. Please see https://github.com/piersharding/php-sapnwrfc#installation');
}
// @see the available connection paraemters here
// http://help.sap.com/saphelp_nwpi711/helpdata/en/48/c7bb09da5e31ebe10000000a42189b/content.htm
$config = ['MSHOST' => '...', 'CLIENT' => '...', 'R3NAME' => '...', 'GROUP' => '...', 'CODEPAGE' => '...', 'LANG' => 'en', 'LCHECK' => true, 'TRACE' => true, 'user' => '...', 'passwd' => '...'];
$conn = new sapnwrfc($config);
$fds = $conn->function_lookup('STFC_DEEP_STRUCTURE');
$fdt = $conn->function_lookup('STFC_DEEP_TABLE');
$parms = ['IMPORTSTRUCT' => ['I' => 123, 'C' => 'AbCdEf', 'STR' => 'The quick brown fox ...']];
$results = $fds->invoke($parms);
var_dump($results);
$parms = ['IMPORT_TAB' => [['I' => 123, 'C' => 'AbCdEf', 'STR' => 'The quick brown fox ...']]];
$results = $fdt->invoke($parms);
var_dump($results);
$conn->close();