Class: NWRFC::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/nwrfc.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#new(connection, function_name) ⇒ Function #new(function_name) ⇒ Function

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

Overloads:

  • #new(connection, function_name) ⇒ Function

    Fetches a function definition from the server pointed to by the connection

    Parameters:

    • connection (Connection)

      Connection to SAP ABAP system

    • function_name (String)

      Name of the function module on the connected system

  • #new(function_name) ⇒ Function

    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.

    Parameters:

    • function_name (String)

      Name of the new function module



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/nwrfc.rb', line 234

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
  @active_function_calls = 0
  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]
    @owns_desc = false
  else
    @function_name = args[0] #function_name
    @desc = NWRFCLib::create_function_desc(args[0].cU, @error)
    NWRFC.check_error(@error)
    @connection = nil
    @owns_desc = true
  end
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



219
220
221
# File 'lib/nwrfc.rb', line 219

def connection
  @connection
end

#descObject (readonly)

Returns the value of attribute desc.



218
219
220
# File 'lib/nwrfc.rb', line 218

def desc
  @desc
end

#function_nameObject (readonly)

Returns the value of attribute function_name.



218
219
220
# File 'lib/nwrfc.rb', line 218

def function_name
  @function_name
end

Instance Method Details

#add_parameter(parameter) ⇒ Object

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

Parameters:

  • Definition (Parameter)

    of a function module parameter



256
257
258
259
# File 'lib/nwrfc.rb', line 256

def add_parameter(parameter)
  rc = NWRFCLib.add_parameter(@desc, parameter.handle, @error)
  NWRFC.check_error(@error) if rc > 0
end

#closeObject Also known as: destroy



277
278
279
280
281
282
283
284
285
# File 'lib/nwrfc.rb', line 277

def close
  return unless @desc
  if @owns_desc
    raise "Cannot close function description while function calls are active" if @active_function_calls > 0
    rc = NWRFCLib.destroy_function_desc(@desc, @error)
    NWRFC.check_error(@error) if rc > 0
  end
  @desc = nil
end

#get_function_callObject

Create and return a callable instance of this function module



262
263
264
# File 'lib/nwrfc.rb', line 262

def get_function_call
  FunctionCall.new(self)
end

#parameter_countObject

Get the number of parameters this function has



290
291
292
293
294
295
# File 'lib/nwrfc.rb', line 290

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

#parametersObject

Return the description of parameters associated with this Function



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/nwrfc.rb', line 298

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

#with_function_callObject

Yield a function call and release its container, including nested data, even when the block raises.



268
269
270
271
272
273
274
275
# File 'lib/nwrfc.rb', line 268

def with_function_call
  function_call = get_function_call
  begin
    yield function_call
  ensure
    function_call.close
  end
end