cancel
Showing results for 
Search instead for 
Did you mean: 

SAP.NET connector 3.0

Former Member
0 Kudos

Dear All,

Recently we had upgraded our web system from Visual Studio 2003 to Visual Studio 2013.  At the same time, we also applied the SAP.NET connector 3.0 instead of RFC call from the SAP function control to connect to the SAP system.

The method that we used to call SAP basically is register RFC -> Call BAPI -> Unregister RFC

<QUOTE>

...

RfcDestinationManager.RegisterDestinationConfigguration(objDestConfig)

...

bapiSOGetDetail.Invoke(destination1)

...

RfcDestinationManager.UnregisterDestinationConfiguration(objDestConfig)

...

<UNQUOTE>

Attached please find the VB source code for your reference.

For single user calling, there is no problem.  However, when there are more than one user calling the BAPI at the same time.  The register will be failed.

Error : Destination configuration already inialized.

Since we need multiple users to call and update SAP system from web system.  Please let me know there is any solution for us.

Look forward to your information.  Thank you very much.

Best Regards

David

Accepted Solutions (1)

Accepted Solutions (1)

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello David,

the pattern you use is wrong. It does not make sense to register/unregister an IDestinationConfiguration all the time. Unregister is an operation, which should be needed very rarely. Registering only once during startup of an application (server). An IDestinationConfiguration implementation is not representing a single destination, but a destination storage. It will take care for providing the properties for all destinations it manages in the associated storage. Your scenario is done differently. You need a single destination pointing to the target system, which is configured somewhere and in the application code you need to create a custom destination from it, set the user credentials and invoke the function module. This has been described already in other forum discussions, simply search for one.

Best regards,

Markus

Former Member
0 Kudos

Dear Markus

Thanks for your information.  I change the code as follows.  It seems work to connect SAP with multiple users.  Is it a correct approach?

Private Sub check_user()

Try

    If Not RfcDestinationManager.IsDestinationConfigurationRegistered() Then

          Dim objDestConfig As New InmemoryDestinationConfiguration

          Dim parms as New RfcConfigParameters

          parms.Add(RfcConfigParameters.AppServerHost, sR3Add.Trim.ToString)

          parms.Add(RfcConfigParameters.SystemNumber, "00")

          parms.Add(RfcConfigParameters.Client, sR3Clinet.Trim.ToString)

          parms.Add(RfcConfigParameters.Language, "EN")

          parms.Add(RfcConfigParameters.Name, "WING")

          RfcDestinationManager.RegisterDestinationConfiguration(objDestConfig)

          objDestConfig.AddOrEditDestination(parms)

    End If

    Dim destination As RfcDestination = RfcDestinationManager.GetDestination("WING")

    Dim destination1 As RfcCustomDestination = destination.CreateCustomDestination()

    destination1.User = sUserID.Trim.ToString

    destination1.Password = sUserPass.Trim.ToString

    destination1.Ping()

Cache ex as Exception

     Response.Redirect("Error.aspx")

End Try

End Sub

Private Sub order_enquiry()

     Dim destination As RFCDestination = RfcDestinationManager.GetDestination("WING"

     Dim destination1 As RfcCustomDestination = destination.CreateCustomDestination()

     destination1.User = sUserID.Trim.ToString

     destination1.Password = sUserPass.Trim.ToString

     Dim repository As RfcRepository = destination1.Repository

     Dim bapiSOGetDetail As IRfcFunction = repository.CreateFunction("Z_BAPI_SALESDOCUMENT_GETDETAIL")

     bapiSOGetDetail.SetValue("SLAESDOCUMENT", DOC_No)

     bapiSOGetDetail.Invoke(destination1)

     ...

     Get results from RFC

     ...

End Sub

Thanks in advanced for your kindly support.

David Lau

MarkusTolksdorf
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi David,

it is definitely much better and with regard to order_enquiry it's already ok. check_user() might be needed, but should look differently. In particular the code in

    If Not RfcDestinationManager.IsDestinationConfigurationRegistered() Then
          Dim objDestConfig As New InmemoryDestinationConfiguration
          Dim parms as New RfcConfigParameters
          parms.Add(RfcConfigParameters.AppServerHost, sR3Add.Trim.ToString)
          parms.Add(RfcConfigParameters.SystemNumber, "00")
          parms.Add(RfcConfigParameters.Client, sR3Clinet.Trim.ToString)
          parms.Add(RfcConfigParameters.Language, "EN")
          parms.Add(RfcConfigParameters.Name, "WING")
          RfcDestinationManager.RegisterDestinationConfiguration(objDestConfig)
          objDestConfig.AddOrEditDestination(parms)
    End If

should be moved to a different place. The instance of InmemoryDestinationConfiguration should be in some place, where it's accessible by some configuration environment/screen and also the registration should happen outside of application code. Last but not least, the destination should also contain RepositoryUser and RepositoryPassword so that the metadata for calling the function modules can be looked up when needed.

Best regards,

Markus

Former Member
0 Kudos

Dear Markus,

Thank you so much for your quick response.  We will modify it according to your suggestion.

Best regards,

David Lau

Answers (0)