class NWRFC::FunctionCall

Represents a callable instance of a function

Attributes

connection[R]
desc[R]
function[R]
handle[R]

Public Class Methods

new(*args) click to toggle source
Call with either Function or Connection and Function Call instance (handle)

@overload new(function)

Get a function call instance from the function description
@param [Function] function Function Description

@overload new(function_handle)

Used in the case of server functions; instantiate a function call instance from the connection
and function description handles received when function is invoked on our side from a remote
system; in this case, there is no handle to the connection, and we take advantage only of the
data container capabilities
@param [FFI::Pointer] function_handle Pointer to the function handle (RFC_FUNCTION_HANDLE)
# File lib/nwrfc.rb, line 292
def initialize(*args)
  @error = NWRFCLib::RFCError.new
  if args[0].class == FFI::Pointer
    @handle = args[0]
    @connection = nil
    @function = nil
    # @connection = args[0].connection
    @desc = NWRFCLib.describe_function(@handle, @error)
    #@todo Investigate having a referenced Function object as well in the server case; does it have practical applications?
    #  Doing this would require an extra way of handling the constructor of Function
    # @function = Function.new
  elsif args[0].class == Function
    @function = args[0] #function
    @connection = args[0].connection
    @handle = NWRFCLib.create_function(@function.desc, @error.to_ptr)
    @desc = args[0].desc
  end
  NWRFC.check_error(@error)
end

Public Instance Methods

active?(parameter) click to toggle source

Returns whether or not a given parameter is active, i.e. whether it will be sent to the server during the RFC call with FunctionCall#invoke. This is helpful for functions that set default values on parameters or otherwise check whether parameters are passed in cases where this may have an impact on performance or otherwise @param[String, Symbol] parameter Name of the parameter

# File lib/nwrfc.rb, line 330
def active?(parameter)
  is_active = FFI::MemoryPointer.new :int
  rc = NWRFCLib.is_parameter_active(@handle, parameter.to_s.cU, is_active, @error)
  NWRFC.check_error(@error) if rc > 0
  is_active.read_int == 1
end
deactivate(parameter) click to toggle source

Set a named parameter to inactive

# File lib/nwrfc.rb, line 346
def deactivate(parameter)
  set_active(parameter, false)
end
invoke(tx = nil) click to toggle source
Execute the function on the connected ABAP system

@raise NWRFC::NWError

# File lib/nwrfc.rb, line 314
def invoke(tx = nil)
  raise "Not a callable function" unless @connection
  if tx
    rc = NWRFCLib.invoke_in_transaction(tx.handle, @handle, @error.to_ptr)
    NWRFC.check_error(@error) if rc > 0
  else
    rc = NWRFCLib.invoke(@connection.handle, @handle, @error.to_ptr)
    #@todo Handle function exceptions by checking for :RFC_ABAP_EXCEPTION (5)
    NWRFC.check_error(@error) if rc > 0
  end
end
set_active(parameter, active=true) click to toggle source

Set a named parameter to active or inactive

# File lib/nwrfc.rb, line 338
def set_active(parameter, active=true)
  (active ? active_flag = 1 : active_flag = 0)
  rc = NWRFCLib.set_parameter_active(@handle, parameter.to_s.cU, active_flag, @error)
  NWRFC.check_error(@error) if rc > 0
  active
end