2

I know how to call a SAP webservice from PHP, but how can I send parameters with my request?

I tried the following:

    #Define Authentication 
  $SOAP_AUTH = array( 'login'    => 'user',
                      'password' => 'password');

  #Specify WSDL
  $WSDL = "http://xxxxxx/sap/bc/srt/wsdl/bndg_E417CA96FB8A5FF1B4A8000C293C9303/wsdl11/allinone/standard/document?sap-client=100";

  #Create Client Object, download and parse WSDL
  $client = new SoapClient($WSDL,$SOAP_AUTH);

  $HEAD_DATA = new stdClass();
  $HEAD_DATA->Material = 'WM-999996';
  $HEAD_DATA->IndSector = 'M';
  $HEAD_DATA->MatlType = 'FERT';
  $HEAD_DATA->BasicView = 'X';
     
  #Setup input parameters (SAP Likes to Capitalise the parameter names)
  $params = array(
          'HEADDATA' => $HEAD_DATA
  );
  
  #Call Operation (Function). Catch and display any errors
  try
  {
     $result = $client->StandardMaterialSaveData($params);
  }
  catch (SoapFault $exception)
  {
      print "***Caught Exception***\n";
      print_r($exception);
      print "***END Exception***\n";
      die();
  }
    
  #Out the results
  print_r($result);

But it gives me the following error:

SOAP-ERROR: Encoding: object has no 'HeadData' property

I think that the following lines are wrong:

  $HEAD_DATA = new stdClass();
  $HEAD_DATA->Material = 'WM-999996';
  $HEAD_DATA->IndSector = 'M';
  $HEAD_DATA->MatlType = 'FERT';
  $HEAD_DATA->BasicView = 'X';

Can anyone please help me and tell me how to add the HEAD_DATA variable correctly onto the webservice call?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
StS
  • 283
  • 4
  • 10
  • You need to show the WSDL – hek2mgl Aug 18 '14 at 08:16
  • This is the part of the WSDL. The whole WSDL would be much too big: It seems to be a table... – StS Aug 18 '14 at 08:37
  • I fear only the full WSDL would help. Can you post it on a pastebin and drop the link here? If note, look at the method definition, and what expected parameters are – hek2mgl Aug 18 '14 at 08:38
  • Here's the Link to bastebin: http://pastebin.com/JHz8U8Ri – StS Aug 18 '14 at 08:45
  • Following the WSDL, the operation `StandardMaterialSaveData`, expexts a single parameter which has the type `StandardMaterialSaveData` (Having the the same name for method and a param is possible but lets say, *unlucky* design.).. However, the expected format of the param object can be found here: http://pastebin.com/5r16UJAJ – hek2mgl Aug 18 '14 at 09:12
  • OK, thank you very much for your help. I found out that my example above is working when I type HeadData instead of HEADDATA. It seems that SAP is case sensitive here. Problem ist solved for me. – StS Aug 18 '14 at 09:38
  • Yeah, had a another look at the WSDL and what you are saying is true. All the members of `StandardMaterialSaveData` are optional, except of `HeadData`. And yes, SOAP is case sensitive. – hek2mgl Aug 18 '14 at 09:41

0 Answers0