Skip to Content

Hello community,

a few days ago I presented the programming language Julia here. Now an add-on with a few SAP NetWeaver RFC functions to the include to read tables.

At first the Julia code:

  #-RfcSetChar------------------------------------------------------
    function RfcSetChars(dataHandle::UInt32, name::AbstractString,
      charValue::AbstractString)
      return ccall((:RfcSetChars, sapnwrfc), stdcall,
        UInt32, (UInt32, Ptr{UInt16}, Ptr{UInt16}, UInt32,
        Ref{RFC_ERROR_INFO}),
        dataHandle, utf16(name), utf16(charValue), length(charValue),
        RfcErrorInfo)
    end

  #-RfcGetTable---------------------------------------------------------
    function RfcGetTable(dataHandle::UInt32, name::AbstractString)
      ref_tableHandle = Ref{UInt32}(0)
      rc = ccall((:RfcGetTable, sapnwrfc), stdcall,
        UInt32, (UInt32, Ptr{UInt16}, Ref{UInt32}, Ref{RFC_ERROR_INFO}),
        dataHandle, utf16(name), ref_tableHandle, RfcErrorInfo)
      return rc, ref_tableHandle[]
    end

  #-RfcGetRowCount------------------------------------------------------
    function RfcGetRowCount(tableHandle::UInt32)
      ref_rowCount = Ref{UInt32}(0)
      rc = ccall((:RfcGetRowCount, sapnwrfc), stdcall,
        UInt32, (UInt32, Ref{UInt32}, Ref{RFC_ERROR_INFO}),
        tableHandle, ref_rowCount, RfcErrorInfo)
      return rc, ref_rowCount[]
    end

  #-RfcMoveToFirstRow---------------------------------------------------
    function RfcMoveToFirstRow(tableHandle::UInt32)
      return ccall((:RfcMoveToFirstRow, sapnwrfc), stdcall,
        UInt32, (UInt32, Ref{RFC_ERROR_INFO}),
        tableHandle, RfcErrorInfo)
    end

  #-RfcGetCurrentRow----------------------------------------------------
    function RfcGetCurrentRow(tableHandle::UInt32)
      return ccall((:RfcGetCurrentRow, sapnwrfc), stdcall,
        UInt32, (UInt32, Ref{RFC_ERROR_INFO}),
        tableHandle, RfcErrorInfo)
    end

  #-RfcGetChars---------------------------------------------------------
    function RfcGetChars(dataHandle::UInt32, name::AbstractString,
      bufferLength::Int32)
      charBuffer = Array(UInt16, bufferLength + 1)
      rc = ccall((:RfcGetChars, sapnwrfc), stdcall,
        UInt32, (UInt32, Ptr{UInt16}, Ptr{UInt16}, UInt32,
        Ref{RFC_ERROR_INFO}),
        dataHandle, utf16(name), charBuffer, sizeof(charBuffer),
        RfcErrorInfo)
      charBuffer[end] = 0
      return rc, charBuffer
    end

  #-RfcMoveToNextRow()--------------------------------------------------
    function RfcMoveToNextRow(tableHandle::UInt32)
      return ccall((:RfcMoveToNextRow, sapnwrfc), stdcall,
        UInt32, (UInt32, Ref{RFC_ERROR_INFO}),
        tableHandle, RfcErrorInfo)
    end

 

Here a sequence of the commands above, to read the table USR01:

JuliaMeetsSAP3.jpg

In the example above you see loading of the include and a sequence of SAP NetWeaver RFC commands to invoke the RFC_READ_TABLE function module. With the function RfcSetChars we set the import parameters of the function module. After the invoke we get the table via RfcGetTable and check the numbers of rows which are delivered with RfcGetRowCount. Now we get the current row and read the first line with RfcGetChars. With RfcMoveToNextRow we jump into the next line and read it also. Last but not least we close the connection.

Here the content of my USR01 table to show that the result in Julia exactly corresponds to the content of the table.

JuliaMeetsSAP33.JPG

It is very interesting to experiment with Julias REPL interface.

More information:

Part 3: sapnwrfc.jl include – with the examples for RFCSI_EXPORT and RFC_ABAP_INSTALL_AND_RUN

Enjoy it.

Cheers
Stefan

To report this post you need to login first.

2 Comments

You must be Logged on to comment or reply to a post.

  1. PAULO MACHADO

    Hi Stefan!

    thank you for share your knowledge about that Julia.

    I’d like know your opinion. What would be better? Use the VBA to import data (via RFC_READ_TABLE) directly to excel or using Julia to download the data (via RFC_READ_TABLE) and after export data to excel (although, I’m not sure, if we have problem when use excel 2016 (vba) 64 bit to connect SAP).

    Thanks in advance.

    Cheers

    Paulo

    (0) 
    1. Stefan Schnell Post author

      Hello Paulo,

      thanks for your reply.

      I don’t know exactly your requirement and your environment, so it isn’t easy to make an evaluation. There are no reasons recognizable why you should have trouble to get data from an SAP system. Check out your favorite way and if you have trouble consider all aspects of another way e.g. like:

      • Is a new development environment really necessary?
      • Is in my company the knowledge for the new development environment available?
      • Is it allowed in my company to use a different development environment?

      You see, it isn’t easy to answer the question “What would be better?” It is necessary to consider many aspects for that.

      Cheers

      Stefan

      (0) 

Leave a Reply