Exemplo n.º 1
0
 /**
  * Retrieves the last error from the SAP connection
  * and returns it as an array.
  *
  * @return array Array of error information
  */
 function getError()
 {
     $error = array();
     $sap_error = saprfc_error();
     if (empty($err)) {
         return $error;
     }
     $err = explode("n", $sap_error);
     foreach ($err as $line) {
         $item = split(':', $line);
         $error[strtolower(trim($item[0]))] = trim($item[1]);
     }
     $error['all'] = $sap_error;
     return $error;
 }
Exemplo n.º 2
0
 /**
  * Check if RFC connection is valid
  *
  * @return SAPRFC_OK on success, <> SAPRFC_OK on failure
  */
 function IsConnectionLive()
 {
     if ($this->rfc == false) {
         return $this->SetStatus(SAPRFC_ERROR, "SAPConnection::IsConnectionLive: No valid RFC handle");
     }
     $fce = @saprfc_function_discover($this->rfc, "RFC_PING");
     if ($fce == false) {
         return $this->SetStatus(SAPRFC_ERROR, @saprfc_error());
     }
     $rc = @saprfc_call_and_receive($fce);
     @saprfc_function_free($fce);
     if ($rc == SAPRFC_OK) {
         return $this->SetStatus(SAPRFC_OK, "");
     } else {
         return $this->SetStatus(SAPRFC_ERROR, @saprfc_error());
     }
 }
Exemplo n.º 3
0
function rfc_error($operation)
{
  global $trace_fp, $rfc_handle;

  $tbuf = "\n<==  RfcLastErrorEx\n";

  $tbud .= sprintf("\nRFC Call/Exception: %s\n", $operation);
  TRFC_trace($tbuf);

  $tbuf = saprfc_error();
  TRFC_trace($tbuf);

  $tbuf = "\n<==  RfcClose\n";
  TRFC_trace($tbuf);

  saprfc_close ($rfc_handle);

  if ($trace_fp != false)
    fclose($trace_fp);

  exit;
}
Exemplo n.º 4
0
 function bapiCommit($bapiName)
 {
     global $rfc, $fce;
     $fce = saprfc_function_discover($rfc, $bapiName);
     if (!$fce) {
         echo "Discovering interface of function module failed";
         exit;
     }
     $rfc_rc = saprfc_call_and_receive($fce);
     // var_dump($rfc_rc);
     if ($rfc_rc != SAPRFC_OK) {
         if ($rfc == SAPRFC_EXCEPTION) {
             echo "Exception raised: " . saprfc_exception($fce);
         } else {
             echo saprfc_error($fce);
         }
         exit;
     }
 }
Exemplo n.º 5
0
 /**
  * Call function module indirectly, TRFC
  *
  * @param [tid]            Transaction ID
  *
  * @return SAPRFC_OK on success
  */
 function IndirectCall($tid)
 {
     if ($this->fce == false) {
         return $this->SetStatus(SAPRFC_ERROR, "SAPFunction::IndirectCall: Function is " . "not defined.");
     }
     $this->ExportVars();
     $rc = @saprfc_trfc_call($this->fce, $tid);
     $this->exception = "";
     return $this->SetStatus($rc, @saprfc_error());
 }
Exemplo n.º 6
0
 public function call()
 {
     $r = saprfc_call_and_receive($this->func);
     if ($r != SAPRFC_OK) {
         throw new Exception($r == SAPRFC_EXCEPTION ? saprfc_exception($this->func) : saprfc_error($this->func));
     }
 }
