Class SAP::WAS

DESCRIPTION

SAP::WAS - Ruby extension for performing Web Service calls against an SAP Web Application Server

SYNOPSIS

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

Caching Interface and Structure discovery

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/

Class SAP::WAS

Class Methods

SAP::WAS.new(:url => "http://seahorse.local.net:8000/sap/bc/soap/rfc",
lang => "EN",
client => "010",
user => "developer",
passwd => "developer",
trace => nil)

creates a new WAS connection object.

All parameters are named (passed via a hash):
  :url
  :lang
  :client
  :user
  :passwd
  :trace

Attribute Readers

URL - URL of Web Application Service
lang - Language logged in
client - Client number logged in to
user - User name
passwd - Password
trace - Trace mode of connection

Methods

SAP::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#ping

Test that the SAP::WAS object is connects to the SAP Web Application Server system. Returns true or false.

SAP::WAS#sapinfo

Return 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.

Class SAP::WAS::Iface

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.

SYNOPSIS

require "SAP/WAS"
was = SAP::WAS.new( ... )
iface = was.discover('RFC_READ_REPORT')
iface.program.value = "SAPLGRFC"
was.call(iface)

superclass

None

Class Methods

SAP::WAS::Iface.new(name="Z_AN_RFC")

creates a new RFC Interface object.

Attribute Readers

name - Name of the interface
parms - Array of interface parameter objects

Methods

SAP::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#reset

Empty all the tables and reset paramters to their default values - useful when you are doing multiple calls.

Class SAP::WAS::Parm

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.

SYNOPSIS

require "SAP/WAS"
eparam = SAP::WAS::Parm.new(name, structure, RFCEXPORT, datatype, intlen, decs, default, default)

superclass

None

Class Methods

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).

Attribute Readers

name - Name of the parameter
type - type either RFCEXPORT | RFCIMPORT
intype - Internal SAP data type
len - Length of the parameter value stored
decimals - number of decimal places | 0
default - default value as specified by the Interface definition in SE37
structure - SAP::WAS::Struct object for complex paramter types | nil
changed - true | false if a parameter has been changed
value - external representation of current parameter value
intvalue - internal (SAP) representation of current parameter value

Methods

SAP::WAS::Parm#reset

Reset 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.

Class SAP::WAS::Tab

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.

SYNOPSIS

require "SAP/WAS"
tab = SAP::WAS::Tab.new(name="table name", structure=SAP::WAS::Struct, len=int, value=Array))

superclass

None

Class Methods

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.

Attribute Readers

name - Name of the parameter
len - Length of the parameter value stored
structure - SAP::WAS::Struct object for complex paramter types | nil
value - access to the Array object containing the rows of the table (use push to add to it)

Methods

SAP::WAS::Tab#reset

Reset the parameter value to its default

SAP::WAS::Tab#empty

Alias 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#rows

returns 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.

Class SAP::WAS::Struct

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.

SYNOPSIS

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")

superclass

None

Class Methods

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).

Attribute Readers

name - Name of the Structure
fields - an Array of the fields of the structure

Methods

SAP::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#value

Automatically 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)

Class SAP::WAS::Field

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.

SYNOPSIS

require "SAP/WAS"
f = SAP::WAS::Field.new(field, type, decs, intlen, off)
...

superclass

None

Class Methods

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).

Attribute Readers

name - Name of the field
type - Internal SAP data type
len - Length of the field value stored
decimals - number of decimal places | 0
value - external representation of current parameter value

Methods

SAP::WAS::Field#value=(value=<something>)

Assign the value of the field, and then set the length

License

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