Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  User Dialogs →  Messages →  System Interface IF_T100_MESSAGE for Messages 

System Interface IF_T100_MESSAGE in a Regular Class

This example demonstrates how a regular class is associated with a message

Other versions: 7.31 | 7.40 | 7.54

Source Code

REPORT demo_if_t100_message.

CLASS msg DEFINITION.
  PUBLIC SECTION.
    INTERFACES if_t100_message.
    ALIASES get_text FOR if_message~get_text.
    METHODS constructor IMPORTING id TYPE symsgid
                                 no TYPE symsgno
                                 v1 TYPE string OPTIONAL
                                 v2 TYPE string OPTIONAL
                                 v3 TYPE string OPTIONAL
                                 v4 TYPE string OPTIONAL.
    DATA: attr1 TYPE c LENGTH 50,
          attr2 TYPE c LENGTH 50,
          attr3 TYPE c LENGTH 50,
          attr4 TYPE c LENGTH 50.
ENDCLASS.

CLASS msg IMPLEMENTATION.
  METHOD constructor.
    if_t100_message~t100key-msgid = id.
    if_t100_message~t100key-msgno = no.
    if_t100_message~t100key-attr1 = 'ATTR1'.
    if_t100_message~t100key-attr2 = 'ATTR2'.
    if_t100_message~t100key-attr3 = 'ATTR3'.
    if_t100_message~t100key-attr4 = 'ATTR4'.
    attr1 = v1.
    attr2 = v2.
    attr3 = v3.
    attr4 = v4.
  ENDMETHOD.
  METHOD if_message~get_text.
    result = cl_message_helper=>get_text_for_message( me ).
  ENDMETHOD.
  METHOD if_message~get_longtext.
    result = cl_message_helper=>get_longtext_for_message( me ).
  ENDMETHOD.
ENDCLASS.

CLASS msg_demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS msg_demo IMPLEMENTATION.
  METHOD main.
    DATA(id) = `SABAPDEMOS`.
    DATA(no) = `888`.
    DATA(v1) = `Hello,`.
    DATA(v2) = `I am`.
    DATA(v3) = `a`.
    DATA(v4) = `Message!`.
    cl_demo_input=>new(
      )->add_field( CHANGING field = id
      )->add_field( CHANGING field = no
      )->add_field( CHANGING field = v1
      )->add_field( CHANGING field = v2
      )->add_field( CHANGING field = v3
      )->add_field( CHANGING field = v4
      )->request( ).

    DATA(mref) = NEW msg( id = CONV #( id )
                          no = CONV #( no )
                          v1 = v1
                          v2 = v2
                          v3 = v3
                          v4 = v4 ).

    cl_demo_output=>display( mref->get_text( ) ).

    MESSAGE mref TYPE 'I'.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  msg_demo=>main( ).

Description

Objects in the example class msg can represent any messages from the table T100 and be used in the statement MESSAGE. The four attributes ATTR1 to ATTR4 stand for the content of four placeholders. The constructor provides input parameters for all necessary values. In the constructor, the message class and the message number are written directly to the associated components of the interface structure T100KEY. The identically named attributes are assigned to the components ATTR1 to ATTR4 and filled with the passed values.

Once the class is instantiated, the message text is filled using the interface method GET_TEXT, which is implemented in an appropriate way in the class and which has an alias name declared. The object of the class is used directly as an operand of the statement MESSAGE. A message type must be specified here.