Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Character String and Byte String Processing →  Expressions and Functions for String Processing →  String Functions →  Examples of String Functions 

String Functions, escape

This example demonstrates the string function escape for HTML.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: begin    TYPE string,
          body     TYPE string,
          esc_body TYPE string,
          end      TYPE string.

    begin = `<html><body>`.
    end   = `</body><html>`.

    body = `<table border> `
        && `<tr><td>11</td><td>12</td></tr> `
        && `<tr><td>21</td><td>22</td></tr> `
        && `</table>`.

    esc_body = escape( val    = body
                       format = cl_abap_format=>e_html_text ).

    MESSAGE body TYPE 'I'.
    MESSAGE esc_body TYPE 'I'.

    cl_abap_browser=>show_html(
      html_string = begin && body && end
      size        = cl_abap_browser=>small
      title       = 'Not escaped' ).
    cl_abap_browser=>show_html(
      html_string = begin && esc_body && end
      size        = cl_abap_browser=>medium
      title       = 'Escaped' ).

Description

The program applies the function escape to a string used as the body of a HTML file. The string is displayed as a text and in the HTML browser both before and after the function is executed.