Exemplo n.º 7
0
	function callFunction($func_name="",$parameters) {
		/* typical call:
			$result=$saprfc->call_function("RFC_SYSTEM_INFO",
									array(	array("EXPORT","SYSTEM","MBS")
											array("IMPORT","CODEPAGE")
											array("IMPORT","DBNAME")
											array("TABLE","APPLLIST",array())
									)
								);
		*/
		
		// Initialize Variables
		$result_data=array();
		$this->call_function_result=false;
						
		// Check SAPRFC-Installation
		if (! extension_loaded ("saprfc")) {
			return $this->setStatus(SAPRFC_ERROR,"saprfc::callFunction()\n SAPRFC-Extension.dll not loaded.");
		}
		
		// Validate given data
		if (empty($func_name)) {
			return $this->setStatus(SAPRFC_ERROR,"saprfc::callFunction():\n No Function-Name given");
		}
		
		// Move Parameters to local Arrays
		$func_params_import=array();		
		$func_params_tables=array();
		$func_params_export=array();
		foreach ($parameters as $key => $param) {
			$type=$param[0];
			$name=$param[1];
			$value=isset($param[2])?$param[2]:"";
			switch ($type) {
				case "IMPORT":
					$func_params_import[$name]=$value;
					break;
				case "EXPORT":
					$func_params_export[$name]="";
					break;
				case "TABLE":
					$func_params_tables[$name]=$value;
					if (!is_array($value)) {
						return $this->setStatus(SAPRFC_ERROR,"saprfc::callFunction()\n Wrong Parameter-Value for Table-Parameter ".$name.". We expected an Array.");
					}
					break;
				default:
					return $this->setStatus(SAPRFC_ERROR,"saprfc::callFunction()\n Wrong Parameter-Type '".$type."'. Must be IMPORT, EXPORT or TABLE.");
			}
		}
		
		// Do Login (only done in method login(), if necessary)	
		if ($this->login()==SAPRFC_ERROR) {
			return $this->getStatus();
		}
		
		// Discover Function in SAP
		$this->func_id=@saprfc_function_discover($this->rfc_conn,$func_name);
		if (!$this->func_id) {
			return $this->setStatus(SAPRFC_ERROR,"saprfc::callFunction()\n Function module '".$func_name."' seems not to exist. function saprfc_function_discover() failed.");
		}

		// Set Import-Parameters		
		foreach ($func_params_import as $name => $value) {
			$rc=@saprfc_import($this->func_id,$name,$value);
			if (empty($rc)) {
				return $this->setStatus(SAPRFC_ERROR,"saprfc::callFunction('".$func_name."')\n Import-Parameter=".$name. " could not be set. (Does it exist?)");
			}
		}
		// Set Table-Parameters	(importing-values)
		foreach ($func_params_tables as $name => $value) {
			$rc=@saprfc_table_init($this->func_id,$name);
			if (empty($rc)) {
				return $this->setStatus(SAPRFC_ERROR,"saprfc::callFunction('".$func_name."')\n Table-Parameter=".$name. " could not be set. (Does it exist?)");
			}
			foreach ($value as $key => $data) {
				@saprfc_table_append($this->func_id,$name,$data);
			}
		}

		// Execute Function
		$result = @saprfc_call_and_receive ($this->func_id);
		if ($result != SAPRFC_OK)
		{
			if ($result == SAPRFC_EXCEPTION ) {
				return $this->setStatus(SAPRFC_ERROR,"saprfc::callFunction('".$func_name."')\n saprfc_call_and_receive(): Exception raised: ".@saprfc_exception($this->func_id));
			} else {
				return $this->setStatus(SAPRFC_ERROR,"saprfc::callFunction('".$func_name."')\n saprfc_call_and_receive(): Call error: ".@saprfc_error($this->func_id));
			}
		}
	   
		// Get Exporting-Parameters
		foreach ($func_params_export as $name =>$value) {
			$rc=@saprfc_export($this->func_id,$name);
//			if (empty($rc)) { // llaegner removed (Reason: when export returns the -good- value "0", then empty also evaluates to true (thanks Alexander Gouriev)
			if (!isset($rc)) {
				return $this->setStatus(SAPRFC_ERROR,"saprfc::callFunction('".$func_name."')\n Export-Parameter=".$name. " could not be set (Does it exist?)".@saprfc_error($this->func_id));
			} else {
				$result_data[$name]=$rc;
			}
		}

		// Get Table-Parameters
		foreach ($func_params_tables as $name => $content) {
			// Ausgabe-Tabelle initialisieren
			$result_data[$name]=array(); 
			$rows=@saprfc_table_rows($this->func_id,$name);
			for ($i=1; $i<=$rows; $i++)
			{
				$result_data[$name][$i]=@saprfc_table_read ($this->func_id,$name,$i);
			}
		}

		// Save function-call result for later analysis
		$this->call_function_result=$result_data;
		
		// Echo Debug-Information, if flagged
		if ($this->debug)
			@saprfc_function_debug_info($this->func_id);
			
		// Falls es ein BAPI-Aufruf ist, Fehler raussuchen
		if ($this->check_bapi_errors) {
			$bapi_return=@saprfc_export($this->func_id,"RETURN");
			if (isset($bapi_return) && 
					is_array($bapi_return) && 
					isset($bapi_return["MESSAGE"]) && 
					$bapi_return["NUMBER"] != 0) {
					
				// FINISH FUNCTION-CALL
				$this->setStatus(SAPRFC_APPL_ERROR,$bapi_return);
				return $result_data;	
			}
		}
		// Close Function-Execution and free results removed because it sometimes stops completly executing PHP!!
		//@saprfc_function_free($this->func_id);
		
		// FINISH FUNCTION-CALL
		$this->setStatus(SAPRFC_OK,"call function '".$func_name."' successfull.");
		return $result_data;	
	}
