Skip to Content

You could display up to 200 characters long message using SE91 message class short text. Let us define the following messages in SE91:

image

There are 3 messages 018, 019 and 021 defined above. The messages 018 and 019 end up with the continuation string, in ##<MsgNo> format, that points to the next message to be appended. The ‘##019’ string at the end of the message 018 indicates that the message 019 should be appended at the end of the message 018. The ‘##021’ string at the end of the message 019 indicates that the message 021 should be appended at the end of the message 019.

Additionally, the ‘|’ character is used as the line break.

Let us write the ZAWB_TEST_MESSAGE test program as shown in the following table:

REPORT  zawb_test_message.INCLUDE zflc_error_m.PARAMETERS:  p_func  TYPE char20 DEFAULT ‘zabc_sohdr_get1’ LOWER CASE,  p_vbeln TYPE vbeln  DEFAULT ‘4981’.DATA:  gr_vbak TYPE vbak,  gr_msg  TYPE bapiret2.START-OF-SELECTION.  CASE p_func.    WHEN ‘zabc_sohdr_get1’.      PERFORM zawb_sohdr_get1 USING p_vbeln gr_vbak gr_msg.    WHEN ‘zabc_sohdr_get2’.      CALL FUNCTION ‘ZAWB_SOHDR_GET2’        EXPORTING          uc_vbeln       = p_vbeln        IMPORTING          xr_vbak        = gr_vbak        EXCEPTIONS          invalid_so_num = 1          OTHERS         = 2.      IF sy-subrc <>

0.

        zflc_on_error_sy_set gr_msg.

      ENDIF.

  ENDCASE.

  zflc_error_popup gr_msg ‘EW’.

*&—-


*

*&      Form  zawb_sohdr_get1

*&—-


*

FORM

   zawb_sohdr_get1 ” get sales order header record

USING

  uc_vbeln  TYPE vbeln     ” sales order number

  xr_vbak   TYPE vbak      ” sale order header record

  xr_msg    TYPE bapiret2. ” message record

*—-


*

  SELECT SINGLE * INTO xr_vbak FROM vbak WHERE vbeln = uc_vbeln.

  IF sy-subrc <> 0.

zflc_error_set xr_msg ‘E’ ‘ZAWB’ 18 uc_vbeln ” ” ”.

ENDIF.

ENDFORM. “zabc_sohdr_get1

The above program tries to retrieve the sales order header record using ZAWB_SOHDER_GET1 ABAP Form or ZAWB_SOHDR_GET2 Function Module shown in the following table:

FUNCTION zawb_sohdr_get2.

*”—-


“Local Interface:

*”  IMPORTING

*”     REFERENCE(UC_VBELN) TYPE  VBELN

*”  EXPORTING

*”     REFERENCE(XR_VBAK) TYPE  VBAK

*”  EXCEPTIONS

*”      INVALID_SO_NUM

*”—-


  SELECT SINGLE *

         INTO xr_vbak

         FROM vbak

         WHERE vbeln = uc_vbeln.

  IF sy-subrc <> 0.

MESSAGE ID ‘ZAWB’ TYPE ‘E’ NUMBER 18 WITH uc_vbeln

RAISING invalid_so_num.

ENDIF.

ENDFUNCTION.

 If sales order is not found, the ZAWB_SOHDER_GET2 Function Module raises exception. The calling program converts SY structure error parameters to gr_msg BAPIRET2 structure calling ZFLC_ON_ERROR_SY_SET macro as shown in the following table:

   …        WHEN ‘zabc_sohdr_get2’.      CALL FUNCTION ‘ZAWB_SOHDR_GET2’        EXPORTING          uc_vbeln       = p_vbeln        IMPORTING          xr_vbak        = gr_vbak        EXCEPTIONS          invalid_so_num = 1          OTHERS         = 2.      IF sy-subrc <> 0.        zflc_on_error_sy_set gr_msg.      ENDIF.    …  

The ZFLC_ON_ERROR_SY_SET macro source code defined in ZFLC_ERROR_M include is shown in the following table:

DEFINE

   zflc_on_error_sy_set. ” sets system message

*PARAMETERS

  • &1              ” BAPIRET2^ message object; e.g.,  lr_msg

*SOURCE

  if sy-subrc <> 0.

call function ‘ZFLC_ERROR_SET’

exporting

us_msgtyp = sy-msgty

us_msgid = sy-msgid

ui_msgno = sy-msgno

us_msgtxt = ”

us_msgv1 = sy-msgv1

us_msgv2 = sy-msgv2

us_msgv3 = sy-msgv3

us_msgv4 = sy-msgv4

changing

xr_msg = &1.

endif.

END-OF-DEFINITION.

