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.
1) You work with file = binary data. So do not get HTTP response as character data (get_cdata), but i think this metod:
response->get_data2) You work with binary data so always keep in mind binary data size as raymond.giuseppi suggested.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thomas,
Already tried that. It doesn't work 🙂
1. I used
lv_response = lcl_client->response->get_data( ).
to read the response, and used the exact FM with the same parameters and have the same error message in Adobe. As a difference the string looks like :
255044462D312E340D0A25A2A38F930D0A372030206F626A0D0A3C3C2F54797065202F584F626A656374202F53756274797065202F496D616765202F576964746820313532202F486569676874203433202F436F6C6F725370616365202F44657669636547726179202F42697473506572436F6D706F6E656E742038202F446
2. The parameter "binary" is checked in both cases.
Kind regards,
Marius
Nonono... 😞 You are still going wrong way.
From HTTP client you should have XSTRING. This XSTRING you can convert to SOLIX_TAB (I already gave you a tip how to do it). And this SOLIX_TAB you will use (with file size) in SCMS_DOWNLOAD (or GUI_DOWNLOAD - not sure why you selected to use SCMS_DOWNLOAD ???).
It is quite easy, basic ABAP handling of files...
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.