class NWRFC::Function

Represents a remote-enabled function module for RFC, can be instantiated either by the caller or by calling Connection#get_function. This only represents the description of the function; to call a function, an instance of a function call must be obtained with get_function_call

Attributes

connection[RW]
desc[R]
function_name[R]

Public Class Methods

new(*args) click to toggle source
Get a function module instance; can also be obtained by calling Connection#get_function
Takes either: (connection, function_name) or (function_name)
When passed only `function_name`, creates a new function description locally, instead of
fetching it form the server pointed to by connection

@overload new(connection, function_name)

Fetches a function definition from the server pointed to by the connection
@param [Connection] connection Connection to SAP ABAP system
@param [String] function_name Name of the function module on the connected system

@overload new(function_name)

Returns a new function descriptor. This is ideally used in the case of establishing a
server function. In this case, the function cannot be used to make a remote function call.
@param [String] function_name Name of the new function module
# File lib/nwrfc.rb, line 219
def initialize(*args)#(connection, function_name)
  raise("Must initialize function with 1 or 2 arguments") if args.size != 1 && args.size != 2
  @error =  NWRFCLib::RFCError.new
  if args.size == 2
    @function_name = args[1] #function_name
    @desc = NWRFCLib.get_function_desc(args[0].handle, args[1].cU, @error.to_ptr)
    NWRFC.check_error(@error)
    @connection = args[0]
  else
    @function_name = args[0] #function_name
    @desc = NWRFCLib::create_function_desc(args[0].cU, @error)
    NWRFC.check_error(@error)
    @connection = nil
  end
end

Public Instance Methods

add_parameter(parameter) click to toggle source

Add a parameter to a function module. Ideally to be used in the case where a function definition is built up in the client code, rather than fetching it from the server for a remote call @param [Parameter] Definition of a function module parameter

# File lib/nwrfc.rb, line 238
def add_parameter(parameter)
  rc = NWRFCLib.add_parameter(@desc, parameter.handle, @error)
  NWRFC.check_error(@error) if rc > 0
end
get_function_call() click to toggle source

Create and return a callable instance of this function module

# File lib/nwrfc.rb, line 244
def get_function_call
  FunctionCall.new(self)
end
parameter_count() click to toggle source

Get the number of parameters this function has

# File lib/nwrfc.rb, line 249
def parameter_count
  pcount = FFI::MemoryPointer.new(:uint)
  rc = NWRFCLib.get_parameter_count(@desc, pcount, @error)
  NWRFC.check_error(@error) if rc > 0
  pcount.read_uint
end
parameters() click to toggle source

Return the description of parameters associated with this Function

# File lib/nwrfc.rb, line 257
def parameters
  parameter_count.times.inject({}) do |params, index|
    param = NWRFCLib::RFCFuncParam.new
    NWRFCLib.get_parameter_desc_by_index(@desc, index, param.to_ptr, @error.to_ptr)
    params[param[:name].get_str] = {
      :type => NWRFCLib::RFC_TYPE[param[:type]],
      :direction => NWRFCLib::RFC_DIRECTION[param[:direction]],
      :nucLength => param[:nucLength],
      :ucLength => param[:ucLength],
      :decimals => param[:decimals],
      :typeDescHandle => param[:typeDescHandle],
      :defaultValue => param[:defaultValue].get_str,
      :parameterText => param[:parameterText].get_str,
      :optional => param[:optional]
    }
    params
  end
end