SAP On-premise

Setup SM59 Connection

  1. 1.
    Login into Renda developer portal
  2. 2.
    Subscribe to HTML->PDF service
  3. 3.
    Copy API Service URL to notepad
  4. 4.
    Go to transaction SM59
    1. 1.
      Create a new HTTP Connection to External Server - Type G
    2. 2.
      Key in RENDA.IO in RFC Destination field
    3. 3.
      Enter description as Renda.io connection for HTML transformation
    4. 4.
      Under Technical Settings tab - Paste region specific API Service URL(from
    5. 5.
      Enter Service No. as 443
    6. 6.
      Test Connection
You should receive a HTTP 200 success code if everything is setup successfully.
Please remember to whitelist API Service URL from within your corporate firewall. This will enable outbound calls to be made from your SAP system to Renda engine in the cloud.

Invoking REST API

The following code demonstrates how Renda can be invoked from ABAP function to convert HTML output to PDF document
ABAP Code - To Convert HTML output to PDF document
1
FUNCTION zgenerate_pdf.
2
*"----------------------------------------------------------------------
3
*"*"Local Interface:
4
*" IMPORTING
5
*" VALUE(IM_RFCDEST) TYPE RFCDEST
6
*" VALUE(IM_API_KEY) TYPE STRING
7
*" VALUE(IM_HTML) TYPE STRING
8
*" VALUE(IM_ENCRYPTION_KEY) TYPE STRING OPTIONAL
9
*" VALUE(IM_LANDSCAPE) TYPE STRING OPTIONAL
10
*" VALUE(IM_FORMAT) TYPE STRING OPTIONAL
11
*" VALUE(IM_MARGIN_TOP) TYPE STRING OPTIONAL
12
*" VALUE(IM_MARGIN_RIGHT) TYPE STRING OPTIONAL
13
*" VALUE(IM_MARGIN_BOTTOM) TYPE STRING OPTIONAL
14
*" VALUE(IM_MARGIN_LEFT) TYPE STRING OPTIONAL
15
*" EXPORTING
16
*" VALUE(EX_SUBRC) TYPE SYSUBRC
17
*" VALUE(EX_MESS) TYPE STRING
18
*" VALUE(EX_PDF) TYPE XSTRING
19
*"----------------------------------------------------------------------
20
*
21
DATA: lo_http_client TYPE REF TO if_http_client,
22
lv_http_rc TYPE i,
23
lv_response TYPE string,
24
lv_json TYPE /ui2/cl_json=>json,
25
lr_data TYPE REF TO data.
26
*
27
FIELD-SYMBOLS: <data> TYPE data,
28
<field> TYPE any.
29
*
30
* Setup IF_HTTP_Client object
31
*
32
CALL METHOD cl_http_client=>create_by_destination
33
EXPORTING
34
destination = im_rfcdest
35
IMPORTING
36
client = lo_http_client
37
EXCEPTIONS
38
argument_not_found = 1
39
plugin_not_active = 2
40
internal_error = 3
41
OTHERS = 4.
42
*
43
IF sy-subrc IS NOT INITIAL.
44
ex_mess = 'Error creating new IF_HTTP_Client object. Process aborted.'.
45
ex_subrc = 4.
46
RETURN.
47
ENDIF.
48
*
49
* Set protocol version
50
*
51
lo_http_client->request->set_version( if_http_request=>co_protocol_version_1_1 ).
52
*
53
* Set request header fields
54
*
55
lo_http_client->request->set_header_field(
56
name = 'Accept'
57
value = 'application/pdf' ).
58
*
59
lo_http_client->request->set_header_field(
60
name = 'Content-Type'
61
value = 'application/x-www-form-urlencoded' ).
62
*
63
lo_http_client->request->set_header_field(
64
name = 'x-api-key'
65
value = im_api_key ).
66
*
67
* Set form fields/attributes
68
*
69
lo_http_client->request->if_http_entity~set_form_field(
70
name = 'inputPayload'
71
value = im_html ).
72
*
73
IF im_encryption_key IS NOT INITIAL.
74
*
75
lo_http_client->request->if_http_entity~set_form_field(
76
name = 'encryptionKey'
77
value = im_encryption_key ).
78
*
79
ENDIF.
80
*
81
IF im_landscape IS NOT INITIAL.
82
*
83
lo_http_client->request->if_http_entity~set_form_field(
84
name = 'landscape'
85
value = im_landscape ).
86
*
87
ENDIF.
88
*
89
IF im_format IS NOT INITIAL.
90
*
91
lo_http_client->request->if_http_entity~set_form_field(
92
name = 'format'
93
value = im_format ).
94
*
95
ENDIF.
96
*
97
IF im_margin_top IS NOT INITIAL.
98
*
99
lo_http_client->request->if_http_entity~set_form_field(
100
name = 'marginTop'
101
value = im_margin_top ).
102
*
103
ENDIF.
104
*
105
IF im_margin_right IS NOT INITIAL.
106
*
107
lo_http_client->request->if_http_entity~set_form_field(
108
name = 'marginRight'
109
value = im_margin_right ).
110
*
111
ENDIF.
112
*
113
IF im_margin_bottom IS NOT INITIAL.
114
*
115
lo_http_client->request->if_http_entity~set_form_field(
116
name = 'marginBottom'
117
value = im_margin_bottom ).
118
*
119
ENDIF.
120
*
121
IF im_margin_left IS NOT INITIAL.
122
*
123
lo_http_client->request->if_http_entity~set_form_field(
124
name = 'marginLeft'
125
value = im_margin_left ).
126
*
127
ENDIF.
128
*
129
lo_http_client->request->set_method( 'POST' ).
130
*
131
lo_http_client->propertytype_logon_popup = lo_http_client->co_disabled.
132
*
133
* Send request
134
*
135
CALL METHOD lo_http_client->send
136
EXPORTING
137
timeout = 60 " 15 Seconds
138
EXCEPTIONS
139
http_communication_failure = 1
140
http_invalid_state = 2.
141
*
142
IF sy-subrc IS NOT INITIAL.
143
*
144
ex_mess = 'HTTP Post error. Process aborted'.
145
ex_subrc = 4.
146
*
147
CALL METHOD lo_http_client->close
148
EXCEPTIONS
149
http_invalid_state = 1
150
OTHERS = 2.
151
*
152
FREE lo_http_client.
153
RETURN.
154
*
155
ENDIF.
156
*
157
* Read the Response
158
*
159
CALL METHOD lo_http_client->receive
160
EXCEPTIONS
161
http_communication_failure = 1
162
http_invalid_state = 2
163
http_processing_failed = 3.
164
*
165
lo_http_client->response->get_status( IMPORTING code = lv_http_rc ).
166
lo_http_client->response->get_status( IMPORTING reason = ex_mess ).
167
lv_response = lo_http_client->response->get_cdata( ).
168
*
169
IF lv_http_rc NE '200'.
170
*
171
* Get error message back from Renda
172
*
173
ex_subrc = 4.
174
lv_json = lv_response.
175
lr_data = /ui2/cl_json=>generate( json = lv_json ).
176
*
177
IF lr_data IS BOUND.
178
ASSIGN lr_data->* TO <data>.
179
ASSIGN COMPONENT 'MESSAGE' OF STRUCTURE <data> TO <field>.
180
IF <field> IS ASSIGNED.
181
lr_data = <field>.
182
ASSIGN lr_data->* TO <data>.
183
ex_mess = <data>.
184
ENDIF.
185
ENDIF.
186
*
187
ELSE.
188
*
189
ex_pdf = lo_http_client->response->get_data( ).
190
*
191
ENDIF.
192
*
193
CALL METHOD lo_http_client->close
194
EXCEPTIONS
195
http_invalid_state = 1
196
OTHERS = 2.
197
*
198
FREE lo_http_client.
199
*
200
ENDFUNCTION.
Copied!
Last modified 8mo ago