forked from piersharding/ruby-sapnwrfc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stfc_connection.rb
executable file
·62 lines (52 loc) · 1.47 KB
/
stfc_connection.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/ruby
# Sort out UNICODE
$KCODE = 'u'
# Stupid inter release gem dance...
require 'rubygems'
gem 'sapnwrfc'
require 'sapnwrfc'
require 'getopts'
def usage
$stderr.print "\n
Usage: #{File.basename($0)} -t [-h -s -c -u -p -l]
Options
-h ashost
-s sysnr
-c client
-u user
-p passwd
-l lang
-t Text to be echoed
"
exit!
end
# Coneciton option defaults
conn_opts = { :ashost => "ubuntu.local.net", :sysnr => "01", :client => "001", :user => "developer", :passwd => "developer", :lang => "EN", :loglevel => "warn" }
# get options and check
getopts('h:s:c:u:p:l:t:')
usage unless $OPT_t
conn_opts[:ashost] = $OPT_h if $OPT_h
conn_opts[:sysnr] = $OPT_s if $OPT_s
conn_opts[:client] = $OPT_c if $OPT_c
conn_opts[:user] = $OPT_u if $OPT_u
conn_opts[:passwd] = $OPT_p if $OPT_p
conn_opts[:lang] = $OPT_l if $OPT_l
SAP_LOGGER.warn "Connection Options: #{conn_opts.inspect}\n"
begin
conn = SAPNW::Base.rfc_connect(conn_opts)
attrib = conn.connection_attributes
SAP_LOGGER.warn "Connection Attributes: #{attrib.inspect}\n"
fds = conn.discover("STFC_CONNECTION")
fs = fds.new_function_call
fs.REQUTEXT = $OPT_t
fs.invoke
SAP_LOGGER.warn "RESPTEXT: #{fs.RESPTEXT}\n"
SAP_LOGGER.warn "ECHOTEXT: #{fs.ECHOTEXT}\n"
conn.close
rescue SAPNW::RFC::ConnectionException => e
SAP_LOGGER.warn "ConnectionException: #{e.error}\n"
raise "gone"
rescue SAPNW::RFC::FunctionCallException => e
SAP_LOGGER.warn "FunctionCallException: #{e.error}\n"
raise "bork!"
end