rnsap 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rnsap.rb +48 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f007a1ea7e705a5e9d6071a22eda01f95debc6c5f2190df7720c2cc5359022e
|
4
|
+
data.tar.gz: aab89dd84c193006677e4f952e5703cfde3a28babdb6db445fdad3bc29ca316f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d04e02c23e7fee1f3af3577ede5195c8ba096062d81cd50be1a0c1a60203fffbd5637c24cb167072cbf2e7cf8dec98102485c5f9d339aa298d521e4f2903185a
|
7
|
+
data.tar.gz: 6b6f07b8d353fdfd91db749c67a2b67640d3e8c815a03b648a5ae97f0af720d594299b0d8e5441680a6b4c53a03f02e63fda7e45339685c09f280d82bdb25592
|
data/lib/rnsap.rb
CHANGED
@@ -4,35 +4,59 @@ require 'nwrfc'
|
|
4
4
|
|
5
5
|
include NWRFC
|
6
6
|
|
7
|
+
# Module for SAP helper methods. RnSap allows for a simpler
|
8
|
+
# manner to access SAP servers calling RFC BAPIs.
|
9
|
+
# @author Rogerio Nascimento
|
7
10
|
module RnSap
|
11
|
+
# This is the central class responsible for SAP remote function calls.
|
12
|
+
# Currently the RFC_READ_TABLE BAPI is implemented.
|
13
|
+
#
|
14
|
+
# * TODO
|
15
|
+
#
|
16
|
+
# Implement other SAP BAPIs, such as BAPI_GOODS_MOVEMENT.
|
8
17
|
class Sap
|
18
|
+
# keeps the SAP connection alive during the Sap instance lifecycle
|
9
19
|
attr_reader :conn
|
10
20
|
|
11
21
|
# Constructor requires to receive connection parameters,
|
12
22
|
# a hash containint necessary information to logon to SAP
|
13
|
-
|
14
|
-
|
23
|
+
# @param conn_parms [Hash] SAP Connection Parameters
|
24
|
+
def initialize(conn_parms)
|
25
|
+
@conn = Connection.new(conn_parms)
|
15
26
|
end
|
16
27
|
|
17
|
-
# Closes SAP connection
|
28
|
+
# Closes the instance's SAP connection#
|
18
29
|
def close
|
19
30
|
conn.disconnect
|
20
31
|
end
|
21
32
|
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
|
32
|
-
#
|
33
|
+
# Invokes SAP RFC_READ_TABLE function module remotely, passing
|
34
|
+
# the table to be read and receiving back a list of objects of that
|
35
|
+
# table.
|
36
|
+
#
|
37
|
+
# Example:
|
38
|
+
#
|
39
|
+
# - name: 'lfa1'
|
40
|
+
# - fields: ['name1', 'land1']
|
41
|
+
#
|
42
|
+
# The return will be an array of object <b>Lfa1</b> with the
|
43
|
+
# attributes <b>name1</b> and <b>land1</b>.
|
44
|
+
#
|
45
|
+
# ```ruby
|
46
|
+
# conn = RnSap::Sap.new(conn_parms)
|
47
|
+
# list = conn.read_table('lfa1', ['name1', 'land1'])
|
48
|
+
# list.each do |item|
|
49
|
+
# puts item.name1
|
33
50
|
# end
|
34
|
-
|
35
|
-
|
51
|
+
# ```
|
52
|
+
#
|
53
|
+
# @param name [String] Name of SAP table to be read
|
54
|
+
# @param fields [Array] Array of strings containing the table field names to be retrieved
|
55
|
+
# @param clauses [Array] Optional 'where' clauses applicable to the table reading. respects SAP sintax
|
56
|
+
# @param _row_skip [Integer] number of rows to be skipped within the selected data
|
57
|
+
# @param _row_count [Integer] max number of rows to be returned
|
58
|
+
# @return [Array] Array of the Objects named after the table (i.e. Lfa1, Mara, Bkpf) with its selected columns as attributes (see example)
|
59
|
+
def read_table(name, fields = [], clauses = [], _row_skip = 0, _row_count = 0)
|
36
60
|
if name.is_a?(Hash)
|
37
61
|
fields = name[:fields]
|
38
62
|
clauses = name[:clauses]
|
@@ -101,6 +125,7 @@ module RnSap
|
|
101
125
|
|
102
126
|
attr_writer :conn
|
103
127
|
|
128
|
+
# Dumps to the output the content of an object
|
104
129
|
def dump_instance_variables(obj)
|
105
130
|
puts "Class: #{obj.class} -> #{obj}"
|
106
131
|
obj.instance_variables.map do |var|
|
@@ -108,6 +133,11 @@ module RnSap
|
|
108
133
|
end
|
109
134
|
end
|
110
135
|
|
136
|
+
# Dynamically returns a class instance with the name 'name' and with each
|
137
|
+
# of its fields as an attribute
|
138
|
+
# @param name [String] name of the intended class instance
|
139
|
+
# @param fields [Array] array of strings containing the list of attributes to be available in the class instance
|
140
|
+
# @return [Object] instance of the object 'Name'
|
111
141
|
def get_class_instance(name, fields)
|
112
142
|
# puts "Class name: #{name}"
|
113
143
|
klass = Object.const_set(name, Class.new).new # , Struct.new(*attributes)
|
@@ -118,6 +148,8 @@ module RnSap
|
|
118
148
|
end
|
119
149
|
end
|
120
150
|
|
151
|
+
# class used to represent a Table Column. Used internally
|
152
|
+
# to map SAP's returned working area (WA) into class instances
|
121
153
|
class TableColumn
|
122
154
|
attr_accessor :field_name, :offset, :length, :type, :description
|
123
155
|
end
|