cancel
Showing results for 
Search instead for 
Did you mean: 

Index out of bound array : calling bapi

Former Member
0 Kudos

Hi,

I am facing a problem while executing a BAPI using the SAP .net connector. The steps I performed are as follows:

Created a web project in Visual Studio .net using VB.net

Added the SAP Connector Proxy to the project

Dragged a Bapi_Customer_Getcontactlist onto the proxy

Created a page with a button on it

In the button_Click event of the web form I wrote the following code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim Maxrows As Integer = 10

Dim Return0 As BAPIRETURN1

Dim Contactaddressdata As BAPICONTACT_ADDRESSDATATable

Dim Customerrange As BAPICUSTOMER_IDRANGETable

SapProxy11.Bapi_Customer_Getcontactlist(Maxrows, Return0, Contactaddressdata, Customerrange)

End Sub

But when I execute the code the method the control goes into the SAPProxy1.vb file in which the code for the method Bapi_Customer_Getcontactlist contains a statement as follows

Dim results As Object()

results = SAPInvoke("Bapi_Customer_Getcontactlist", New Object() { _

Maxrows, Contactaddressdata, Customerrange})

When the SAPInvoke method is executed it gives an exception saying “Index was outside the bounds of the array.”

For any other bapi that I execute it gives the same error. Please someone help me to execute the BAPI and let me know if I have missed out something.

Regards,

sridhar

Accepted Solutions (0)

Answers (1)

Answers (1)

reiner_hille-doering
Active Contributor
0 Kudos

I'm not sure if it solves the problem, but you should initialize all variable you pass to the proxy:

Dim Return0 As New BAPIRETURN1
Dim Contactaddressdata As New BAPICONTACT_ADDRESSDATATable
Dim Customerrange As New BAPICUSTOMER_IDRANGETable

Former Member
0 Kudos

Thanks a lot for your suggestion.

I got rid of the error by manually editing the code that the SAPProxy.vb contains in which the SAPInvoke method is called. This method expects the second parameter as the array of input parameters which it writes automatically but when executed the number of parameters is not the same as those in the actual method.

i.e. The code that is written automatically when I drag the method from the Server explorer contains the BAPI method which internally calls the SAPInvoke method. Now the BAPI that I want to make a call contains the output parameters which you said I need to initialize. But the code excludes this output parameters in the SAPInvoke method. Thats the reason why the index out of bound error was generated.

Now once I manually changed the code to include the output parameters too in the SAPInvoke method the error is gone but the call thus made does not return any value in the output parameters. Where as when executed from the SAP IDE it returns the values.

Please let me know whats wrong with it.

Regards,

Sridhar