SAP Help ABAP code to encode a URL using base 64 ins SAP, also includes ABAP functionality to decodes data that has already been encoded









SAP Base 64 encoding and decoding using ABAP code

Below is a simple ABAP program that will encode a URL or any data into base 64. Not only that it will also decode any data that has already been encoded using another base64 encoder such as the one found at https://www.base64encode.org.

*ABAP code to demonstrate base64 encoding & decoding 
*&---------------------------------------------------------------------*
*& Report ZTMP_BASE64
*&
*&---------------------------------------------------------------------*
*& Encodes URL or any values to Base64
*& Decodes URL or any values from Base64
 *& i.e. Replicates fucntionality of https://www.base64encode.org/
*&---------------------------------------------------------------------*
REPORT ztmp_base64.
DATA: lo_httputil TYPE REF TO if_http_utility.
DATA: ld_rawurl type string,
ld_encodedurl type string.
*p_url & p_base64 needs to be a char value that excepts lowercase characters
PARAMETERS: p_url type text1000 default '../index.htm',
p_base64 type text1000 default 'aHR0cDovL3d3dy5zYXBkZXYuY28udWs='.
************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
CREATE OBJECT lo_httputil TYPE cl_http_utility.
ld_encodedurl = p_url.
ld_encodedurl = lo_httputil->encode_base64( ld_encodedurl ).
ld_rawurl = p_base64.
ld_rawurl = lo_httputil->decode_base64( ld_rawurl ).
************************************************************************
*END-OF-SELECTION.
END-OF-SELECTION.
write:/ p_url, 'encoded as', ld_encodedurl,
/ p_base64, 'dencoded to', ld_rawurl.