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.
-
#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)
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
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
280 281 282 |
# File 'lib/nwrfc.rb', line 280 def connection @connection end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
280 281 282 |
# File 'lib/nwrfc.rb', line 280 def desc @desc end |
#function ⇒ Object (readonly)
Returns the value of attribute function.
280 281 282 |
# File 'lib/nwrfc.rb', line 280 def function @function end |
#handle ⇒ Object (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
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
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 |