要将 PDF 二进制文件上传到 SAP,我可以使用 RFC 功能模块。此 FM 需要两个特定参数:
IC_ARC_OBJECT
= 在 SAP (OAC2) 中定义 mime 类型的文档类IN_CONTENT_LENGHT
= IMPORTING 数据类型,是文件的大小IT_CONTENT
= IMPORTING 结构TBL1024
表,包含文件字节的表,切成大小为 1024 的块ET_MESSAGES
= 只是一个BAPIRET2
检查错误的表(RETURN 表)
函数模块在 Python 程序中成功执行,但是当我在函数模块上中断以检查内容时,IT_CONTENT
我可以看到表格的行没有正确填写:
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 LINE461DB44B3B0AAB12500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 .... LINE8 202020202020202000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000LINE8 202020202020202000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000LINE8 202020202020202000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
IT_CONTENT
使用 FM 检查的预期结果ARCHIVE_OBJECT_GET
应该类似于:
LINE1 255044462D312E330D0A25E2E3CFD30D0A25525354585044463320506172616D65746572733A204452535458680D0A322030206F626A0D0A3C3C0D0A2F46696C7465722033203020520D0A2F4C656E67 LINE2 FA1D555450C8EF41AC263F14BC03C49BDD773CF22BC43FD21B3565DA2DFCCB83D8FFAC7BCBBBEBE6DED0AD68DEA29B349398511824DDDCFFAF41EA7FDADDF67EE61EF3FC303293F7E96351A911F8DE10 LINE3 FB4A559526CD6AED428976E80F8DD0B02517C4178D1EFB73C65792D09CFE5C717883BE38E61ED0AB3ADC0983C103E4338A1B210DA086DA73375E679C0A410F510FDC542BB686A1A4D601DD411A506504 ...
所以问题是只有第一个字节被传输,其余的都是尾随零。
这是否与我做错了什么有关,或者是否可以将二进制文件正确切割成 1024 块并将它们传输到 SAP 的表中。如何在python中使用SAP的字节类型?
非常感谢您的建议/支持。