Class: NWRFC::FunctionCall
- Inherits:
-
DataContainer
- Object
- DataContainer
- NWRFC::FunctionCall
- Defined in:
- lib/nwrfc.rb
Overview
Represents a callable instance of a function
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
Instance Method Summary collapse
-
#active?(parameter) ⇒ Boolean
Returns whether or not a given parameter is active, i.e.
- #close ⇒ Object (also: #destroy)
-
#deactivate(parameter) ⇒ Object
Set a named parameter to inactive.
-
#initialize(*args) ⇒ FunctionCall
constructor
Call with either Function or Connection and Function Call instance (handle).
-
#invoke(tx = nil) ⇒ Object
Execute the function on the connected ABAP system.
-
#set_active(parameter, active = true) ⇒ Object
Set a named parameter to active or inactive.
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)
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/nwrfc.rb', line 343 def initialize(*args) @error = NWRFCLib::RFCError.new if args[0].kind_of?(FFI::Pointer) @handle = args[0] @owns_handle = false @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].kind_of?(Function) @function = args[0] #function @owns_handle = true @connection = args[0].connection @handle = NWRFCLib.create_function(@function.desc, @error.to_ptr) @desc = args[0].desc end NWRFC.check_error(@error) @function.send(:function_call_opened) if @function end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
331 332 333 |
# File 'lib/nwrfc.rb', line 331 def connection @connection end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
331 332 333 |
# File 'lib/nwrfc.rb', line 331 def desc @desc end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
331 332 333 |
# File 'lib/nwrfc.rb', line 331 def function @function end |
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
331 332 333 |
# File 'lib/nwrfc.rb', line 331 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
399 400 401 402 403 404 |
# File 'lib/nwrfc.rb', line 399 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 |
#close ⇒ Object Also known as: destroy
366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/nwrfc.rb', line 366 def close return unless @handle if @owns_handle rc = NWRFCLib.destroy_function(@handle, @error.to_ptr) NWRFC.check_error(@error) if rc > 0 end @handle = nil @desc = nil @function.send(:function_call_closed) if @function @function = nil end |
#deactivate(parameter) ⇒ Object
Set a named parameter to inactive
415 416 417 |
# File 'lib/nwrfc.rb', line 415 def deactivate(parameter) set_active(parameter, false) end |
#invoke(tx = nil) ⇒ Object
Execute the function on the connected ABAP system
382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/nwrfc.rb', line 382 def invoke(tx = nil) Rails.logger.info "NWRFC#invoke" if defined?(Rails) 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
407 408 409 410 411 412 |
# File 'lib/nwrfc.rb', line 407 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 |