Thursday, March 8, 2012

Encode and Decode URL in ABAP

CL_HTTP_UTILITY is an utility class which provides several functions related to URL manipulations. There are many methods available in it, the one which I would like to share here is IF_HTTP_UTILITY~ESCAPE_URL and IF_HTTP_UTILITY~UNESCAPE_URL.
The method ESCAPE_URL does the URL encoding and the method UNESCAPE_URL does the URL Decoding as mentioned below:

Report YURL.
DATA:v_unescaped TYPE string,
           v_escaped   TYPE string,
           v_return_code TYPE i.
START-OF-SELECTION.
***********Example for URL encoding
  v_unescaped = 'HTTP://TOOMUCHABAP.BLOGSPOT.COM/'.
  v_escaped = cl_http_utility=>escape_url(
                unescaped = v_unescaped ).
  v_return_code = cl_http_utility=>get_last_error( ).
  IF v_return_code = 0.
    WRITE: 'Encoded URL-',v_escaped.
    SKIP 1.
  ENDIF.
***********Example for URL decoding
  CLEAR:v_unescaped.
  v_unescaped = cl_http_utility=>unescape_url(
                  escaped   = v_escaped ).
  v_return_code = cl_http_utility=>get_last_error( ).
  IF v_return_code = 0.
    WRITE: 'Decoded URL-',v_unescaped.
    SKIP 1.
  ENDIF.

2 comments:

  1. Copy Cat.. This is was copied from http://zevolving.com/2012/02/encode-and-decode-url-in-abap/ without author's consent.

    ReplyDelete