cancel
Showing results for 
Search instead for 
Did you mean: 

SAP PO - 7.5 SOAP Response URL PDF file to BASE64

julian_baldner2
Explorer
0 Kudos

Dear community,

we have the following request.

We have a synchronous scenario to call a webservice from SAP ERP to an external provider.

Within the webservice response we have a field containing an URL to download a PDF.

The request is to retrieve the PDF and to convert it to BASE64 and pass the BASE64 within the response message back to ECC. Any idea how to handle this quite smoothly UDF etc ?

Thanks for all your answers - highly appreciated.

Julian

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member189420
Active Participant
0 Kudos

Hi Julian,

I have recently done something similar.

1. In the response mapping, execute the http call within the UDF to the URL directly or you can call a HTTP_AAE communication channel within the udf.

2. Once you have the response i.e. binary pdf document - use Base64.getEncoder().encode(byte[]) to get the base64 formatted data.

3. The Base64 encoded data can be passed back over ABAP proxy to ECC.

4. In ECC, depending on your requirement you may have to convert back from Base64 to Binary - refer to https://blogs.sap.com/2019/03/29/base64-function-modules-in-sap-abap/

Hope that helps!

Regards,

Anand

julian_baldner2
Explorer
0 Kudos

Hi Anand,

do you have some sample coding for this ?

Thanks and best regards,

Julian

former_member189420
Active Participant
0 Kudos

Hi Julian,

Unfortunately, I don't have access to the system I had done that.

You may get some idea regarding how to call the external url within the UDF here - https://answers.sap.com/questions/242015/operating-communication-channel-externally-using-u.html

Hope that helps!

Regards,

Anand

ThorstenHoefer
Active Contributor
0 Kudos

Hi julian.baldner2,

How you can retrieve data from an URL is descripted in the articel:

https://codezentrale.de/tag/create_by_url/

You can convert it to base 64 with

CL_HTTP_UTILITY=>IF_HTTP_UTILITY~IF_HTTP_UTILITY~ENCODE_X_BASE64( lv_xdata )

I hope following code snippets are helpful:

  DATA(lv_url) = |http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=\|1&chl=viele%20lustige%20Zeichen/chart.png|.
 
  TRY.
      DATA: o_client TYPE REF TO if_http_client.
* Client-Objekt erzeugen
      cl_http_client=>create_by_url( EXPORTING
                                       url     = lv_url
                                     IMPORTING
                                       client  = o_client ).
      IF sy-subrc = 0.
* HTTP GET senden
        o_client->send( ).
 
* Response lesen
        o_client->receive( ).
 
        DATA: lv_http_status TYPE i.
        DATA: lv_status_text TYPE string.
 
* HTTP Return Code holen
        o_client->response->get_status( IMPORTING
                                          code   = lv_http_status
                                          reason = lv_status_text ).
 
* Wenn Status 200 (Ok)
        IF lv_http_status = 200.
 
* Binärdaten (QR-Code) auslesen
          DATA(lv_xdata) = o_client->response->get_data( ).
 
          o_client->close( ).
        

data(L_base64) CL_HTTP_UTILITY=>IF_HTTP_UTILITY~IF_HTTP_UTILITY~ENCODE_X_BASE64( lv_xdata )


julian_baldner2
Explorer
0 Kudos

Hi Thorsten,

many thanks for your quick reply.

Sorry, maybe I forgot to mention that we are working with a JAVA only system not working with ABAP coding.

Best regards,

Julian