Exemplo n.º 8
0
   if (! $fce )
   {
       echo "Discovering interface of function module RFC_READ_REPORT failed";
       exit;
   }

   saprfc_import ($fce,"PROGRAM",$REPORT);
   saprfc_table_init ($fce,"QTAB");

   $rc = saprfc_call_and_receive ($fce);
   if ($rfc_rc != SAPRFC_OK)
   {
       if ($rfc == SAPRFC_EXCEPTION )
           echo ("Exception raised: ".saprfc_exception($fce));
       else
           echo ("Call error: ".saprfc_error($fce));
       exit;
   }
   
   $SYSTEM = saprfc_export ($fce,"SYSTEM");
   $TRDIR = saprfc_export ($fce,"TRDIR");
   $rows = saprfc_table_rows ($fce,"QTAB");
   echo "<PRE>";
   for ($i=1; $i<=$rows; $i++)
   {
	 $QTAB = saprfc_table_read ($fce,"QTAB",$i);
     echo ($QTAB[LINE]."\n");
   }
   echo "</PRE>";
   saprfc_function_free($fce);
   saprfc_close($rfc);
Exemplo n.º 9
0
 /**
  * @throws Exception
  * @author Manuel Will
  * @since 2013
  */
 private function checkStatusCode($receivedData, $moduleConnection)
 {
     if ($receivedData !== SAPRFC_OK) {
         if ($this->getConnectionResource() == SAPRFC_EXCEPTION) {
             $errorMessage = saprfc_exception($moduleConnection);
         } else {
             $errorMessage = saprfc_error();
         }
         if (!empty($errorMessage)) {
             throw new SAP_Exception($errorMessage);
         }
     }
 }
Exemplo n.º 10
0
            $var="RFC_TABLE_".$interface["name"];
            $vararray = unserialize (urldecode($$var));
            if (is_array($vararray))
            {
               for ($j=0;$j<count($vararray);$j++)
                    saprfc_table_append ($fce,$interface["name"],$vararray[$j]);
            }
         }
      }
      // rfc call function in connected R/3
      $retval = @saprfc_call_and_receive ($fce);
      if ( $retval != SAPRFC_OK  )
      {
        print_error_message ( "Call error",
                              "Calling of function module $function failed. See the error message below.<a href=\"saprfc_test.php?p=select\">Other function module</a>",
                              saprfc_error()
                            );
        exit;
      }

      print_header ("Results of function module $function");

      $form = "<table colspacing=0 colpadding=0>\n";
      $form .= "<tr bgcolor=#D0D0D0><td colspan=2><b>EXPORT PARAMETERS</b></td></tr>\n";
      for ($i=0;$i<count($def);$i++)
      {
         $interface = $def[$i];
         if ($interface["type"] == "EXPORT")  // show export parameters
         {
            $var = saprfc_export ($fce,$interface["name"]);
            $form .= show_parameter_out ($interface["name"],$interface["def"],$var);
Exemplo n.º 11
-1
 public function open()
 {
     $rfc = saprfc_open($sap_config);
     if (!$rfc) {
         echo 'An error occured: <pre>';
         print_r(saprfc_error());
         exit;
     }
     return $rfc;
 }
Exemplo n.º 12
-2
 /**
  * @param $config
  * @throws Exception
  */
 function __construct($config)
 {
     if (!function_exists('saprfc_open')) {
         throw new Exception('no saprfc extension');
     }
     $this->connection = saprfc_open($config);
     if (!$this->connection) {
         throw new Exception($this->decodeString(saprfc_error()));
     }
     $this->errors = array(SAPRFC_FAILURE => 'Error occurred', SAPRFC_EXCEPTION => 'Exception raised', SAPRFC_SYS_EXCEPTION => 'System exception raised, connection closed', SAPRFC_CALL => 'Call received', SAPRFC_INTERNAL_COM => 'Internal communication, repeat (internal use only)', SAPRFC_CLOSED => 'Connection closed by the other side', SAPRFC_RETRY => 'No data yet', SAPRFC_NO_TID => 'No Transaction ID available', SAPRFC_EXECUTED => 'Function already executed', SAPRFC_SYNCHRONIZE => 'Synchronous Call in Progress', SAPRFC_MEMORY_INSUFFICIENT => 'Memory insufficient', SAPRFC_VERSION_MISMATCH => 'Version mismatch', SAPRFC_NOT_FOUND => 'Function not found (internal use only)', SAPRFC_CALL_NOT_SUPPORTED => 'This call is not supported', SAPRFC_NOT_OWNER => 'Caller does not own the specified handle', SAPRFC_NOT_INITIALIZED => 'RFC not yet initialized.', SAPRFC_SYSTEM_CALLED => 'A system call such as RFC_PING for connectiontest is executed', SAPRFC_INVALID_HANDLE => 'An invalid handle was passed to an API call.', SAPRFC_INVALID_PARAMETER => 'An invalid parameter was passed to an API call.', SAPRFC_CANCELED => 'Internal use only');
 }