SAP::WAS - Ruby extension for performing Web Service calls against an SAP Web Application Server
SAP::WAS - Ruby extension for performing RFC Web Service calls against an SAP Web Application Server.
API Documentation at: http://www.piersharding.com/download/ruby/sapwas/doc/
Project and Download at: http://raa.ruby-lang.org/project/sapwas
<b>SYNOPSIS</b>
require "SAP/WAS"
@was = SAP::WAS.new(:url => "http://seahorse.local.net:8000/sap/bc/soap/rfc",
:lang => "EN",
:client => "010",
:user => "developer",
:passwd => "developer",
:trace => nil)
# ping check
begin
ping = @was.ping
rescue SAP::WAS::CallException => e
puts "caught a ping failure..."
end
# get the system information
sapinfo = @was.sapinfo()
print "sapinfo: ", sapinfo.inspect, "\n"
# lookup the interface for RFC_READ_TABLE
itab = @was.discover("RFC_READ_TABLE")
# set some interface parameters
itab.query_table.value = "TRDIR"
itab.delimiter.value = "|"
itab.rowcount.value = 5
# put a rows into table OPTIONS
opts = itab.options = [ {'TEXT' => "NAME LIKE 'SAPL\%RFC\%'"} ]
# do the RFC call
@was.call(itab)
itab.data.rows do |h|
print "hash rows: ", h.inspect, "\n"
end
In the interests of performance it is possible to cache the results of Interface and Structure discovery - each of which require WAS calls to R/3 to determine their makeup. To switch on the caching call SAP::WAS.useCache = true. The location of the cache repository can be controlled by calling SAP::WAS.cache = "/some/directory" . The default cache directory is .was_cache/ - which is relative to the current working directory at run time. Caching makes use of the standard ruby serialisation mechanism Marshal.
Project homepage/owner http://www.piersharding.com/blog/
SAP::WAS.new(:url => "http://seahorse.local.net:8000/sap/bc/soap/rfc",creates a new WAS connection object.
All parameters are named (passed via a hash): :url :lang :client :user :passwd :trace
URL - URL of Web Application Servicelang - Language logged inclient - Client number logged in touser - User namepasswd - Passwordtrace - Trace mode of connectionSAP::WAS#discover(name="RFC_READ_REPORT")Used to look up the definition of an RFC interface. Returns an instance of SAP::WAS::Iface. This also automatically defines any associated SAP::WAS::Parm, SAP::WAS::Tab, SAP::WAS::Struct, and SAP::WAS::Field objects that come together to describe a complete RFC Interface.
SAP::WAS#structure(name="TDIR")Discover and return the definition of a valid data dictionary structure. This could be subsequently used in association with an SAP::WAS::Parm, or SAP::WAS::Tab object. Returns a SAP::WAS::Struct object.
SAP::WAS#pingTest that the SAP::WAS object is connects to the SAP Web Application Server system. Returns true or false.
SAP::WAS#sapinfoReturn a hash of the values supplied by the RFC_SYSTEM_INFO function module. This function is only properly called once, and the data is cached until the RFC connection is closed - then it will be reset next call.
SAP::WAS#call(iface=SAP::WAS::Iface object)Do the actual WAS call - this encapsulates the values for the RFC in the SAP::WAS::Iface object into a SOAP call, performs the call, and then decodes the SOAP Response setting the return values in the SAP::WAS::Iface object again.
SAP::WAS::Iface - Ruby extension for parsing and creating an Interface Object. The interface object would then be passed to the SAP::WAS object to carry out the actual call, and return of values.
Generally you would not create one of these manually as it is far easier to use the "discovery" functionality of the SAP::WAS#discover("RFCNAME") method. This returns a fully formed interface object. This is achieved by using standard RFCs supplied by SAP to look up the definition of an RFC interface and any associated structures.
require "SAP/WAS"
was = SAP::WAS.new( ... )
iface = was.discover('RFC_READ_REPORT')
iface.program.value = "SAPLGRFC"
was.call(iface)
None
SAP::WAS::Iface.new(name="Z_AN_RFC")creates a new RFC Interface object.
name - Name of the interfaceparms - Array of interface parameter objectsSAP::WAS::Iface#<name of a parameter>require "SAP/WAS"
was = SAP::WAS.new(...)
itab = was.discover("RFC_READ_TABLE")
itab.query_table.value = "TRDIR"
Returns the object of the given parameter either an SAP::WAS::Tab, or SAP::WAS::Parm object.
SAP::WAS::Iface#addParm(<SAP::WAS::Parm | SAP::WAS::Tab>)Add an RFC interface parameter to the SAP::WAS::Iface definition - see SAP::WAS::Parm, and SAP::WAS::Tab
SAP::WAS::Iface#getParm(name="name of parameter")Get a named parameter object - returns the object either a SAP::WAS::Parm or SAP::WAS::Tab instance.
SAP::WAS::Iface#resetEmpty all the tables and reset paramters to their default values - useful when you are doing multiple calls.
SAP::WAS::Parm - Ruby extension for parsing and creating an SAP parameter to be added to an RFC Interface.
Generally you would not create one of these manually as it is far easier to use the "discovery" functionality of the SAP::WAS#discover("RFCNAME") method. This returns a fully formed interface object. This is achieved by using standard RFCs supplied by SAP to look up the definition of an RFC interface and any associated structures.
require "SAP/WAS" eparam = SAP::WAS::Parm.new(name, structure, RFCEXPORT, datatype, intlen, decs, default, default)
None
SAP::WAS::Parm.new(name="a name", structure="structure if complex", RFCEXPORT | RFCIMPORT, datatype="SAP datatype", intlen="internal parameter length", decs="decimal places", value="value", default="default value for reset")creates a new RFC Interface Parameter object. This is either an import or export parameter (Export for parameters going into a call, Import for parameter values as a result of a call).
name - Name of the parametertype - type either RFCEXPORT | RFCIMPORTintype - Internal SAP data typelen - Length of the parameter value storeddecimals - number of decimal places | 0default - default value as specified by the Interface definition in SE37structure - SAP::WAS::Struct object for complex paramter types | nilchanged - true | false if a parameter has been changedvalue - external representation of current parameter valueintvalue - internal (SAP) representation of current parameter valueSAP::WAS::Parm#resetReset the parameter value to its default
SAP::WAS::Parm#value=(value="some value")Assign the value of the parameter - automatically converts the external (Ruby) value to the internal SAP representation.
SAP::WAS::Tab - Ruby extension for parsing and creating Tables to be added to an RFC Interface.
Generally you would not create one of these manually as it is far easier to use the "discovery" functionality of the SAP::WAS#discover("RFCNAME") method. This returns a fully formed interface object. This is achieved by using standard RFCs supplied by SAP to look up the definition of an RFC interface and any associated structures.
require "SAP/WAS" tab = SAP::WAS::Tab.new(name="table name", structure=SAP::WAS::Struct, len=int, value=Array))
None
SAP::WAS::Tab.new(name="table name", structure=SAP::WAS::Struct, len=int, value=Array))creates a new RFC Interface Table object. Tables are populated with rows of data to pass into an RFC call, and then refresed with the results of the call afterwards.
name - Name of the parameterlen - Length of the parameter value storedstructure - SAP::WAS::Struct object for complex paramter types | nilvalue - access to the Array object containing the rows of the table (use push to add to it)SAP::WAS::Tab#resetReset the parameter value to its default
SAP::WAS::Tab#emptyAlias for reset
SAP::WAS::Tab#value=(value=Array)Pass in an Array object of rows, that are converted and assigned to the table.
SAP::WAS::Tab#hashRows { |h| code block }Yields to a code block a Hash object representing the name/value pairs for each field of a row of table data - does not shift the values off the table value Array.
SAP::WAS::Tab#rowsreturns an Array of Hash objects representing the name/value pairs for each field of a row of table data - does not shift the values off the table value Array.
SAP::WAS::Struct - Ruby extension for parsing and creating Structure definitions to be added to an RFC Parameter and Table objects.
Generally you would not create one of these manually as it is far easier to use the "discovery" functionality of the SAP::WAS#discover("RFCNAME") method. This returns a fully formed interface object. This is achieved by using standard RFCs supplied by SAP to look up the definition of an RFC interface and any associated structures.
require "SAP/WAS" s = SAP::WAS::Struct.new(name="struct_name") s.addField( SAP::WAS::Field.new(field, exid, decs, intlen, off) ...
or more commonly:
require "SAP/WAS"
was = SAP::WAS.new(...)
str = was.structure("TRDIR")
None
SAP::WAS::Struct.new(name="DDIC structure name"))creates a new RFC Structure object. You must subsequently add fields to this structure for it to be of any use. The resulting structure object is then used for SAP::WAS::Parms, and SAP::WAS::Tab objects to manipulate complex data elements. This is normally created through the SAP::WAS#structure('STRUCT_NAME') method that does an auto look up of the data dictionary definition of a structure, or as a result of SAP::WAS#discover ( which create an entire interface definition).
name - Name of the Structurefields - an Array of the fields of the structureSAP::WAS::Struct#addField(field=SAP::WAS::Field)Add a field object to the structure definition
SAP::WAS::Struct#getField(name="field name")Get a SAP::WAS::Field object from the structure by name.
SAP::WAS::Struct#value=(value=String)Set the value of a structure - this automatically unpacks the string into the structure objects list of fields, and doe sthe SAP to Ruby data type conversions. Returns a Hash object of the fieldname/value pairs of the structure.
SAP::WAS::Struct#valueAutomatically packs the current value of all the structure fields into the structure and returns the complete value as a string (in all the appropriate SAP data types)
SAP::WAS::Field - Container for what is a field within an SAP::WAS::Struct object
Generally you would not create one of these manually as it is far easier to use the "discovery" functionality of the SAP::WAS#discover("RFCNAME") method. This returns a fully formed interface object. This is achieved by using standard RFCs supplied by SAP to look up the definition of an RFC interface and any associated structures.
require "SAP/WAS" f = SAP::WAS::Field.new(field, type, decs, intlen, off) ...
None
SAP::WAS::Field.new(field, type, decs, intlen, off)Create a new field object - these are normally created through the SAP::WAS#structure('STRUCT_NAME') method that does an auto look up of the data dictionary definition of a structure, or as a result of SAP::WAS#discover ( which create an entire interface definition).
name - Name of the fieldtype - Internal SAP data typelen - Length of the field value storeddecimals - number of decimal places | 0value - external representation of current parameter valueSAP::WAS::Field#value=(value=<something>)Assign the value of the field, and then set the length
sapwas is Copyright (c) 2006-2006 Piers Harding. It is free software, and may be redistributed under the terms specified in the README file of the Ruby distribution.
Author:: Piers Harding <piers@ompka.net> Requires:: Ruby 1.8.0 or later