There are static methods both for encoding and decoding URL in class CL_HTTP_UTILITY. For encoding, ABAP predefined function encode( ) can be used as well.
Encoding URL
For encoding URL, you can use method ESCAPE_URL from mentioned class.
1 2 3 4 5 6 7 8 |
DATA: lv_unescaped TYPE string, lv_escaped TYPE string. CALL METHOD cl_http_utility=>escape_url EXPORTING unescaped = lv_unescaped RECEIVING escaped = lv_escaped. |
OR with simplified call:
1 |
lv_escaped = cl_http_utility=>escape_url( lv_unescaped ). |
Alternatively, you can also use predefined method encode( ) to accomplish the same result.
Decoding URL
For encoding URL, you can use method UNESCAPE_URL from mentioned class.
1 2 3 4 5 6 7 8 |
DATA: lv_unescaped TYPE string, lv_escaped TYPE string. CALL METHOD cl_http_utility=>unescape_url EXPORTING escaped = lv_escaped RECEIVING unescaped = lv_unescaped. |
OR the same simplier way as above:
1 |
lv_unescaped = cl_http_utility=>unescape_url( lv_escaped ). |
Reading return code
Reading return code is quite unusual, but it is same for both methods.
1 2 3 4 5 6 |
DATA lv_return_code TYPE i. lv_return_code = cl_http_utility=>get_last_error( ). IF lv_return_code = 0. * success * string was escaped / unescaped successfully ENDIF. |