"When I Execute BAPIs, I don't get back any data". Help!

The two most common questions I get from customers using the SAPBinding:

  • I execute a BAPI (via the generated WCF proxy) from a .NET application. However, after the call returns, I see that many table parameters are null.
  • I am trying to execute a BAPI with some input values. If I use those same values in the SAP GUI, relevant data is returned. However, when I call the method via a WCF proxy from a .NET application, I get the message "No data found" or something similar.

For the first issue: consider a scenario where you want to call a BAPI, which returns 25 tables. Each table on the average, (assume) contains 100 rows relevant to the input you returned. That's a lot of data. You might be interested in just the rows from one table, and don't want the extra payload slowing things down. Therefore, we added an optimization in the WCF SAP Adapter - we only return those tables, which you specifically requested. You will notice that table parameters are ref / InOut parameters in the generated proxy. If you pass in null, the interpretation is that you are not interested, and hence the adapter will return null for that table. Therefore, if you want rows for a particular table, pass in an empty table (i.e., your array parameter should not be null, but instead new array[0] ).

If you're sending messages using the channel model instead of using a .NET proxy (for example, in BizTalk) - if the table node is missing from the input XML, we interpret that as if you're not interested in that table. If you do want the rows from that table in the response message, you should pass in the node in the input XML (0 rows, just the starting and ending parameter tag).

For the second issue: SAP has a concept called "conversion exit" - when you enter values in the SAP GUI, and then press F8 to execute the RFC, SAP behind the scenes converts your value (which you entered in the UI) to an appropriate format before executing the RFC. For example, lets take the RFC_CUSTOMER_GET RFC. For this example, enter * in the NAME1 field (leave the KUNNR field blank) and execute the RFC, to get back a list of all customers in SAP. Choose any customer, whose KUNNR is less than 10 digits (assume the KUNNR for a customer is "12"). Now, go back to the RFC_CUSTOMER_GET execution screen, leave the NAME1 field blank, and enter "12" in the KUNNR field. Execute the RFC. You should get back the details of the one customer (the customer with KUNNR = "12").
Now, from the WCF proxy generated for RFC_CUSTOMER_GET, execute it with the same input (i.e., NAME1 is null (since we don't want to send any value for NAME1 to SAP), but KUNNR is "12"). You will get back an error saying "NO_RECORD_FOUND". Why? Because, there really is no customer with KUNNR="12". When you executed the RFC from the SAP GUI, the conversion exit kicked in, which (behind the scenes) converted "12" to "0000000012" and then searched for the relevant data. It is not possible to apply such conversion exits from external programs (your .NET application using the SAP Adapter, for example), and hence you need to know the format in which the data is stored in SAP. If you re-run your .NET code passing in "0000000012" as the KUNNR in RFC_CUSTOMER_GET, (and provided you passed in an empty table (see issue #1 above) for the CUSTOMER_T table), you should now successfully get back 1 row for that customer.