Example #1
0
 function getTable($fieldName)
 {
     global $rfc, $fce;
     $SalesOrder = "";
     $rowsag = saprfc_table_rows($fce, $fieldName);
     for ($i = 1; $i <= $rowsag; $i++) {
         $SalesOrder[] = saprfc_table_read($fce, $fieldName, $i);
         //var_dump($SalesOrder);
     }
     return $SalesOrder;
 }
Example #2
0
function write_itab_to_file($fce, $data_file, $itab_name)
{
  /* Open data_file */
  $fp = fopen($data_file, "a");
  if ($fp == false)
    return 1;

  $it_fill = saprfc_table_rows ($fce,$itab_name);
  $tbuf = sprintf("Table Name=%s\nTable Line=%u\nTable Fill=%u\n",
	  $itab_name, 0, $it_fill);
   
  if ( fwrite($fp,$tbuf,strlen($tbuf)) < strlen($tbuf) )
    function_abort("Cannot write data in received file");

  for ($k = 1; $k<=$it_fill ; $k++)
  {
    $ptr = saprfc_table_read ($fce,$itab_name,$k);

    $tbuf = $ptr[LINE]."\n";
    fwrite($fp, $tbuf);
  }

  /* Close data_file */
  fclose($fp);

  return 0;
}
Example #3
0
 public function get($n)
 {
     $j = array();
     $r = saprfc_table_rows($this->func, $n);
     for ($i = 1; $i <= $r; $i++) {
         array_push($j, saprfc_table_read($this->func, $n, $i));
     }
     return $j;
 }
Example #4
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;	
	}
Example #5
0
 /**
  * @param string $name
  * @param array $request
  * @param array $responseKeys
  * @throws Exception
  * @return object
  */
 public function execute($name, $request, $responseKeys)
 {
     $start = microtime(1);
     $fce = saprfc_function_discover($this->connection, $name);
     if (!$fce) {
         throw new Exception("Error discovering " . $name, 1);
     }
     foreach ($request as $k => $v) {
         if (is_array($v)) {
             foreach ($v as $index => $row) {
                 if (is_object($row)) {
                     $row = get_object_vars($row);
                 }
                 foreach ($row as $row_key => $row_value) {
                     $row[$row_key] = $this->encodeString($row_value);
                 }
                 saprfc_table_insert($fce, $k, $row, $index + 1);
             }
         } else {
             saprfc_request($fce, $k, $this->encodeString($v));
         }
     }
     $result = saprfc_call_and_receive($fce);
     if ($result != SAPRFC_OK) {
         $message = isset($this->errors[$result]) ? $this->errors[$result] : 'Unknown error';
         if ($this->profiler) {
             $this->profiler->register((object) array('name' => $name, 'request' => $request, 'success' => false, 'message' => $message, 'time' => microtime(1) - $start));
         }
         throw new Exception($message);
     }
     $response = array();
     foreach ($responseKeys as $table) {
         $count = saprfc_table_rows($fce, $table);
         if ($count == -1) {
             // responseKeys param
             $data = $this->decodeString(saprfc_export($fce, $table));
         } else {
             // responseKeys table
             $data = array();
             for ($i = 1; $i <= $count; $i++) {
                 $row = saprfc_table_read($fce, $table, $i);
                 foreach ($row as $k => $v) {
                     $row[$k] = $this->decodeString($v);
                 }
                 $data[] = (object) $row;
             }
         }
         $response[$table] = $data;
     }
     if ($this->profiler) {
         $this->profiler->register((object) array('name' => $name, 'request' => (object) $request, 'response' => (object) $response, 'success' => true, 'time' => microtime(1) - $start));
     }
     return (object) $response;
 }
Example #6
0
    $Receive->getResult();
    $ResponseExport = new ResponseExport();
    $r['ORDERK'] = $ResponseExport->export('ORDERK');
    $rowsag = saprfc_table_rows($fce, 'TTEXT');
    for ($i = 1; $i <= $rowsag; $i++) {
        $r['TTEXT'][] = saprfc_table_read($fce, 'TTEXT', $i);
    }
    $rowsag = saprfc_table_rows($fce, 'TORDERP');
    for ($i = 1; $i <= $rowsag; $i++) {
        $r['TORDERP'][] = saprfc_table_read($fce, 'TORDERP', $i);
    }
    $rowsag = saprfc_table_rows($fce, 'TSHIPMENTK');
    for ($i = 1; $i <= $rowsag; $i++) {
        $r['TSHIPMENTK'][] = saprfc_table_read($fce, 'TSHIPMENTK', $i);
    }
    $rowsag = saprfc_table_rows($fce, 'TSHIPMENTP');
    for ($i = 1; $i <= $rowsag; $i++) {
        $r['TSHIPMENTP'][] = saprfc_table_read($fce, 'TSHIPMENTP', $i);
    }
} catch (Exception $e) {
    echo $msg = 'Message:- ' . $e->getMessage();
    exit;
}
$_SESSION['test_data'] = $r;
if ($action != 'SHIPMENT') {
    echo json_encode($r) . '$@$' . $options[$r['ORDERK']['STATUS']];
} else {
    echo json_encode($r);
}
//$_SESSION['order_details']=$r;
//echo $json_de=json_encode($r);
Example #7
0
       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);
