Entering content frame

Background documentation FormattedTextView Locate the document in its SAP Library structure

This UI element is used to display formatted text using a simple, XML-compatible syntax.  You can use a FormattedTextView to simply and quickly format larger sections of texts, for example, verwenden, an introduction or copyright information. The text may contain links, images or structured lists.

The XML format of the FormattedTextView supports an XHTML subset as well as some SAP-specific tags (see Supported Tags). The XHTML tags must not contain any attributes.

The service class CL_WD_FORMATTED_TEXT for use withFormattedTextView. One instance of this class represents one formatted text.

Note

When the template is designed there is no check for the tool tip property to guarantee Accessibilty.

A tooltip does not necessarily have to be set for this UI element, but it could make sense to set it if it contains detailed semantic information.

 

Runtime Class

CL_WD_FORMATTED_TEXT_VIEW

 

Properties in the View Designer

Name

Type

Initial Value

Bindable

ID

STRING

(automatic)

No

dataSource

context node

 

Yes

enabled

WDY_BOOLEAN

true

Yes

hAlign

WDUI_INPUT_FIELD_ALIGNMENT

auto

Yes

text

Text

 

Yes

textDirection

WDUI_TEXT_DIRECTION

inherit

Yes

tooltip

Text

 

Yes

visible

WDUI_VISIBILITY

visible

Yes

 

Events in the View Designer

Name

onAction

Note

Further properties that can be inherited are defined in the associated higher-level class.  The associated interface elements are:

·         UIElement

·         ViewElement

Dynamic Programming

For dynamic programming the same properties, events, and aggregations are provide in the View Designer. Bear in mind the different spellings.

Dynamic Programming of Properties

View Designer Name

Runtime Name

Type

dataSource

DATA_SOURCE

OBJECT

enabled

ENABLED

WDY_BOOLEAN

hAlign

H_ALIGN

WDUI_INPUT_FIELD_ALIGNMENT

 hAlign: auto

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-AUTO

 hAlign: beginOfLine

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-BEGIN_OF_LINE

 hAlign: center

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-CENTER

 hAlign: endOfLine

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-END_OF_LINE

 hAlign: forcedLeft

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-FORCED_LEFT

 hAlign: forcedRight

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-FORCED_RIGHT

text

TEXT

WDY_MD_TRANSLATABLE_TEXT

textDirection

TEXT_DIRECTION

WDUI_TEXT_DIRECTION

 textDirection: inherit

CL_WD_FORMATTED_TEXT_VIEW=>E_TEXT_DIRECTION-INHERIT

 textDirection: ltr

CL_WD_FORMATTED_TEXT_VIEW=>E_TEXT_DIRECTION-LTR

 textDirection: rtl

CL_WD_FORMATTED_TEXT_VIEW=>E_TEXT_DIRECTION-RTL

tooltip

TOOLTIP

WDY_MD_TRANSLATABLE_TEXT

visible

VISIBLE

WDUI_VISIBILITY

 visible: blank

CL_WD_FORMATTED_TEXT_VIEW=>E_VISIBLE-BLANK

 visible: none

CL_WD_FORMATTED_TEXT_VIEW=>E_VISIBLE-NONE

 visible: visible

CL_WD_FORMATTED_TEXT_VIEW=>E_VISIBLE-VISIBLE

 

Dynamic Programming of Events

View Designer Name

Runtime Name

onAction

ON_ACTION

 

Conversion of SAPscript Texts into Formatted Texts

You can convert SAPscript texts into formatted texts by calling static method CL_WD_FORMATTED_TEXT=> CREATE_FROM_SAPSCRIPT.

Example

data: lr_text type ref to cl_salv_form_text.

" convert from context
formatted_text = cl_wd_formatted_text=> create_from_sapscript(
  sapscript_head  = sapscript_head
  sapscript_lines = sapscript_lines
).


" set it into the context
wd_context->set_attribute(
  name  = my_formatted_text_attr

  value = formatted_text->m_xml_text ).

cl_wd_formatted_text=>write_sapscript_tokens( ).

Note that not all SAPscript properties and formats are valid with FormattedTextView.  The following list shows how SAPscript escape sequences are converted into formatted texts.

 

Type

Subtype

Replacement

Description

PARAGRAPH_BEGIN

U1

<h1>

U1 Header

PARAGRAPH_BEGIN

U2

<h2>

U2 Header

PARAGRAPH_BEGIN

U3

<h3>

U3 Header

PARAGRAPH_BEGIN

U4

<h4>

U4 Header

PARAGRAPH_BEGIN

U5

<h5>

U5 Header

PARAGRAPH_BEGIN

UT

<h6>

UT Header

PARAGRAPH_BEGIN

AS

<p>

AS Default Paragraph

PARAGRAPH_BEGIN

*

<p>

* Default Paragraph

PARAGRAPH_BEGIN

PE

<pre>

PE Default Paragraph

PARAGRAPH_BEGIN

B1

<ul>

B1 Bullet List Item

PARAGRAPH_BEGIN

B2

<ul>

B2 Bullet List Item (2)

PARAGRAPH_BEGIN

