在我的ABAP程序中,我有两个与XSTRING类型相同的二进制文件的内容。 二进制文件如:docx、xlsx、pptx、pdf等。 我需要将这两个文件内容附加到相同类型的另一个文件中。 例如将两个 PDF 文件合并到另一个 PDF 文件中。
问题是: 最终文件仅包含第一个文件的内容,但文件大小等于两个文件大小的总和。 在调试器中看起来一切都很好!连接看起来也正确!
我做了什么:
这是我的代码:
DATA: lt_bin_old TYPE STANDARD TABLE OF x255.
DATA: lt_bin_new TYPE STANDARD TABLE OF x255.
DATA: lt_bin TYPE STANDARD TABLE OF x255.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = <lv_old_value>
IMPORTING
output_length = lv_size
TABLES
binary_tab = lt_bin_old.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = <lv_new_value>
IMPORTING
output_length = lv_size2
TABLES
binary_tab = lt_bin_new.
lv_size = lv_size + lv_size2.
APPEND LINES OF lt_bin_old TO lt_bin.
APPEND LINES OF lt_bin_new TO lt_bin.
cl_gui_frontend_services=>gui_download(
EXPORTING
bin_filesize = lv_size
filename = lv_fullpath
filetype = 'BIN'
CHANGING
data_tab = lt_bin
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24
).
IF sy-subrc <> 0.
RETURN.
ENDIF.
我也尝试过:
CONCATENATE <lv_old_value> <lv_new_value> INTO <lv_value> IN BYTE MODE.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lv_size
IMPORTING
buffer = <lv_value>
TABLES
binary_tab = lt_bin
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
cl_gui_frontend_services=>gui_download(
EXPORTING
bin_filesize = lv_size
filename = lv_fullpath
filetype = 'BIN'
CHANGING
data_tab = lt_bin
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
not_supported_by_gui = 22
error_no_gui = 23
OTHERS = 24
).
IF sy-subrc <> 0.
RETURN.
ENDIF.
预先感谢您的帮助。
您无法连接两个 xstrings 变量来创建新文件。这样不行。
但是,您可以使用以下类合并两个 PDF 文件,而不是创建一个新文件:
TRY .
DATA(lo_merger) = NEW cl_rspo_pdf_merge( ).
CATCH cx_rspo_pdf_merge INTO DATA(lo_error).
"Error handling
ENDTRY.
lo_merger->check_document( EXPORTING document = lv_pdf_xstring1
IMPORTING error_text = DATA(error_text)
rc = DATA(lv_subrc) ).
IF lv_subrc NE 0 .
"Error handling
ENDIF.
lo_merger->add_document( lv_pdf_xstring1 ).
lo_merger->check_document( EXPORTING document = lv_pdf_xstring2
IMPORTING error_text = error_text
rc = lv_subrc ).
IF lv_subrc NE 0 .
"Error handling
ENDIF.
lo_merger->add_document( lv_pdf_xstring2 ).
lo_merger->merge_documents( IMPORTING merged_document = DATA(lv_pdf_xstring_result)
rc = lv_subrc ).
两个 xstring lv_pdf_xstring1 和 lv_pdf_xstring2 是源,lv_pdf_xstring_result 将是结果。
我希望这有帮助 :)