Skip to Content
Technical Articles
Author's profile photo Stefan Schnell

Different Behaviour of new SAP ActiveX Controls

These days I got an e-mail about different behaviour after installing the actual SAP GUI for Windows 7.50 with the changed ActiveX controls. This means the old ActiveX controls bases on Classic RFC library and the new ActiveX controls bases on SAP NetWeaver RFC library.

  1. The length of a return value from a table was with the old ActiveX controls corresponding to the content, but with the new ActiveX controls corresponding to the definition.
  2. The setting of a value from a table column doesn’t work anymore with the new version.

For my test scenario I use an enviroment which I described here.

Here my analysis about this behaviour:

Value Length

With the old ActiveX controls delivers the call of RFC_READ_TABLE with the table USR01 exact the length of the table USR01 plus delimiters:

But with the new ActiveX controls delivers the same program the length of the data structure (UC):

If you transfer a great data volum, it could be give some memory problems.

Set Value of a Table Column

With the old ActiveX controls you can set a value of a table column. Here a snippet with AutoIt:

$Row = $ReadTableFunc.Tables("FIELDS").Rows.Add
$Row("FIELDNAME") = "BNAME"
$Row = $ReadTableFunc.Tables("FIELDS").Rows.Add
$Row("FIELDNAME") = "LANGU"

This delivers in the SAP system this:

But with the new ActiveX controls delivers the same program this:

It seems that it is not possible to set the value of a table column at the moment.

 

The Test Program

To test this different behaviour I use an AutoIt script which calls RFC_READ_TABLE with the table USR01. The code is commented and really easy to understand.

;-Begin-----------------------------------------------------------------

  ;-Directives----------------------------------------------------------
  AutoItSetOption("MustDeclareVars", 1)

  ;-Sub Main------------------------------------------------------------
  Func Main()

    ;-Variables---------------------------------------------------------
    Local $SAPFunc = 0, $Connection = 0, $SAPConnection = 0
    Local $ReadTableFunc = 0, $Param = 0, $Table = 0
    Local $RowCount = 0, $DataLine = "", $i = 0

    ;-Get SAP.Functions-------------------------------------------------
    $SAPFunc = ObjCreate("SAP.Functions.Unicode")
    If Not IsObj($SAPFunc) Then
      MsgBox(0, "Hint", "Can't create SAP.Functions.Unicode object")
      Exit
    EndIf

    ;-Get SAP.LogonControl connection-----------------------------------
    $Connection = $SAPFunc.Connection
    If Not IsObj($Connection) Then
      MsgBox(0, "Hint", "Can't get SAP.LogonControl connection")
      Exit
    EndIf

    ;-Set connection parameters-----------------------------------------
    $Connection.Client = "001"
    $Connection.User = "BCUSER"
    $Connection.Password = "minisap"
    $Connection.Language = "EN"
    $Connection.System = "NSP"
    $Connection.HostName = "ABAP"
    $Connection.SystemNumber = 0

    ;-Connect SAP system------------------------------------------------
    $SAPConnection = $Connection.Logon(0, -1)
    If $SAPConnection = 0 Then
      MsgBox(0, "Hint", "Can't logon to the SAP system")
      Exit
    EndIf

    ;-Get ABAP function module RFC_READ_TABLE---------------------------
    $ReadTableFunc = $SAPFunc.Add("RFC_READ_TABLE")
    If Not IsObj($ReadTableFunc) Then
      ;-Logoff----------------------------------------------------------
      $Connection.Logoff()
      MsgBox(0, "Hint", "Can't get the function module")
      Exit
    EndIf

    ;-Define export parameters------------------------------------------
    $ReadTableFunc.Exports("QUERY_TABLE").Value = "USR01"
    $ReadTableFunc.Exports("DELIMITER").Value = "~"

    ;-Call ABAP function module RFC_READ_TABLE to read table USR01------
    $ReadTableFunc.Call()

    ;-Show the content of the table-------------------------------------
    $Table = $ReadTableFunc.Tables("DATA")
    If IsObj($Table) Then
      $RowCount = $Table.RowCount
      For $i = 1 To $RowCount
        $DataLine = $Table.Value($i, "WA")
        MsgBox(0, "Data", "Length: " & StringLen($DataLine) & @CrLf & _
          String($DataLine))
      Next
    EndIf

    ;-Logoff------------------------------------------------------------
    $Connection.Logoff()

  EndFunc

  ;-Main----------------------------------------------------------------
  If @AutoItX64 Then
    MsgBox(0, "Version", "AutoIt " & @AutoItVersion & " x64")
  Else
    MsgBox(0, "Version", "AutoIt " & @AutoItVersion & " x86")
  EndIf

  Main()

