Hello community,

 

Julia is a very incredible high-performance programming language for technical computing. You can find Julia here. You can find more information about Julia here. You can find the first introduction of Julia in SCN Innovation Management here from Alvaro Tejada Galindo. Julia offers new perspectives, e.g. in parallel programming or speed. Julia uses a low level virtual machine (LLVM) to execute the code. The VM generates optimized processor dependent machine code, so Julia is very fast. Here now an include to use Julia with the SAP NetWeaver RFC library – but only with a few functions:

#-Begin-----------------------------------------------------------------

  #-User Defined Types--------------------------------------------------
    type RFC_CONNECTION_PARAMETER
      nameASHost::Ptr{UInt16}
      valueASHost::Ptr{UInt16}
      nameSysNr::Ptr{UInt16}
      valueSysNr::Ptr{UInt16}
      nameClient::Ptr{UInt16}
      valueClient::Ptr{UInt16}
      nameUser::Ptr{UInt16}
      valueUser::Ptr{UInt16}
      namePassWd::Ptr{UInt16}
      valuePassWd::Ptr{UInt16}
      nameLang::Ptr{UInt16}
      valueLang::Ptr{UInt16}
    end

    type RFC_ERROR_INFO
      code::Int32
      group::Int32
      key::Ptr{UInt16}
      message::Ptr{UInt16}
      abapMsgClass::Ptr{UInt16}
      abapMsgType::Ptr{UInt16}
      abapMsgNumber::Ptr{UInt16}
      abapMsgV1::Ptr{UInt16}
      abapMsgV2::Ptr{UInt16}
      abapMsgV3::Ptr{UInt16}
      abapMsgV4::Ptr{UInt16}
    end

  #-Constants-----------------------------------------------------------
    const sapnwrfc = "sapnwrfc.dll"

  #-Main----------------------------------------------------------------
    cd("C:\\Projects\\SAP\\RFC\\Julia")

    code = 0
    group = 0
    key = ""
    message = ""
    abapMsgClass = ""
    abapMsgType = ""
    abapMsgNumber = ""
    abapMsgV1 = ""
    abapMsgV2 = ""
    abapMsgV3 = ""
    abapMsgV4 = ""
    RfcErrorInfo = RFC_ERROR_INFO(
     code, group, pointer(utf16(key)), pointer(utf16(message)),
     pointer(utf16(abapMsgClass)), pointer(utf16(abapMsgType)),
     pointer(utf16(abapMsgNumber)), pointer(utf16(abapMsgV1)),
     pointer(utf16(abapMsgV2)), pointer(utf16(abapMsgV3)),
     pointer(utf16(abapMsgV4))
    )

  #-RfcGetVersion-------------------------------------------------------
    function RfcGetVersion()
      majorVersion = Ref{UInt32}(0)
      minorVersion = Ref{UInt32}(0)
      patchLevel = Ref{UInt32}(0)
      ptrVersion = ccall((:RfcGetVersion, sapnwrfc), stdcall,
        Ptr{UInt16}, (Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}),
        majorVersion, minorVersion, patchLevel)
      return utf16(ptrVersion), majorVersion[], minorVersion[],
        patchLevel[]
    end

  #-RfcOpenConnection---------------------------------------------------
    function RfcOpenConnection(ashost::AbstractString,
      sysnr::AbstractString, client::AbstractString,
      user::AbstractString, passwd::AbstractString,
      lang::AbstractString = "EN")
      nameASHost = "ASHOST"
      valueASHost = ashost
      nameSysNr = "SYSNR"
      valueSysNr = sysnr
      nameClient = "CLIENT"
      valueClient = client
      nameUser = "USER"
      valueUser = user
      namePassWd = "PASSWD"
      valuePassWd = passwd
      nameLang = "LANG"
      valueLang = lang
      RfcConnectionParameter = RFC_CONNECTION_PARAMETER(
        pointer(utf16(nameASHost)), pointer(utf16(valueASHost)),
        pointer(utf16(nameSysNr)), pointer(utf16(valueSysNr)),
        pointer(utf16(nameClient)), pointer(utf16(valueClient)),
        pointer(utf16(nameUser)), pointer(utf16(valueUser)),
        pointer(utf16(namePassWd)), pointer(utf16(valuePassWd)),
        pointer(utf16(nameLang)), pointer(utf16(valueLang))
      )
      return ccall((:RfcOpenConnection, sapnwrfc), stdcall,
        UInt32, (Ref{RFC_CONNECTION_PARAMETER}, UInt32,
        Ref{RFC_ERROR_INFO}), RfcConnectionParameter, 6, RfcErrorInfo)
    end

  #-RfcGetFunctionDesc--------------------------------------------------
    function RfcGetFunctionDesc(rfcHandle::UInt32,
      funcName::AbstractString)
      return ccall((:RfcGetFunctionDesc, sapnwrfc), stdcall,
        UInt32, (UInt32, Ptr{UInt16}, Ref{RFC_ERROR_INFO}),
        rfcHandle, utf16(funcName), RfcErrorInfo)
    end

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

  #-RfcInvoke-----------------------------------------------------------
    function RfcInvoke(rfcHandle::UInt32, funcHandle::UInt32)
      return ccall((:RfcInvoke, sapnwrfc), stdcall,
        UInt32, (UInt32, UInt32, Ref{RFC_ERROR_INFO}),
        rfcHandle, funcHandle, RfcErrorInfo)
    end

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

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

#-End-------------------------------------------------------------------

With this include it is easy possible to use NetWeaver RFC Library with Julia REPL interface (Read – Eval – Print – Loop):

JuliaMeetsSAP2.jpg

In the example above you see loading of the include and a sequence of SAP NetWeaver RFC commands to invoke the RFC_PING function module.

After the RfcOpenConnection command you see the connected Julia in the Gateway Monitor (TAC SMGW):

JuliaMeetsSAP.JPG

It should be not very difficult now to extend the include with the other functions from the SAP NetWeaver RFC library.

More information:

Part 2: Read a table

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.

1 Comment

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

Leave a Reply