Pyrfc:RFCTable 类型 TBL1024
Pyrfc: RFCTable type TBL1024
要将 PDF 二进制文件上传到 SAP,我可以使用 RFC 功能模块。这个FM需要两个特定的参数:
IC_ARC_OBJECT
=文档class定义SAP中的mime类型
(OAC2)
IN_CONTENT_LENGHT
= IMPORTING数据类型,就是文件的大小
IT_CONTENT
= IMPORTING table of structure TBL1024
, table with the
文件的字节,切成大小为 1024 的块
ET_MESSAGES
= 只是一个 BAPIRET2
table 来检查错误 (RETURN table)
功能模块在 Python 程序中成功执行,但是当我中断功能模块检查 IT_CONTENT
的内容时,我可以看到 table 填写不正确:
提取FM的python程序调用:
arc_object = "ZZ_PDF"
content = Arc.get_arc_content(filename)
size = Arc.get_size(filename)
messages = []
result = connection.call("ZZ_UPLOAD_FILE",
IC_ARC_OBJECT = arc_object,
IN_CONTENT_LENGTH = str(size),
IT_CONTENT = content,
ET_MESSAGES = messages)
messages = result['ET_MESSAGES']
for mes in messages:
print mes['MESSAGE']
提取python函数Arc.get_arc_content(filename)
:
def get_arc_content(filename="file.pdf"):
maxLineLength = 1024
structure = []
if filename == '':
filename = 'file.pdf'
with open(filename, 'rb') as file1:
f = file1.read()
n = 1024
fl = [f[i:i + n] for i in range(0, len(f), n)]
content = []
for line in fl:
lineapp = {
u"LINE": line
}
print len(line)
content.append(lineapp)
return content
SAP 中的结果是以下参数:
IN_CONTENT_LENGHT
= 000000007945 (7.8 kb)
IT_CONTENT
= 8 x 1 行:(4 行)
LINE1 255044462D312E3300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
LINE2 B89B067867673EAB00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
LINE3 5BF4CB23B9A7513700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
LINE4 61DB44B3B0AAB12500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
....
LINE8
202020202020202000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
IT_CONTENT
的预期结果,与 FM ARCHIVE_OBJECT_GET
核对后应该是这样的:
LINE1
255044462D312E330D0A25E2E3CFD30D0A25525354585044463320506172616D65746572733A204452535458680D0A322030206F626A0D0A3C3C0D0A2F46696C7465722033203020520D0A2F4C656E67
LINE2
FA1D555450C8EF41AC263F14BC03C49BDD773CF22BC43FD21B3565DA2DFCCB83D8FFAC7BCBBBEBE6DED0AD68DEA29B349398511824DDDCFFAF41EA7FDADDF67EE61EF3FC303293F7E96351A911F8DE10
LINE3
FB4A559526CD6AED428976E80F8DD0B02517C4178D1EFB73C65792D09CFE5C717883BE38E61ED0AB3ADC0983C103E4338A1B210DA086DA73375E679C0A410F510FDC542BB686A1A4D601DD411A506504
...
所以问题是只有第一个字节被传输,其余的都是尾随零。
这是否与我做错了什么有关,或者无法将二进制文件正确切割成 1024 的块并将它们传输到 table 到 SAP。 python?
如何使用SAP的字节类型
非常感谢您的 suggestions/support。
pyrfc-1.9.4-py2.7-win-amd64.egg 解决了这个问题。
似乎是 Windows + PyRFC 1.9.3 版本问题,1.9.4 分发完美,
非常感谢Srdjan Boskovic的支持
要将 PDF 二进制文件上传到 SAP,我可以使用 RFC 功能模块。这个FM需要两个特定的参数:
IC_ARC_OBJECT
=文档class定义SAP中的mime类型 (OAC2)IN_CONTENT_LENGHT
= IMPORTING数据类型,就是文件的大小IT_CONTENT
= IMPORTING table of structureTBL1024
, table with the 文件的字节,切成大小为 1024 的块
ET_MESSAGES
= 只是一个BAPIRET2
table 来检查错误 (RETURN table)
功能模块在 Python 程序中成功执行,但是当我中断功能模块检查 IT_CONTENT
的内容时,我可以看到 table 填写不正确:
提取FM的python程序调用:
arc_object = "ZZ_PDF"
content = Arc.get_arc_content(filename)
size = Arc.get_size(filename)
messages = []
result = connection.call("ZZ_UPLOAD_FILE",
IC_ARC_OBJECT = arc_object,
IN_CONTENT_LENGTH = str(size),
IT_CONTENT = content,
ET_MESSAGES = messages)
messages = result['ET_MESSAGES']
for mes in messages:
print mes['MESSAGE']
提取python函数Arc.get_arc_content(filename)
:
def get_arc_content(filename="file.pdf"):
maxLineLength = 1024
structure = []
if filename == '':
filename = 'file.pdf'
with open(filename, 'rb') as file1:
f = file1.read()
n = 1024
fl = [f[i:i + n] for i in range(0, len(f), n)]
content = []
for line in fl:
lineapp = {
u"LINE": line
}
print len(line)
content.append(lineapp)
return content
SAP 中的结果是以下参数:
IN_CONTENT_LENGHT
= 000000007945 (7.8 kb)IT_CONTENT
= 8 x 1 行:(4 行)
LINE1 255044462D312E3300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 LINE2 B89B067867673EAB00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 LINE3 5BF4CB23B9A7513700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 LINE4 61DB44B3B0AAB12500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 .... LINE8 202020202020202000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
IT_CONTENT
的预期结果,与 FM ARCHIVE_OBJECT_GET
核对后应该是这样的:
LINE1 255044462D312E330D0A25E2E3CFD30D0A25525354585044463320506172616D65746572733A204452535458680D0A322030206F626A0D0A3C3C0D0A2F46696C7465722033203020520D0A2F4C656E67 LINE2 FA1D555450C8EF41AC263F14BC03C49BDD773CF22BC43FD21B3565DA2DFCCB83D8FFAC7BCBBBEBE6DED0AD68DEA29B349398511824DDDCFFAF41EA7FDADDF67EE61EF3FC303293F7E96351A911F8DE10 LINE3 FB4A559526CD6AED428976E80F8DD0B02517C4178D1EFB73C65792D09CFE5C717883BE38E61ED0AB3ADC0983C103E4338A1B210DA086DA73375E679C0A410F510FDC542BB686A1A4D601DD411A506504 ...
所以问题是只有第一个字节被传输,其余的都是尾随零。
这是否与我做错了什么有关,或者无法将二进制文件正确切割成 1024 的块并将它们传输到 table 到 SAP。 python?
如何使用SAP的字节类型非常感谢您的 suggestions/support。
pyrfc-1.9.4-py2.7-win-amd64.egg 解决了这个问题。
似乎是 Windows + PyRFC 1.9.3 版本问题,1.9.4 分发完美,
非常感谢Srdjan Boskovic的支持