The ZAWB_SOHDER_GET1 ABAP Form is shown in the following table:

*&—-


*

*&      Form  zawb_sohdr_get1

*&—-


*

FORM

   zawb_sohdr_get1 ” get sales order header record

USING

  uc_vbeln  TYPE vbeln     ” sales order number

  xr_vbak   TYPE vbak      ” sale order header record

  xr_msg    TYPE bapiret2. ” message record

*—-


*

  SELECT SINGLE * INTO xr_vbak FROM vbak WHERE vbeln = uc_vbeln.

  IF sy-subrc <> 0.

zflc_error_set xr_msg ‘E’ ‘ZAWB’ 18 uc_vbeln ” ” ”.

ENDIF.

ENDFORM. “zabc_sohdr_get1

 If sales order is not found, the ZAWB_SOHDER_GET1 ABAP Form sets the error message in xr_msg BAPIRET2 structure using ZFLC_ERROR_SET macro  defined in ZFLC_ERROR_M include and shown in the following table:

DEFINE

   zflc_error_set. ” sets message

*PARAMETERS

  • &1              ” BAPIRET2^ message object; e.g.,  lr_msg

  • &2              ” message type; e.g.,    E

  • &3              ” message id; e.g.,      ZOIM

  • &4              ” message number

  • &5              ” message parameter 1

  • &6              ” message parameter 2

  • &7              ” message parameter 3

  • &8              ” message parameter 4

*SOURCE

  call function ‘ZFLC_ERROR_SET’

    exporting

      us_msgtyp = &2

      us_msgid  = &3

      ui_msgno  = &4

      us_msgtxt = ”

      us_msgv1  = &5

      us_msgv2  = &6

      us_msgv3  = &7

      us_msgv4  = &8

    changing

      xr_msg    = &1.

END-OF-DEFINITION.

The ZFLC_ERROR_SET macro calls ZFLC_ERROR_SET function module that formats message processing message extension strings ##<MsgNo>. The function module source code is shown in the following table:

FUNCTION ZFLC_ERROR_SET.

*”—-


“Local Interface:

*”  IMPORTING

*”     REFERENCE(US_MSGTYP) TYPE  ANY

*”     REFERENCE(US_MSGID) TYPE  ANY

*”     REFERENCE(UI_MSGNO) TYPE  ANY

*”     REFERENCE(US_MSGTXT) TYPE  ANY

*”     REFERENCE(US_MSGV1) TYPE  ANY

*”     REFERENCE(US_MSGV2) TYPE  ANY

*”     REFERENCE(US_MSGV3) TYPE  ANY

*”     REFERENCE(US_MSGV4) TYPE  ANY

*”  CHANGING

*”     REFERENCE(XR_MSG) TYPE  BAPIRET2

*”—-


  DATA:

    li_subrc  TYPE sysubrc,

    ls_msgno  TYPE char3,

    ls_msgno2 TYPE char3,

    li_pos    TYPE i,

    lr_t100   TYPE t100,

    ls_msgv1  TYPE symsgv,

    ls_msgv2  TYPE symsgv,

    ls_msgv3  TYPE symsgv,

    ls_msgv4  TYPE symsgv.

  FIELD-SYMBOLS:

    The error message is displayed by ZFLC_ERROR_POPUP macro defined in ZFLC_ERROR_M  include and shown in the following table:

DEFINE

   zflc_error_popup. ” display msg of types in popup window

*PARAMETERS

  • &1              ” BAPIRET2^ message object; e.g.,  lr_msg

  • &2              ” consider message types e.g.,   EW

*SOURCE

  if not &1-type is initial and &2 cs &1-type.

    sy-title = ‘[P][P]( (P))’.

    replace ‘[P]’ with:

      &1-type   into sy-title,

      &1-number into sy-title,

      &1-id     into sy-title.

    condense sy-title no-gaps.

    concatenate ‘Message:’ sy-title into sy-title

                separated by space.

    clear:

      sy-winsl,

      sy-entry,

      sy-rtitl,

      sy-xcode.

    split &1-message at ‘|’ into sy-winsl

                                 sy-entry

                                 sy-rtitl

                                 sy-xcode.

    call function ‘POPUP_TO_INFORM’

      exporting

        titel = sy-title

        txt1  = sy-winsl

        txt2  = sy-entry

        txt3  = sy-rtitl

        txt4  = sy-xcode.

  endif.

END-OF-DEFINITION.

Now let us execute the ZAWB_TEST_MESSAGE test program as shown on the following screen:

image

 Click on the Execute button. The following popup window appears:

image

