Skip to Content

h2. Messages

When implementing a table which shows application log messages, two problems came up: I cannot use the message manager (by MessageArea UI element) and second I knew only how to retrieve the short texts.

The MessageArea could not be used, because I wanted to have a independent table which can show messages from the application log. These messages had been retrieved via BAL_* function modules (T100 messages). The MessageArea element is to be used for messages created during the runtime of the application itself and not for showing other messages.

Retrieve a message long text

There is a method DOCU_GET

which provides the long text in ITF (SAPScript format). So we first call this method:

CONCATENATE lv_msgid lv_msgno INTO docu_key.

CALL FUNCTION ‘DOCU_GET’

 EXPORTING

  id = ‘NA’

  langu = sy-langu

  object = docu_key

  typ = ‘E’

 IMPORTING

  head = ls_thead

 TABLES

  line = itf_itab.

This will return the long text of the message (lv_msgid = message class, lv_msgno = message number).

But the returned table is SAPScript, so we have to convert this…

Convert the long text

The result of our message thing has to be a XHTML snipplet (without header) so there are two parts of this: first we have to ensure that no HTML tags or special characters are in the raw text of the message and second that the ITF/SAPScript formatting is converted correctly.

There are already several function modules to convert ITF/SAPScript to something (also HTML). There is for example the WebDynpro class CL_WD_FORMATTED_TEXT which converts SAPScript to XHTML which WebDynpro can understand – but perhaps you want to do it by yourself!?

I will show you both ways to do this.

CL_WD_FORMATTED_TEXT

This is quite easy:

DATA: lo_formatted_text TYPE REF TO CL_WD_FORMATTED_TEXT.

lo_formatted_text = CL_WD_FORMATTED_TEXT=>CREATE_FROM_SAPSCRIPT(

   sapscript_head = ls_thead

   sapscript_lines = itf_itab ).

longtext = lo_formatted_text->m_xml_text.

So you have the message long text converted by standard tools.

Own solution: special characters

To remove the bad characters we do

REPLACE ALL OCCURRENCES OF ‘&’ IN thetext WITH ‘&’.

REPLACE ALL OCCURRENCES OF ‘<‘ IN thetext WITH ‘<‘.

REPLACE ALL OCCURRENCES OF ‘>’ IN thetext WITH ‘>’.

(‘thetext’ is the variable for the string we want to clean up.)

We have to do this for each line from the result of DOCU_GET and for each message variable (v1 to v4).

Own solution: ITF/SAPScript conversion

Own solution: Missing titles and symbols

What now is missing are the titles “Procedure” which are encoded like &KEYWORD& and other special SAPScript things in the ITF table from DOCU_GET. Therefore we call some basis methods: TEXT_INCLUDE_REPLACE, TEXT_CONTROL_REPLACE and REPLACE_TEXTSYMBOL. See the complete coding…

Own solution: All together

   REPLACE REGEX ‘( 0. EXIT. ENDIF.

  ENDDO.

  DO.

   REPLACE REGEX ‘(<DS[&]*>)( (&)*)()( (^&))(</>)’ IN longtext WITH ‘$2

*’.

   IF sy-subrc )’ IN longtext WITH ‘$2‘.

   IF sy-subrc )( (^&))(</>)’ IN longtext WITH ‘$2*’.

   IF sy-subrc )’ IN longtext WITH ‘$2‘.

   IF sy-subrc )’ IN longtext WITH ‘$2‘.

   IF sy-subrc  0. EXIT. ENDIF.

  ENDDO.

  DO.

   REPLACE REGEX ‘<( (0-9))>’ IN longtext WITH ‘&#$1;’. ” this is not correct, but it could be worse…

   IF sy-subrc <> 0. EXIT. ENDIF.

  ENDDO.

  IF lv_msgv1 IS NOT INITIAL.

   REPLACE ALL OCCURRENCES OF ‘&’ IN lv_msgv1 WITH ‘&’.

   REPLACE ALL OCCURRENCES OF ‘<‘ IN lv_msgv1 WITH ‘<‘.

   REPLACE ALL OCCURRENCES OF ‘>’ IN lv_msgv1 WITH ‘>’.

  ENDIF.

  IF lv_msgv2 IS NOT INITIAL.

   REPLACE ALL OCCURRENCES OF ‘&’ IN lv_msgv2 WITH ‘&’.

   REPLACE ALL OCCURRENCES OF ‘<‘ IN lv_msgv2 WITH ‘<‘.

   REPLACE ALL OCCURRENCES OF ‘>’ IN lv_msgv2 WITH ‘>’.

  ENDIF.

  IF lv_msgv3 IS NOT INITIAL.

   REPLACE ALL OCCURRENCES OF ‘&’ IN lv_msgv3 WITH ‘&’.

   REPLACE ALL OCCURRENCES OF ‘<‘ IN lv_msgv3 WITH ‘<‘.

   REPLACE ALL OCCURRENCES OF ‘>’ IN lv_msgv3 WITH ‘>’.

  ENDIF.

  IF lv_msgv4 IS NOT INITIAL.

   REPLACE ALL OCCURRENCES OF ‘&’ IN lv_msgv4 WITH ‘&’.

   REPLACE ALL OCCURRENCES OF ‘<‘ IN lv_msgv4 WITH ‘<‘.

   REPLACE ALL OCCURRENCES OF ‘>’ IN lv_msgv4 WITH ‘>’.

  ENDIF.

  REPLACE ALL OCCURRENCES OF ‘&V1&’ IN longtext WITH lv_msgv1.

  REPLACE ALL OCCURRENCES OF ‘&V2&’ IN longtext WITH lv_msgv2.

  REPLACE ALL OCCURRENCES OF ‘&V3&’ IN longtext WITH lv_msgv3.

  REPLACE ALL OCCURRENCES OF ‘&V4&’ IN longtext WITH lv_msgv4.

 ENDIF.

ENDMETHOD.

Trivial: show with WebDynpro

1. Create an attribute with type STRING in your views context.

2. Put a FormattedTextView on your view and bind the context attribute you created with the property text of the FormattedTextView.

3. (PROPOSAL) In your SALV component (do not use the table thing) which shows the message list, catch the ON_LEAD_SELECT event, call the GET_LONG_TEXT method and put the result in the attribute of the context.

That’s all, look:

SAPGUI view of message long text (part 1)

image

WebDynpro view of message long text (part 1)

image

SAPGUI view of message long text (part 2)

image

WebDynpro view of message long text (part 2)

!https://weblogs.sdn.sap.com/weblogs/images/8499/message_2hd.jpg|height=278|alt=image|width=467|src=https://weblogs.sdn.sap.com/weblogs/images/8499/message_2hd.jpg|border=0!</body>

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Uwe Klinger
    Hello Harry,

    Thank you for providing insights about SAPScript and the FormattedTextView to the WD ABAP community. I hope that our standard conversion can solve the task usually.

    By the way, there is a Web Dynpro Application WDR_TEST_MISC. With which you can play around with formatted text.

    When building your own formatted text you should always ensure to have a valid formatted text at the end, otherwise you will get an exception in the rendering.

    Best Regards,
    Uwe

    (0) 

Leave a Reply