BL

<dd>

BL Bullet / List Comment

PARAGRAPH_BEGIN

D1

<dl>

D1 Definition list

PARAGRAPH_BEGIN

N1

<ol>

N1 Numbered list item

PARAGRAPH_BEGIN

N2

<ol>

N2 Numbered list item (2)

CTAG_BEGIN

AB

<code>

AB ABAP language

CTAG_BEGIN

DS

<acronym>

DS DSYS reference

CTAG_BEGIN

EX

<samp>

EX ABAP example

CTAG_BEGIN

GL

<dfn>

GL glossary reference

CTAG_BEGIN

LB

<kbd>

LB User input

CTAG_BEGIN

LS

<var>

LS screen element

CTAG_BEGIN

NP

<code>

NP fixed width font

CTAG_BEGIN

PF

<strong><kbd>

PF function key

CTAG_BEGIN

SE

<em>

SE SAP expression

CTAG_BEGIN

ZG

 

ZG protected

CTAG_BEGIN

ZH

<strong>

ZH emphasized

CTAG_BEGIN

ZK

<em>

ZK italic

CTAG_BEGIN

ZU

<em>

ZU underlined (not supported!)

CTAG_BEGIN

ZV

 

ZV hidden

COMMENT

 

 

Comment

ELEMENT_BEGIN

 

 

Element

LINE_BEGIN

 

 

Line

STRING

 

 

String

OPTION

 

 

Option -> Not supported (just printed)

SAP_CHAR

 

 

SAPChar -> Not supported (just printed)

TEMPLATE_STRING

 

 

Template String -> Not supported (just printed)

TAB

 

&nbsp;&nbsp;&nbsp; 

Tab (rendered as 4 spaces)

SYMBOL_BEGIN

 

&amp;

Symbol Begin & End

SYMBOL_BEGIN

 

 

Symbol

CTAG_BEGIN

 

 

Comment

PARAGRAPH_BEGIN

 

<p>

Generic paragraph

LTAG_BEGIN

 

 

Link (<a>)

URL_BEGIN

 

 

URL (<a>)

PREFIX_BEGIN

 

 

Prefix -> Not supported (just printed)

SUFFIX_BEGIN

 

 

Suffix -> Not supported (just printed)

COMMAND_BEGIN

 

 

Command -> Not supported (ignored)

TEXT_END

 

 

Text end -> Not supported (ignored)

COMMAND

 

 

Command -> Not supported (just printed)

PARAGRAPH_BEGIN

U1

<h1>

U1 Header

 

Validation of Formatted Text

You can call method VALIDATE for a formatted text object to check the object's validity. If there is an error, the exception CX_WD_GENERAL is triggered. Th error text is contained in the MSG attribute of the exception.

Example

  try.
      formatted_text->validate( ).
    catch cx_wd_general into ex.
      … ex->msg …

   endtry.

Dynamic Creation of Formatted Text

An interface is provided for creating formatted texts dynamically.

Note

FORMATTED_TEXT parameters require an object of type CL_WD_FORMATTED_TEXT.

TEXT parameters require that the text is provided with a toggle character for switching the code (“escaped text”).

XML_TEXT parameters require a valid formatted text (with markups, and so on).

Example

  data f1 type ref to cl_wd_formatted_text.
  data f2 type ref to cl_wd_formatted_text.
  data f3 type ref to cl_wd_formatted_text.
  data f  type ref to cl_wd_formatted_text.

  f1 = cl_wd_formatted_text=>make_text(
    inner_text = 
'available' "#EC NOTEXT
    tag        = cl_wd_formatted_text=>e_tag-em
  ).

  f2 = cl_wd_formatted_text=>make_sap_field( name = 'CONNID' ).
  f2 = cl_wd_formatted_text=>make_text(
    inner_formatted_text = f2
    tag = cl_wd_formatted_text=>e_tag-
code ).
  f3 = cl_wd_formatted_text=>make_sap_field( name = 'CARRID' ).

  f = cl_wd_formatted_text=>make_text( inner_text = 'Places &STATE& for flight &CONNID& of line &CARRID&' ). "#EC NOTEXT
  f->replace_placeholder( name = 'STATE'  formatted_text = f1 ).
  f->replace_placeholder( name = 'CONNID' formatted_text = f2 ).
  f->replace_placeholder( name = 'CARRID' formatted_text = f3 ).

  wd_context->set_attribute( name = 'TEXT' value = f->m_xml_text ).

 

Result

Places <em>available</em> for flight <code><sap:field name="CONNID"/></code> of line <sap:field name="CARRID"/>

 

Note

Note that in productive applications the texts, “available” and “places” must come from a source that can be converted. In the example above these texts are hard coded only so that they can be read more easily.

Use method REPLACE_PLACEHOLDER to replace placeholders in formatted texts with a text or a formatted text. This method helps to embed formatted text in “normal” text. Moreover, there is no risk of distorting the XML through the conversion.

Example

You can find examples in the system in the Web Dynpro applications, WDR_TEST_UI_ELEMENTS and WDR_TEST_MISC.

 

 

Leaving content frame