?>

Example #8
0
 /**
  * @param SAP_Module_Abstract $module
  *
  * @throws Exception
  * @return array
  * @author Manuel Will
  * @since 2013
  */
 public function executeSave(SAP_Module_Abstract $module)
 {
     $this->storeDebugTraceToStatic();
     $moduleName = $module->getModuleName();
     $moduleResource = $this->getModuleResource($moduleName);
     $receivedData = @saprfc_call_and_receive($moduleResource);
     $this->checkStatusCode($receivedData, $moduleResource);
     /**
      * Ein Commit kann trotzdem stattfinden, obwohl ein Resultat zurückkommt.
      * Ein Rollback braucht es eigentlich nur beim Fehler, der wirklich ein Fehler ist. Der Fehler würde dann aber schon
      * in $this->checkStatusCode eine Exception werfen. Möglicherweise erübrigt sich ein Rollback eigentlich immer. Hier sollte wohl immer
      * Array zurückkommen weshalb das nur mit if ($var) geprüft wurde. Bei manchen Bausteinen kommt es wohl vor, dass auch -1 zurück kommen kann.
      * Das heißt, es kommt ein "Fehlerresult" zurück, aber nicht als Array sondern als "-1". Das ist offensichtlich kein Fehler.
      */
     $mxdResult = saprfc_table_rows($moduleResource, 'RETURN');
     if ($mxdResult && $mxdResult != -1) {
         $moduleResource2 = saprfc_function_discover($this->getConnectionResource(), 'BAPI_TRANSACTION_ROLLBACK');
         $errorCode = saprfc_call_and_receive($moduleResource2);
         $this->checkStatusCode($errorCode, $moduleResource2);
     } else {
         $moduleResource2 = saprfc_function_discover($this->getConnectionResource(), 'BAPI_TRANSACTION_COMMIT');
         $errorCode = saprfc_call_and_receive($moduleResource2);
         $this->checkStatusCode($errorCode, $moduleResource2);
     }
     $successState = @saprfc_table_read($moduleResource, 'RETURN', 1);
     //
     if (!empty($successState['TYPE']) && $successState['TYPE'] == 'E') {
         throw new SAP_Exception(json_encode($successState));
     }
     $result = array();
     $this->appendExporter($result, $moduleResource, $module->getExporter());
     //		saprfc_function_debug_info($moduleConnection);
     saprfc_function_free($moduleResource);
     if (PHP_SAPI == 'cli') {
         echo print_r($this->debug) . PHP_EOL;
     }
     return array('transactionSuccess' => false === $successState, 'export' => $result);
     // d.h. insert hat funktioniert!
 }
Example #9
0
         $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);
         }
      }
      for ($i=0;$i<count($def);$i++)
      {
         $interface = $def[$i];
         if ($interface["type"] == "TABLE")  // show content of internal tables
         {
            $form .= "<tr bgcolor=#D0D0D0><td colspan=2><b>TABLE ".$interface["name"]."</b></td></tr>\n";
            unset ($vararray);
            $rows = saprfc_table_rows ($fce,$interface["name"]);
            for ($j=1;$j<=$rows;$j++)
                $vararray[] = saprfc_table_read($fce,$interface["name"],$j);
            $form .= show_table_out ($interface["name"],$interface["def"],$vararray);
         }
      }
      $form  .= "</table>";
      print_window ("Results of function module $function",$form,"<a href=\"javascript:history.back()\">Back</a>&nbsp;<a href=\"saprfc_test.php?p=newlogin\">New login</a>&nbsp;<a href=\"saprfc_test.php?p=select\">Select other function</a>");
      print_footer();
}

// free resources and close rfc connection
@saprfc_function_free($fce);
@saprfc_close($rfc);

?>
Example #10
0
 function Next()
 {
     if ($this->rowLast > $this->rowNum) {
         return false;
     }
     unset($this->row);
     $this->row = @saprfc_table_read($this->fce, $this->name, $this->rowLast);
     $this->rowLast++;
     return true;
 }