Class: NWRFC::FunctionCall

Inherits:
DataContainer show all
Defined in:
lib/nwrfc.rb

Overview

Represents a callable instance of a function

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DataContainer

#[], #[]=, #fields, #member_metadata, #value_to_date, #value_to_time

Constructor Details

#new(function) ⇒ FunctionCall #new(function_handle) ⇒ FunctionCall

Call with either Function or Connection and Function Call instance (handle)

Overloads:

  • #new(function) ⇒ FunctionCall

    Get a function call instance from the function description

    Parameters:

    • function (Function)

      Function Description

  • #new(function_handle) ⇒ FunctionCall

    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

    Parameters:

    • function_handle (FFI::Pointer)

      Pointer to the function handle (RFC_FUNCTION_HANDLE)



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# 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

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



280
281
282
# File 'lib/nwrfc.rb', line 280

def connection
  @connection
end

#descObject (readonly)

Returns the value of attribute desc.



280
281
282
# File 'lib/nwrfc.rb', line 280

def desc
  @desc
end

#functionObject (readonly)

Returns the value of attribute function.



280
281
282
# File 'lib/nwrfc.rb', line 280

def function
  @function
end

#handleObject (readonly)

Returns the value of attribute handle.



280
281
282
# File 'lib/nwrfc.rb', line 280

def handle
  @handle
end

Instance Method Details

#active?(parameter) ⇒ Boolean

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

Returns:

  • (Boolean)


330
331
332
333
334
335
# 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) ⇒ Object

Set a named parameter to inactive



346
347
348
# File 'lib/nwrfc.rb', line 346

def deactivate(parameter)
  set_active(parameter, false)
end

#invoke(tx = nil) ⇒ Object

Execute the function on the connected ABAP system

Raises:

  • NWRFC::NWError



314
315
316
317
318
319
320
321
322
323
324
# 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) ⇒ Object

Set a named parameter to active or inactive



338
339
340
341
342
343
# 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