2020 Nov 18 7:00 PM
I added some comments for solution. Please check below codes.
************************************************************************************************************
Hi all,
I want to get smartform output from another system by using RFC function call. I made a Z* RFC function which returns PDF's
- OTF Data
- Binary Data
- XString
- Base64
Why I need that?
We have three different systems and source system. Source system has a smartform itself. Three system will be connected source system by using RFC and source system will return PDF data to which system call it.
RFC connection user is system user, not a dialog. That's why, I couldn't run any GUI services on source system. If it was dialog, there won't be any problem.
When I try download PDF data on caller system by using GUI_DOWNLOAD, PDF file is generated as damaged file and it won't be opened.
Source and call system versions are different.
What could be reason of it?
Thanks,
From Caller System; It is damaged.
From Source System; It works.
Here is what I've used on source system to generate PDF
ls_output_options-tdarmod = '1'.
ls_output_options-tdnoprint = 'X'.
ls_output_options-tddest = 'LOCL'.
ls_output_options-tdimmed = 'X'.
ls_output_options-tdcopies = 1.
ls_output_options-tdreceiver = sy-uname.
ls_control_params-no_dialog = 'X'.
ls_control_params-getotf = 'X'.
ls_control_params-langu = 'E'.
ls_control_params-device = 'PRINTER'.
After getting OTF; Conversions and Download
*Solution 1: Use CONVERT_OTF instead of CONVERT_OTF_2_PDF, if you need XSTRING
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = ef_bin_filesize
bin_file = ef_xstring
TABLES
otf = lt_otf
lines = et_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
IF sy-subrc <> 0.
ENDIF.
* CALL FUNCTION 'CONVERT_OTF_2_PDF'
* EXPORTING
* use_otf_mc_cmd = space
* IMPORTING
* bin_filesize = ef_bin_filesize
* TABLES
* otf = ls_job_output_info-otfdata
* doctab_archive = lt_docs
* lines = et_lines
* EXCEPTIONS
* err_conv_not_possible = 1
* err_otf_mc_noendmarker = 2
* OTHERS = 3.
* IF sy-subrc NE 0.
* RETURN.
* ENDIF.
* CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
* EXPORTING
* input_length = ef_bin_filesize
* IMPORTING
* buffer = ef_xstring
* TABLES
* binary_tab = et_lines
* EXCEPTIONS
* failed = 1
* OTHERS = 2.
* IF sy-subrc NE 0.
* RETURN.
* ENDIF.
CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
EXPORTING
input = ef_xstring
IMPORTING
output = ef_base64.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = ef_bin_filesize
filename = 'C:\Users\onder\Desktop\From_Source.pdf'
filetype = 'BIN'
CHANGING
data_tab = et_lines[]
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.
On caller system,
CALL FUNCTION 'ZGETPDF' DESTINATION ap_dest
EXPORTING
it_belnr = lt_belnr[]
IMPORTING
et_message = lt_ret[]
ef_bin_filesize = lf_bin_filesize
ef_xstring = lf_xstring
ef_base64 = lf_base64
TABLES
et_lines = lt_lines
EXCEPTIONS
communication_failure = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc NE 0.
RETURN.
ENDIF.
* CALL FUNCTION 'SCMS_BASE64_DECODE_STR'
* EXPORTING
* input = lf_base64
* IMPORTING
* output = lf_xstring
* EXCEPTIONS
* failed = 1
* OTHERS = 2.
*
* Solution 2: lt_lines must be SOLIX_TAB instead of TLINE.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lf_xstring
TABLES
binary_tab = lt_solix_tab.
* CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
* EXPORTING
* buffer = lf_xstring
* TABLES
* binary_tab = lt_lines.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = lf_bin_filesize
filename = 'C:\Users\onder\Desktop\From_Caller.pdf'
filetype = 'BIN'
CHANGING
data_tab = lt_solix_tab[]
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.
2020 Nov 18 7:42 PM
Why don't you get data from external system calling RFC? After you got the data you can easily call your smart form in the source system. Keep it simple please.
2020 Nov 19 10:06 AM
There is no problem calling smartform on source system. Problem is transfer PDF data between systems. I was generating XSTRING and converting XSTRING to BINARY with wrong way. That' s why, it doesn't work. My solution is above. You can check.
Thanks for your time.
2020 Nov 19 10:43 AM
I saw your solution but I never wouldn't do it. In my opinion, file transfer among SAP systems are not a good idea, it would be better option to getting data and make your conversion in the source system. But if you or your customer persist on doing it with this way, i can't say anything. I am just simply saying you are making to much job instead of making it easily. Get your tables and structures via RFC connection, use those data for calling SF in the source system and make your PDF conversion in the source system. This way make sense for me (:
2020 Nov 18 7:47 PM
I guess you use incorrectly SCMS_XSTRING_TO_BINARY, that you declared LT_LINES as TLINE_TAB (or similar) which has lines with 2 components. Unfortunately, the function module returns data only in the first component of the lines of the parameter BINARY_TAB, and when you download LT_LINES, the second empty component is unfortunately written too, inserting incorrect "spaces" between sequences of bytes.
For instance, declare LT_LINES with a line type made of only one component:
DATA lt_lines TYPE solix_tab.
2020 Nov 19 9:45 AM
Thanks for help, yes I had a mistake about that part 👍 Also made some changes on my code.