RFC_READ_TABLE with Ruby and SAP::Rfc
Warning: another code sample is included in this post.
I spent a few hours this morning trying to use Piers Harding’s SAP/Rfc library for Ruby to read a table from SAP. I found several examples using other languages (Perl, VBscript, PHP, etc.), but the only Ruby example I could find reads the entire table. Figuring out how to load the “options” took some trial and error.
The idea of this example is to read the “LQUA” table in SAP which stores information about where to find a particular material in the warehouse. The whole thing is wrapped up in its own model so it can be easily called elsewhere in my Rails app:
class SapMaterial < SAP4Rails::Base
function_module :RFC_READ_TABLE
class << self
def find_stock(options={})
material = options[:material]
return nil if material.blank?
rfc = self.RFC_READ_TABLE
rfc.query_table.value = "LQUA"
rfc.delimiter.value = "|"
rfc.options.value = ["MATNR EQ '#{material}'"]
rfc.call()
rfc
end
end
end
This is called with something like this:
stock_locations = SapMaterial.find_stock(:material=>'VOC300V')
Which yields a handy data set containing all the locations and available quantity for the DigiTech Vocalist 300 in the warehouse. This will be used as part of my new scan gun application which directs the shipping department to the various storage bins for picking large orders.
Filed under: Rails, Ruby, Web Projects, scripting | Tagged: RFC, Ruby, SAP