;-End-------------------------------------------------------------------

 

I asked about the future of ActiveX controls here. I wrote a recommendation about the ActiveX controls here. And a few tips how to work with it eg. here and here. I was surprised about the further development of the ActiveX controls with the SAP GUI for Windows 7.50, because for a long time it looked as if no changes could be expected.

 

2017/09/26: With the SAP GUI for Windows 7.50 PL 2 from 2017/09/12 the error is fixed. Thanks to Badari, Gaurav and Shruthi for the efforts.

Assigned Tags

      11 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Frank Krause
      Frank Krause

      Hello Stefan,

      thank you for this great post.
      I would like to quickly comment from SAP side:

      • The change you explain above is mentioned in our note "2256415 - Adaptation of RFC controls (Logon, Function, Table and BAPI) to use SAP NetWeaver RFC Library"
      • We do not intend to "revive" these controls, but we are keeping them alive for compatibility
      • The background of the switch to SAP NetWeaver RFC is the fact that the classical RFC library (librfc32.dll) - which had been used by these controls in the past - is no longer supported

      Best regards,
      Frank

      Author's profile photo Stefan Schnell
      Stefan Schnell
      Blog Post Author

      Hello Frank,

      thank you very much for your reply.

      Thanks also for the clear words that the controls should not be revived - that is good to know.

      Cheers
      Stefan

      Author's profile photo Badari Nath J
      Badari Nath J

      Hi Stefan,

      We are from SAP GUI Controls development team and we have developed these new ActiveX controls based on SAP NetWeaver RFC library.

      Thanks a lot for sharing your observations. We have fixed both the issues observed by you.

      We have also released SAP Note 2483700 to address these issues.

      We would like to share test binaries with you so that you can recheck and share your feedback.

      It would be good if you can share you mail id so that we can share test binaries which contains fixes for both the issues.

      Please feel free to share your feedback/observations while using the new ActiveX controls based on SAP NetWeaver RFC library.

      Thanks a lot for your efforts in sharing your feedback.

      Please feel free to reach out to us in case if you need any further clarification about the new NWRFC based ActiveX controls.

      Thanks and Regards,

      Badari Nath, Gaurav and Shruthi.

       

      Author's profile photo Stefan Schnell
      Stefan Schnell
      Blog Post Author

      Hello Badari,

      thank you very much for your reply and the solution - great 🙂

      Cheers
      Stefan

      Author's profile photo Badari Nath J
      Badari Nath J

      Hi Stefan,

      You are welcome.

      Feel free to get back to us in case if you need any clarification on these new SAPNRFC based activeX controls.

      Thanks and Regards,

      Badari Nat

      Author's profile photo David Buzinkai
      David Buzinkai

      Hello Everyone,

      I am using VBA code to extract tables data from SAP and I am facing same issues that Stefan described in his blog entry - the RFC call returns incorrect columns lengths and empty data for table cells

      I have patched the SAP Logon with latest patch (3) including hotfix but it did not helped:

       

      the data that I see from SE37 transaction (FM: DB_ORA_TABLESPACE_HISTORY; TAB: HIST1):

      the data that I get in excel VBA:

      8th column even returns sometimes "Automation error" but this does not bother me for now and columns 4-6 are having incorrect length and shows empty data. For example column 6 shows IntLength=8 but the column in SAP is obviously longer:

      I'm not sure if I am missing something obvious or there is some other issue

       

      I would really appreciate any help, advice or hints

       

      PS: I am using same commands to connect to SAP as Stefan stated above in "Test Program" section

       

      thanks again and best retards,

      David Buzinkai

      Author's profile photo David Buzinkai
      David Buzinkai

      UPDATE:

      I have found that the column length is correct because the actual data type is PACKED for these 3 fields

      But I still dont know why the VBA shows empty string for PACKED variables and incorrect string for INTEGER variables in this specific case

       

      Regards,

      David

      Author's profile photo Ralf Reckfort
      Ralf Reckfort

       

      Hi,

      it seems the exception is used differntly in the new ActiveX (SAPGUI 7.50, pl7) - if I call a function in a loop, and react on the sap.functions.exception, the new AxtiveX does not reset the exception text in the next call. Here's my example:

      For Each...

      ' Call SAP FuBa
      If oSapFunction.Call() = False Then ErrorHandler  oSapFunction.Exception: Exit Function
      If Err.Number <> 0 Then ErrorHandler  oSapFunction.Exception: Exit Function

      ' check for errors
      If oSapFunction.Exception <> "" Then ErrorHandler oSapFunction.Exception: Exit Function

      Next

      Once an error occurs in the loop, all following oSapFunction.Exception are not empty and leads to errors. Any idea how to reset the oSapFunction.Exception after a call?

      Thanks in advance.

      King regards,

      Ralf

       

       

      Author's profile photo Stefan Schnell
      Stefan Schnell
      Blog Post Author

      Hello Ralf,

      I don't know how the libraries from SAP GUI for Windows < 7.50 works in the case you described, but I can confirm the behaviour. In my opinion you can handle the different behaviour very easily:

      ForEach...
      
        'Call SAP FuBa
        retValue = oSapFunction.Call()
        If retValue = False Or Err.Number <> 0 Then
          ErrorHandler oSapFunction.Exception
          Exit Function
        End If
      
        'check for errors
        If retValue = False Then
          ErrorHandler oSapFunction.Exception
          Exit Function
        End If
       
      Next

      As far as I know is the Exception property only defined as get, so I assume you have no chance to clear that. So you need an auxiliary construct via an additional variable.

      Best regards
      Stefan

       

      Author's profile photo Guido Bamberger
      Guido Bamberger

      Hi together,

      unfortunately, I detected an other issue with regard to the BAPI behaviour of SAPgui 7.50 (PL13):
      If a BAPI is called two (or more) times with a different parameterisation during one session (means without an interim logoff/logon), then the (changed) parameters are not transported to the ABAP processor! - The ABAP processor still "sees" the parameter values of the first BAPI call.

      Example:

      bapi_param_inout.Value("DATA") = 'X'

      => First BAPI call => ABAP processor sees "X"!

      bapi_param_inout.Value("DATA") = 'Y'

      => Second BAPI call => ABAP processor still sees "X" (instead of "Y")!

      Did anybody recognize this behaviour too? And is there any solution?

      Regards,
      Guido

      Author's profile photo Roger Zühlsdorf
      Roger Zühlsdorf

      A serious bug in SapGUi 7.60 PL 9

      In VBA/VB6 assigning a number > 32767  creates to a non numeric RFC variable  an 16 bit overflow with no error.  A different value (may be negative) ist stored instead.
      This happens for table fields also an may create wrong data in uploads.

      My note
      3003922 - SAP GUI NWRFC function control : Large values of integer type are not getting passed correctly through VBA code to NWRFC Controls.

      ... Logon ...

      Set oFunc = oR3.Add("RFC_GET_MATERIAL_DATA")

      Dim lNumber as Long

      lNumber = 812345
      oFunc.Exports("I_MATERIAL") = lNumber

      MsgBox "lNumber=<" & lNumber & "> is changed to = Func.Exports(I_MATERIAL) = <" & oFunc.Exports("I_MATERIAL").Value & ">"

      >>>>> 812345 is changed to 25913 !!
      Using Str$(lNumber) works correctly