Skip to content

Commit 7f77f6f

Browse files
committed
README
1 parent 6c8e90b commit 7f77f6f

7 files changed

Lines changed: 330 additions & 184 deletions

File tree

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"restructuredtext.confPath": "${workspaceFolder}/doc",
3-
"python.pythonPath": "/Users/d037732/.pyenv/versions/py374/bin/python"
3+
"python.pythonPath": "/Users/d037732/.pyenv/versions/py2715/bin/python"
44
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ SAP NW RFC Library is fully backwards compatible, supporting all NetWeaver syste
3131

3232
On Windows platforms the Microsoft Visual C++ 2005 Service Pack 1 Redistributable Package (KB973544), or [newer](https://www.microsoft.com/en-us/download/details.aspx?id=48145), must be installed, per [SAP Note 1375494 - SAP system does not start after applying SAP kernel patch](https://launchpad.support.sap.com/#/notes/1375494).
3333

34-
:exclamation: Due to a [change introduced with Python 3.8 for Windows](https://docs.python.org/3.8/whatsnew/3.8.html#bpo-36085-whatsnew), PATH directories are no longer searched for DLL. The SAP NWRFC SDK lib path is no longer required on PATH.
34+
:exclamation: Due to a [change introduced with Python 3.8 for Windows](https://docs.python.org/3.8/whatsnew/3.8.html#bpo-36085-whatsnew), PATH directories are no longer searched for DLL. The SAP NWRFC SDK lib path is no longer required on PATH, for Python >= 3.8.
3535

3636
### macOS
3737

material/__init__.py

Whitespace-only changes.

material/config.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# -*- coding: utf-8 -*
2+
3+
import datetime
4+
5+
try:
6+
from configparser import ConfigParser
7+
8+
COPA = ConfigParser()
9+
fc = open("tests/pyrfc.cfg", "r")
10+
COPA.read_file(fc)
11+
except ImportError as ex:
12+
from configparser import config_parser
13+
14+
COPA = config_parser()
15+
COPA.read_file("tests/pyrfc.cfg")
16+
17+
18+
# Numeric types
19+
#
20+
# ABAP: https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abenddic_builtin_types_intro.htm
21+
# JavaScript: https://www.ecma-international.org/ecma-262/10.0/index.html#Title
22+
#
23+
24+
RFC_MATH = {
25+
"RFC_INT1": {"MIN": 0, "MAX": 255},
26+
"RFC_INT2": {"NEG": -32768, "POS": 32767},
27+
"RFC_INT4": {"NEG": -2147483648, "POS": 2147483647},
28+
"RFC_INT8": {"NEG": -9223372036854775808, "POS": 9223372036854775807},
29+
"FLOAT": {
30+
"NEG": {"MIN": "-2.2250738585072014E-308", "MAX": "-1.7976931348623157E+308"},
31+
"POS": {"MIN": "2.2250738585072014E-308", "MAX": "1.7976931348623157E+308"},
32+
},
33+
"DECF16": {
34+
"NEG": {"MIN": "-1E-383", "MAX": "-9.999999999999999E+384"},
35+
"POS": {"MIN": "1E-383", "MAX": "9.999999999999999E+384"},
36+
},
37+
"DECF34": {
38+
"NEG": {"MIN": "-1E-6143", "MAX": "-9.999999999999999999999999999999999E+6144"},
39+
"POS": {"MIN": "1E-6143", "MAX": "9.999999999999999999999999999999999E+6144"},
40+
},
41+
"DATE": {"MIN": "00010101", "MAX": "99991231"},
42+
"TIME": {"MIN": "000000", "MAX": "235959"},
43+
}
44+
45+
46+
def get_error(ex):
47+
error = {}
48+
ex_type_full = str(type(ex))
49+
error["type"] = ex_type_full[ex_type_full.rfind(".") + 1 : ex_type_full.rfind("'")]
50+
error["code"] = ex.code if hasattr(ex, "code") else "<None>"
51+
error["key"] = ex.key if hasattr(ex, "key") else "<None>"
52+
error["message"] = ex.message.split("\n")
53+
error["msg_class"] = ex.msg_class if hasattr(ex, "msg_class") else "<None>"
54+
error["msg_type"] = ex.msg_type if hasattr(ex, "msg_type") else "<None>"
55+
error["msg_number"] = ex.msg_number if hasattr(ex, "msg_number") else "<None>"
56+
error["msg_v1"] = ex.msg_v1 if hasattr(ex, "msg_v1") else "<None>"
57+
return error
58+
59+
60+
def ABAP_to_python_date(abap_date):
61+
return datetime.datetime.strptime(abap_date, "%Y%m%d").date()
62+
63+
64+
def ABAP_to_python_time(abap_time):
65+
return datetime.datetime.strptime(abap_time, "%H%M%S").time()
66+
67+
68+
def python_to_ABAP_date(py_date):
69+
return "{:04d}{:02d}{:02d}".format(py_date.year, py_date.month, py_date.day)
70+
71+
72+
def python_to_ABAP_time(py_time):
73+
return "{:02d}{:02d}{:02d}".format(py_time.hour, py_time.minute, py_time.second)
74+
75+
76+
CONFIG_SECTIONS = COPA._sections
77+
CONNECTION_INFO = CONFIG_SECTIONS["coevi51"]
78+
UNICODETEST = "ทดสอบสร้างลูกค้าจากภายนอกครั้งที่" * 7
79+
80+
PARAMS = CONNECTION_INFO
81+

material/datatypes.py

Lines changed: 47 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -1,180 +1,52 @@
11
# -*- coding: utf-8 -*-
22
from pyrfc import *
33
from decimal import Decimal
4-
5-
connection_info = {
6-
'user': 'demo',
7-
'passwd': 'welcome',
8-
'ashost': '10.68.110.51',
9-
'sysnr': '00',
10-
'lang': 'EN',
11-
'client': '620',
12-
'sysid': 'MME'
13-
}
14-
15-
conn = Connection(**connection_info)
16-
17-
is_input = dict(
18-
19-
# Character
20-
ZCHAR=u'Hällö SÄP!',
21-
ZCLNT='510',
22-
ZUNIT_DTEL='KGM',
23-
ZCUKY_DTEL='USD',
24-
ZLANG='e',
25-
26-
# Date, time
27-
ZDATS='20161231', # datetime.date(2011,10,17),
28-
ZTIMS='123456', # datetime.time(12,34,56),
29-
30-
# Integer
31-
ZINT1=2 ** 8 - 1, # 255
32-
ZINT2=2 ** 15 - 1, # 32767
33-
ZINT4=2 ** 31 - 1, # 2147483647
34-
35-
# Numeric
36-
ZACCP='201805',
37-
ZNUMC='123456',
38-
39-
ZPREC=2,
40-
41-
# String
42-
ZRAW=bytes('abc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'),
43-
ZRAWSTRING=bytes('四周远处都能望见'),
44-
ZSTRING=u'\u0001\uf4aa',
45-
ZSSTRING=u'四周远处都能望见'
4+
import datetime
5+
from config import CONNECTION_INFO, RFC_MATH
6+
7+
8+
conn_strip = Connection({"rstrip": True}, **CONNECTION_INFO)
9+
hello = u"Hällo SAP! "
10+
result = conn_strip.call("STFC_CONNECTION", REQUTEXT=hello)
11+
# assert len(result["RESPTEXT"]) == len(result["ECHOTEXT"])
12+
# self.conn_strip.close()
13+
14+
"""
15+
16+
client = Connection(**CONNECTION_INFO)
17+
18+
19+
uc = u"四周远处都"
20+
uc = u"ÄÜ"
21+
uc = u"fgh"
22+
buc = uc.encode("utf-8")
23+
print(len(uc), uc)
24+
print(len(buc), buc)
25+
26+
ZRAW = buc
27+
IS_INPUT = {"ZRAW": ZRAW, "ZRAWSTRING": ZRAW}
28+
output = client.call("/COE/RBP_FE_DATATYPES", IS_INPUT=IS_INPUT, IV_COUNT=0)[
29+
"ES_OUTPUT"
30+
]
31+
print(len(ZRAW), ZRAW)
32+
print(len(output["ZRAW"]), output["ZRAW"])
33+
34+
35+
imp = dict(
36+
RFCFLOAT=1.23456789,
37+
RFCINT2=0x7FFE,
38+
RFCINT1=0x7F,
39+
RFCCHAR4=u"bcde",
40+
RFCINT4=0x7FFFFFFE,
41+
RFCHEX3=buc,
42+
RFCCHAR1=u"a",
43+
RFCCHAR2=u"ij",
44+
RFCTIME="123456", # datetime.time(12,34,56),
45+
RFCDATE="20161231", # datetime.date(2011,10,17),
46+
RFCDATA1=u"k" * 50,
47+
RFCDATA2=u"l" * 50,
4648
)
49+
result = client.call("STFC_STRUCTURE", IMPORTSTRUCT=imp)["ECHOSTRUCT"]
4750
48-
result = conn.call('/COE/RBP_FE_DATATYPES', IS_INPUT=is_input)['ES_OUTPUT']
49-
for k in is_input:
50-
if is_input[k] != result[k]:
51-
print k, type(result[k])
52-
if str(is_input[k]) != str(result[k]):
53-
print '!', k, is_input[k], result[k]
54-
55-
56-
is_input = dict(
57-
# Float
58-
ZFLTP='0.123456789',
59-
60-
# Decimal
61-
ZDEC='12345.67',
62-
63-
# Currency, Quantity
64-
ZCURR='1234.56',
65-
ZQUAN='12.3456',
66-
ZQUAN_SIGN='-12.345',
67-
)
68-
69-
result = conn.call('/COE/RBP_FE_DATATYPES', IS_INPUT=is_input)['ES_OUTPUT']
70-
for key, in_val in is_input.iteritems():
71-
out_val = result[key]
72-
if type(in_val) != type(out_val):
73-
if str(in_val) != str(out_val):
74-
print 'str:', k, in_val, out_val
75-
else:
76-
if in_val != result[key]:
77-
print key, in_val, out_val
78-
79-
is_input = dict(
80-
# Float
81-
ZFLTP=0.123456789,
82-
83-
# Decimal
84-
ZDEC=12345.67,
85-
86-
# Currency, Quantity
87-
ZCURR=1234.56,
88-
ZQUAN=12.3456,
89-
ZQUAN_SIGN=-12.345,
90-
)
91-
92-
93-
result = conn.call('/COE/RBP_FE_DATATYPES['ES_OUTPUT']
94-
for key, in_value in is_input.iteritems():
95-
out_value = result[key]
96-
if type(in_value) != type(out_value):
97-
if str(in_value) != str(out_value):
98-
print 'str:', k, in_value, out_value
99-
else:
100-
if in_value != result[key]:
101-
print key, in_value, out_value
102-
103-
is_input = dict(
104-
# Float
105-
ZFLTP=Decimal('0.123456789'),
106-
107-
# Decimal
108-
ZDEC=Decimal('12345.67'),
109-
110-
# Currency, Quantity
111-
ZCURR=Decimal('1234.56'),
112-
ZQUAN=Decimal('12.3456'),
113-
ZQUAN_SIGN=Decimal('-12.345'),
114-
)
115-
116-
117-
result = conn.call('/COE/RBP_FE_DATATYPES', IS_INPUT=is_input)['ES_OUTPUT']
118-
for key, in_value in is_input.iteritems():
119-
out_value = result[key]
120-
if type(in_value) != type(out_value):
121-
if str(in_value) != str(out_value):
122-
print 'str:', k, in_value, out_value
123-
else:
124-
if in_value != result[key]:
125-
print key, in_value, out_value
126-
127-
INPUTS = {
128-
'dec': dict(
129-
# Float
130-
ZFLTP=Decimal('0.123456789'),
131-
132-
# Decimal
133-
ZDEC=Decimal('12345.67'),
134-
135-
# Currency, Quantity
136-
ZCURR=Decimal('1234.56'),
137-
ZQUAN=Decimal('12.3456'),
138-
ZQUAN_SIGN=Decimal('-12.345'),
139-
),
140-
141-
'numbers': dict(
142-
# Float
143-
ZFLTP=0.123456789,
144-
145-
# Decimal
146-
ZDEC=12345.67,
147-
148-
# Currency, Quantity
149-
ZCURR=1234.56,
150-
ZQUAN=12.3456,
151-
ZQUAN_SIGN=-12.345
152-
),
153-
154-
'strings': dict(
155-
# Float
156-
ZFLTP='0.123456789',
157-
158-
# Decimal
159-
ZDEC='12345.67',
160-
161-
# Currency, Quantity
162-
ZCURR='1234.56',
163-
ZQUAN='12.3456',
164-
ZQUAN_SIGN='-12.345',
165-
)
166-
}
167-
168-
for in_type in INPUTS:
169-
result = conn.call('/COE/RBP_FE_DATATYPES',
170-
IS_INPUT=INPUTS[in_type])['ES_OUTPUT']
171-
print
172-
print in_type
173-
for k in is_input:
174-
in_val = is_input[k]
175-
out_val = result[k]
176-
print k, type(in_val), type(out_val), in_val, out_val
177-
if type(in_val) != type(out_val):
178-
assert(str(in_val) == str(out_val))
179-
else:
180-
assert(in_val == out_val)
51+
print(len(result["RFCHEX3"]), result["RFCHEX3"])
52+
"""

material/test.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,36 @@
33
from configparser import ConfigParser
44
from pyrfc import Connection, get_nwrfclib_version
55

6-
config = ConfigParser()
7-
config.read('pyrfc.cfg')
8-
params = config._sections['test']
6+
try:
7+
from configparser import ConfigParser
98

10-
conn = Connection(**params)
9+
COPA = ConfigParser()
10+
fc = open("tests/pyrfc.cfg", "r")
11+
COPA.read_file(fc)
12+
except ImportError as ex:
13+
from configparser import config_parser
1114

12-
print('Platform:', system(), release())
13-
print('Python version:', version_info)
14-
print('SAP NW RFC:', get_nwrfclib_version())
15+
COPA = config_parser()
16+
COPA.read_file("tests/pyrfc.cfg")
17+
CONFIG_SECTIONS = COPA._sections
18+
CONNECTION_INFO = CONFIG_SECTIONS["coevi51"]
1519

1620

21+
conn = Connection(**CONNECTION_INFO)
22+
23+
print("Platform:", system(), release())
24+
print("Python version:", version_info)
25+
print("SAP NW RFC:", get_nwrfclib_version())
26+
27+
str_unicode = "四周远处都能望见"
28+
str_unicode = "四周远处都"
29+
ZRAW = bytes(str_unicode, encoding="utf-8") # or str_unicode.encode("utf-8")
30+
IS_INPUT = {"ZRAW": ZRAW, "ZRAWSTRING": ZRAW}
31+
output = conn.call("/COE/RBP_FE_DATATYPES2", IV_INT1=1)
32+
print(output)
33+
34+
"""[summary]
35+
1736
result = conn.call('/COE/RBP_PAM_SERVICE_ORD_CHANG', IV_ORDERID='4711', IT_NOTICE_NOTIFICATION=[{'': 'ABCD'}, {'': 'XYZ'}])
1837
1938
for line in result['ET_STRING']:
@@ -30,3 +49,4 @@
3049
for line in result['ET_TABLE']:
3150
print line
3251
52+
"""

0 commit comments

Comments
 (0)