The file bapi.php is used to prepare the Input fields for the transfer to the SAP system and to treat the returned data.
<?php
class jobsapbapi_Z_ACC_DOCUMENT_POST
extends BapiHandler
{
private $nextItemNo;
private $currencyAmount;
public function __construct($webServiceId, $inputValues)
{
$this->nextItemNo = 1;
$this->currencyAmount = array();
parent::__construct($webServiceId, $inputValues);
}
...
The class name follows the format jobsapbapi_<JobLink for SAP module name>. The class expands the JobRouter class BapiHandler. The constructor can be overwritten if additional actions are necessary. The constructor of the BapiHandler class has to be called as well.
Furthermore, the class contains functions to treat the field values of specific tables from the Tables element if needed. You can also treat dependencies between two fields from different tables here. Tables are processed according to their order in the bapi.xml file. The visibility of the functions has to be set to protected to allow the BapiHandler class to access them. The function names correspond to the format get<table name>. Passed as input parameter are the table name and a BapiDefinition object. Every function has to return an array with data for the respective table.
protected function getACCOUNTPAYABLE($tableName, BapiDefinition $bapiDefinition)
{
$inputParameters = array();
$inputParameterRow = array();
$tableInputFields = $bapiDefinition->getInputFields($tableName);
foreach ($tableInputFields as $field) {
$fieldName = $field['name'];
$fieldType = $field['type'];
$fieldValue = $this->getInputFieldValue($fieldName, $fieldType);
$inputParameterRow[$fieldName] = $fieldValue;
}
$inputParameterRow['ITEMNO_ACC'] = $this->nextItemNo++;
$inputParameters[] = $inputParameterRow;
$currency = $this->getInputFieldValue('CURRENCY');
$totalAmount = $this->getInputFieldValue('TOTAL_AMOUNT') * -1;
$this->currencyAmount[] = array(
'CURRENCY' => $currency, 'AMT_DOCCUR' => $totalAmount, 'ITEMNO_ACC' => $inputParameterRow['ITEMNO_ACC'],
'AMT_BASE' => 0.00
);
return $inputParameters;
}
The function getOutputParameter can be overwritten to pass output fields into appropriate SAP fields. The visibility of the function has to be set to protected to allow the BapiHandler class to access it.
protected function getOutputParameter($name)
{
switch ($name) {
case 'FISCALYEAR':
return 'OBJ_KEY';
break;
case 'INVOICEDOCNUMBER':
return 'OBJ_KEY';
break;
default:
throw new JobRouterException('Unknown name for userdefined output parameter: ' . $name);
break;
}
}
The function getOutputValue can be overwritten to store return values from the SAP system into appropriate table fields in JobRouter. The visibility of the function has to be set to public to allow JobRouter classes to access it.
public function getOutputValue($fieldName, $result)
{
switch ($fieldName) {
case 'FISCALYEAR':
$objectKey = $result['OBJ_KEY'];
return substr($objectKey, -4);
break;
case 'INVOICEDOCNUMBER':
$objectKey = $result['OBJ_KEY'];
return substr($objectKey, 0, 10);
break;
default:
throw new JobRouterException('Unknown field for userdefined output parameter: ' . $fieldName);
break;
}
}
Note: To transfer data to the SAP system, a get<table name> function is required for each table (input parameters and input lists). For the retrieval of data from the SAP system no such functions are needed, the data is coupled to JobRouter fields using the definition in bapi.xml and the configuration of the system activity or module (output parameters and output lists).