rnsap 0.1.8 → 0.4.0
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 +102 -14
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f44b42cb85ce971b63caafa40e57062a287861ac3dc221f5627d931c9d2792d6
|
4
|
+
data.tar.gz: 5403af8af25304f9de38fecb09f380e7ccd9a9c9bb684ae63f5f080e51d44aab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db5a0dd7f38e5b31dc1136dfda6d6bfba3db5ba8d437fc13711f64a6c6f060aa92148a1e9d996e7612db6dc479c566d9945aab06b782012683b3aa55ca7281ec
|
7
|
+
data.tar.gz: ebcdcf12bae1cad45e498748b444da864b8e3f3de67031ab8431c16caf43454f985f004b11be060ef8f32f3a863119417d950cf44cb9b8d2a23d7c7be9338a57
|
data/lib/rnsap.rb
CHANGED
@@ -1,22 +1,69 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'nwrfc'
|
4
|
-
require 'json'
|
5
|
-
require 'yaml'
|
6
4
|
|
7
5
|
include NWRFC
|
8
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
|
9
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.
|
10
17
|
class Sap
|
18
|
+
# keeps the SAP connection alive during the Sap instance lifecycle
|
11
19
|
attr_reader :conn
|
12
20
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
21
|
+
# Constructor requires to receive connection parameters,
|
22
|
+
# a hash containint necessary information to logon to SAP
|
23
|
+
# @param conn_parms [Hash] SAP Connection Parameters
|
24
|
+
def initialize(conn_parms)
|
25
|
+
@conn = Connection.new(conn_parms)
|
17
26
|
end
|
18
27
|
|
19
|
-
|
28
|
+
# Closes the instance's SAP connection#
|
29
|
+
def close
|
30
|
+
conn.disconnect
|
31
|
+
end
|
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
|
50
|
+
# end
|
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)
|
60
|
+
if name.is_a?(Hash)
|
61
|
+
fields = name[:fields]
|
62
|
+
clauses = name[:clauses]
|
63
|
+
_row_skip = name[:row_skip]
|
64
|
+
_row_count = name[:row_count]
|
65
|
+
name = name[:name]
|
66
|
+
end
|
20
67
|
klass_name = name.capitalize
|
21
68
|
fields_up = []
|
22
69
|
fields_down = []
|
@@ -24,19 +71,28 @@ module RnSap
|
|
24
71
|
fields_up << field.upcase
|
25
72
|
fields_down << field.downcase
|
26
73
|
end
|
74
|
+
|
27
75
|
base_obj = get_class_instance(klass_name, fields_down)
|
28
76
|
|
29
77
|
#-- Read Table
|
30
|
-
dump_instance_variables(conn)
|
78
|
+
# dump_instance_variables(conn)
|
31
79
|
fn_read_table = @conn.get_function('RFC_READ_TABLE')
|
32
80
|
fc_read_table = fn_read_table.get_function_call
|
33
81
|
|
34
82
|
fc_read_table[:QUERY_TABLE] = name.upcase
|
83
|
+
fc_read_table[:ROWSKIPS] = _row_skip
|
84
|
+
fc_read_table[:ROWCOUNT] = _row_count
|
85
|
+
fc_read_table[:DELIMITER] = '|'
|
35
86
|
fields_up.each do |field|
|
36
87
|
row = fc_read_table[:FIELDS].new_row
|
37
88
|
row[:FIELDNAME] = field
|
38
89
|
end
|
39
90
|
|
91
|
+
clauses.each do |clause|
|
92
|
+
row = fc_read_table[:OPTIONS].new_row
|
93
|
+
row[:TEXT] = clause
|
94
|
+
end
|
95
|
+
|
40
96
|
fc_read_table.invoke
|
41
97
|
|
42
98
|
columns_hash = {}
|
@@ -65,15 +121,45 @@ module RnSap
|
|
65
121
|
list
|
66
122
|
end
|
67
123
|
|
68
|
-
|
69
|
-
|
70
|
-
conn.
|
124
|
+
def preq_detail(preq = 0, acc_assignment = 'X', item_text = 'X', services = 'X', services_texts = 'X')
|
125
|
+
#-- Execute BAPI_REQUISITION_GETDETAIL
|
126
|
+
fn_preq_detail = @conn.get_function('BAPI_REQUISITION_GETDETAIL')
|
127
|
+
fc_preq_detail = fn_preq_detail.get_function_call
|
128
|
+
|
129
|
+
fc_preq_detail[:NUMBER] = preq
|
130
|
+
fc_preq_detail[:ACCOUNT_ASSIGNMENT] = acc_assignment
|
131
|
+
fc_preq_detail[:ITEM_TEXTS] = item_text
|
132
|
+
fc_preq_detail[:SERVICES] = services
|
133
|
+
fc_preq_detail[:SERVICE_TEXTS] = services_texts
|
134
|
+
|
135
|
+
fc_preq_detail.invoke
|
136
|
+
|
137
|
+
list = []
|
138
|
+
avoid_list = ['!','__','+', '=','!', '?','~','>', '<']
|
139
|
+
fc_preq_detail[:REQUISITION_ITEMS].each do |row|
|
140
|
+
preq = PreqItem.new
|
141
|
+
preq.class.instance_methods.each do |method_name|
|
142
|
+
begin
|
143
|
+
if preq.respond_to?("#{method_name}=")
|
144
|
+
unless avoid_list.any? { |word| method_name.to_s.include?(word)}
|
145
|
+
value = row[method_name]
|
146
|
+
eval("preq.#{method_name} = '#{value}'")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
rescue
|
150
|
+
end
|
151
|
+
end
|
152
|
+
list.push(preq)
|
153
|
+
end
|
154
|
+
|
155
|
+
list
|
71
156
|
end
|
72
157
|
|
73
158
|
private
|
74
159
|
|
75
160
|
attr_writer :conn
|
76
161
|
|
162
|
+
# Dumps to the output the content of an object
|
77
163
|
def dump_instance_variables(obj)
|
78
164
|
puts "Class: #{obj.class} -> #{obj}"
|
79
165
|
obj.instance_variables.map do |var|
|
@@ -81,6 +167,11 @@ module RnSap
|
|
81
167
|
end
|
82
168
|
end
|
83
169
|
|
170
|
+
# Dynamically returns a class instance with the name 'name' and with each
|
171
|
+
# of its fields as an attribute
|
172
|
+
# @param name [String] name of the intended class instance
|
173
|
+
# @param fields [Array] array of strings containing the list of attributes to be available in the class instance
|
174
|
+
# @return [Object] instance of the object 'Name'
|
84
175
|
def get_class_instance(name, fields)
|
85
176
|
# puts "Class name: #{name}"
|
86
177
|
klass = Object.const_set(name, Class.new).new # , Struct.new(*attributes)
|
@@ -91,7 +182,4 @@ module RnSap
|
|
91
182
|
end
|
92
183
|
end
|
93
184
|
|
94
|
-
class TableColumn
|
95
|
-
attr_accessor :field_name, :offset, :length, :type, :description
|
96
|
-
end
|
97
185
|
end
|
metadata
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rnsap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rogerio Nascimento
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2020-04-30 00:00:00.000000000 Z
|
@@ -24,8 +24,23 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.0.9
|
27
|
-
|
28
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: By encapsulating SAPs NW RFC library calls, Ruby routines can access
|
42
|
+
SAP power in a simpler manner
|
43
|
+
email:
|
29
44
|
executables: []
|
30
45
|
extensions: []
|
31
46
|
extra_rdoc_files: []
|
@@ -36,7 +51,7 @@ licenses:
|
|
36
51
|
- MIT
|
37
52
|
metadata:
|
38
53
|
source_code_uri: https://github.com/rnasc/rnsap
|
39
|
-
post_install_message:
|
54
|
+
post_install_message:
|
40
55
|
rdoc_options: []
|
41
56
|
require_paths:
|
42
57
|
- lib
|
@@ -51,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
66
|
- !ruby/object:Gem::Version
|
52
67
|
version: '0'
|
53
68
|
requirements: []
|
54
|
-
rubygems_version: 3.
|
55
|
-
signing_key:
|
69
|
+
rubygems_version: 3.2.3
|
70
|
+
signing_key:
|
56
71
|
specification_version: 4
|
57
72
|
summary: Facilitates SAP RFC calls in Ruby
|
58
73
|
test_files: []
|