PHP SOAP Handling of SAP Table Reads

Handle tables returned from SAP, with PHP+SOAP.

SAP tables with SOAP

Note that AtpTable is listed as input (non-optional). Just pass it an empty string. For the output, you have to handle 3 cases: empty, 1 result (returns a single object), more than 1 result (returns an array). Make sure SOAPSINGLEELEMENT_ARRAYS is set, which returns an array of 1 item when only 1 item exists (PHP considers that a feature, not a bug). Then you just test that the array exists (isset).

$SOAP_OPTS = array( 'login' => '<THEACCOUNT>',
                    'password' => '<THEPASSWORD>',
                    'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
$WSDL = '';
$client = new SoapClient($WSDL,$SOAP_OPTS);
$params = array(
    'AtpTable' => '',
    'Branch' => '1',
    'CheckRule' => 'A',
    'GetRows' => '100',
    'IncludeUnsavSo' => 'X',
    'StartMaterial' => '12345',
    'Sloc' => '0001'

    $result = $client->ZfmGetAtpTest($params);

catch (SoapFault $exception)  
    print '***Caught Exception***\n';
    print '***END Exception***\n';

if (isset($result->AtpTable->item)) {  
    foreach ($result->AtpTable->item as $row) {
        print '$row->Material\t$row->Branch\t$row->AtpQty\n';

Jason Filley

I have chickens, read Scandinavian mysteries, and play a little Bach on the banjo. David Caruso is in 3 of my favorite movies ("Jade," "Session 9", "Hudson Hawk"), and I don't know how that happened.