on ‎2019 Jan 07 12:37 PM
Hi guys,
I'm trying to download a PDF created by a third party from an API. I'm in a EHP4 FOR SAP ERP 6.0 / NW7.01 environment.
I created using SM50 a HTTP destination (type G and default SSL client) that I use to do POST and GET requests, and everything goes well, unless I try to download a PDF file.
Using:
* Create HTTP client object
CALL METHOD cl_http_client=>create_by_destination
EXPORTING
destination = 'HTTPS'
IMPORTING
client = lcl_client
EXCEPTIONS
destination_not_found = 1
internal_error = 2.
I get a correct response:
IF lv_status = 200.
lv_response = lcl_client->response->get_cdata( ).
ENDIF.
And although "lv_response" has the data that looks correct:
Field LV_RESPONSE
Data Type CString{26202}
Absolute Type \TYPE=STRING
View
%PDF-1.4##%����##7 0 obj##<</Type /XObject /Subtype /Image /Width 152 /Height
When I try to transfer the string to the "file" something goes wrong. Here is the code I use to write the file:
DATA: ls_string TYPE lvc_s_1022,
lt_string TYPE lvc_t_1022.
DO .
lv_len = STRLEN( lv_response ).
IF lv_len <> 1022.
ls_string-line = lv_response+0(lv_len).
ELSE.
ls_string-line = lv_response+0(1022).
ENDIF.
APPEND ls_string TO lt_string.
SHIFT lv_response BY 1022 PLACES.
IF lv_response IS INITIAL.
EXIT.
ENDIF.
ENDDO.
CONCATENATE lv_file '\' lv_filename '.pdf' INTO lv_file.
CALL FUNCTION 'SCMS_DOWNLOAD'
EXPORTING
filename = lv_file
binary = 'X'
frontend = 'X'
mimetype = 'charset=UTF8'
TABLES
data = lt_string
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
I tried playing with the MIMETYPE parameter and BINARY paratemer, with no success. When opening the file with Acrobat Reader I get the error that the file is corrupt.
Any idea why this doesn't work ?
Kind regards,
Marius
Request clarification before answering.
You didn't fill the FILESIZE parameter?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.