The same popup window will appear if we would change Function Module/ABAP Form Name parameter from ZAWB_SOHDR_GET1 ABAP Form name to* ZAWB_SOHDR_GET2* Function Module name.

As described in this paper, the message was formatted by ZFLC error macros and ZFLC_ERROR_SET function module from messages, with special formatting strings, defined in SE91 message class:

!https://weblogs.sdn.sap.com/weblogs/images/5188/SE91Messages.JPG|height=284|alt=image|width=652|src=https://weblogs.sdn.sap.com/weblogs/images/5188/SE91Messages.JPG|border=0!</body>

To report this post you need to login first.

10 Comments

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

  1. Former Member
    What happens if you define messages as follows:
    018 – bla bla bla ##019
    019 – bla bla bla ##018
    ? So be carefull!

    Anyhow good blog ๐Ÿ˜‰

    (0) 
    1. Former Member Post author

      You could protect against infinite loop as follows:<br/>…<br/>      DO 5 TIMES.<br/>        IF xr_msg-message CS ‘##’.<br/>          li_pos = sy-fdpos + 2.<br/>          ASSIGN xr_msg-messageli_pos(3) TO <f>.<br/>          ls_msgno2 = <f>.<br/>          li_pos = li_pos – 2.<br/>          ASSIGN xr_msg-messageli_pos(*) TO Adding 5 TIMES after DO in ZFLC_ERROR_SET function module will protect against infinite loop

      (0) 
  2. Former Member
    Thank you, It was a very informative blog.

    Could you please tell me if we have four variable place holders in one message and 2 variable place holders in next message, can we use these two messages to display all six varaibles.

    Thanks again,
    Goutham.

    (0) 
    1. Former Member Post author
      Hi Goutham:

      The answer is NO. No matter how many massages are linked altogether only up to 4 parameters are supported.

      However, you might try modifying the source code I provided and develop version that accepts more than 4 parameters. If you will be doing it, you would have to overcome some limitations; e.g.:
      •     4 parameter variables in SY system variable SY-MSGV1, …
      •     4 parameter variables in BAPIRET2 structure
      •     Limitation on number of parameters in ABAP macros

      I am sure that you could overcome this and share with SDN community a new version supporting more than 4 parameters to the message.

      Best regards,

      Adam

      (0) 
    2. Former Member Post author
      You could develop ZFLC_ERROR_UPDATE ABAP macro that could populate parameters 5, 6, … in already formatted message. Let us assume that we have the message with 7 parameter holders:

      ZABC 020 ‘This is message with parameters &, &, &, &, &, & and &’

      If error occurs you could call:

      ZFLC_ERROR_SET lr_msg ‘E’ ‘ZABC’ 20 ‘A’ ‘B’ ‘C’ ‘D’.

      After this call, LR_MSG-MESSAGE field will contain the following text:

      ‘This is message with parameters A, B, C, D, &, & and &’

      Then you could call:

      ZFLC_ERROR_UPDATE lr_msg ‘E’ ‘F’ ‘G’ ”.

      After that call, the LR_MSG-MESSAGE will contain:

      ‘This is message with parameters A, B, C, D, E, F and G’

      Once you would have this, ZFLC_ERROR_POPUP should display correctly the message with 7 parameters. It should be easy to implement ZFLC_ERROR_UPDATE ABAP macro.

      The calling sequence for all of this should be like this:

      IF sy-subrc <> 0.
      zflc_error_set lr_msg ‘E’ ‘ZABC’ 20 ‘A’ ‘B’ ‘C’ ‘D’.
      zflc_error_update lr_msg ‘E’ ‘F’ ‘G’ ”.
      zflc_error_popup lr_msg ‘E’.
      ENDIF.

      Best regards,

      Adam

      (0) 
  3. Emanuel Klenner
    Hi Adam !

    I would like to suggest an easier approach to the solution you showed.

    In transaction SE61 create a document of type ‘DT’ (text in dialog), e.g. Z_MULTI_LINE_MSG.
    Document can be as long as you want and you can include your own parameters, e.g. &PAR1, &PAR2 in the text.

    To issue the ‘message’ call function POPUP_TO_CONFIRM with parameter DIAGNOSE_OBJECT = ‘Z_MULTI_LINE_MSG’ und table parameter PARAMETER.

    PARAMETER containing
    PARAM  VALUE
    &PAR1  abc
    &PAR2  xyz

    etc.

    Best regards,

    Emanuel

    (0) 
  4. Former Member

    Hi Adam,

    with which release did you develop your solution?

    In 7.0 you can maintain dialogtexts with transaction SE61 and display them with function module POPUP_TO_CONFIRM.

    Saves a log of work.

    Anyway good post of yours.

    Regards,

    Dirk

    (0) 

Leave a Reply