Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to save message into internal table?

Former Member
0 Kudos

Hi,everyone!

I have a problem when I'm coding.I want to store messages into a internal table.Can you help me?

Thanks!

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

Hello Feng

If you are already working on SAP basis release >= 6.20 I would recommend the most versatile message handler of all: interface <b>IF_RECA_MESSAGE_LIST</b>

Perhaps you will find the following sample report ZUS_SDN_APOLLO_13

(see also: <a href="https://wiki.sdn.sap.com/wiki/display/profile/2007/07/09/MessageHandling-FindingtheNeedleintheHaystack">Message Handling - Finding the Needle in the Haystack</a>) useful.


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_APOLLO_13
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_apollo_13
  LINE-SIZE 200.


TYPE-POOLS: abap.

TYPES: BEGIN OF ty_s_outtab.
TYPES:   status     TYPE exception.
INCLUDE TYPE bapiret2  AS msg.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab  TYPE STANDARD TABLE OF ty_s_outtab
                    WITH DEFAULT KEY.

DATA:
  gs_layout         TYPE lvc_s_layo,
  gt_outtab         TYPE ty_t_outtab.


DATA:
  gd_title          TYPE lvc_title,
  gd_msgv           TYPE symsgv,
  gd_msg            TYPE bapi_msg,
  gs_msg            TYPE recamsg,
  gs_return         TYPE bapiret2,
  gt_return         TYPE bapirettab,
  go_msglist        TYPE REF TO if_reca_message_list,
  go_random         TYPE REF TO cl_random_number,
  gif_random        TYPE REF TO if_random_number.




PARAMETERS:
  p_opt1  RADIOBUTTON GROUP radi  DEFAULT 'X',
  p_opt2  RADIOBUTTON GROUP radi,
  p_opt3  RADIOBUTTON GROUP radi.
SELECTION-SCREEN ULINE.
PARAMETERS:
  p_opt4  RADIOBUTTON GROUP radi,
  p_opt5  RADIOBUTTON GROUP radi,
  p_opt6  RADIOBUTTON GROUP radi.


SELECTION-SCREEN ULINE.
PARAMETERS:
  p_count    TYPE numc3     DEFAULT '4',
  p_level    TYPE ballevel  DEFAULT '7'.


DEFINE mac_build_msg.
  clear: gs_msg.
  gs_msg-msgty = &5.
  gs_msg-msgid = '00'.
  gs_msg-msgno = '398'.
  gs_msg-msgv1 = &1.
  gs_msg-msgv2 = &2.
  gs_msg-msgv3 = &3.
  gs_msg-msgv4 = &4.
  gs_msg-detlevel = &6.

END-OF-DEFINITION.

*  msgty
*  msgid
*  msgno
*  msgv1
*  msgv2
*  msgv3
*  msgv4
*  msgv1_src
*  msgv2_src
*  msgv3_src
*  msgv4_src
*  detlevel
*  probclass
*  alsort
*  time_stmp
*  msg_count
*  context
*  params


START-OF-SELECTION.

  " Create message handler
  go_msglist = cf_reca_message_list=>create( ).



  " Create random number instance
  CREATE OBJECT go_random TYPE cl_random_number.
  gif_random ?= go_random.
  gif_random->init( ).




  PERFORM message_handling_1.
  PERFORM message_handling_2.
  PERFORM message_handling_3.
*
  PERFORM message_handling_4.


END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  MESSAGE_HANDLING_1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM message_handling_1 .

  CHECK ( p_opt1 = abap_true ).
  gd_title = 'Information System 1 (IS1)'.
  SET TITLEBAR 'TITLE' WITH gd_title.

  WRITE: / 'Apollo 13 Mission'.
  WRITE: / syst-uline.

  WRITE: / 'Take-Off             -> ok'.
  WRITE: / 'Leaving Orbit        -> ok'.
  WRITE: / 'Trajectory           -> ok'.
  WRITE: /.

  FORMAT COLOR COL_NEGATIVE.
  WRITE: / 'Explosion happened   -> not ok'.
  WRITE: / 'Command and Service module (CSM) -> damaged'.
  FORMAT RESET.
  WRITE: / 'Lunar module (LM)    -> not affected, ok'.

  MESSAGE text-hou TYPE 'S'.

ENDFORM.                    " MESSAGE_HANDLING_1


*&---------------------------------------------------------------------*
*&      Form  message_handling_2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM message_handling_2 .
* define local data
  DATA:
    ld_success(6)  TYPE n,
    ld_warning(6)  TYPE n,
    ld_failure(6)  TYPE n,
    ld_total(6)    TYPE n.

  CHECK ( p_opt2 = abap_true ).
  gd_title = 'Information System 2 (IS2)'.
  SET TITLEBAR 'TITLE' WITH gd_title.

  PERFORM generate_messages.  " simulation of messages

  CALL METHOD go_msglist->get_list_as_bapiret
    IMPORTING
      et_list = gt_return.

  " Calculate message types and total
  ld_total   = 0.
  ld_success = 0.
  ld_warning = 0.
  ld_failure = 0.


" Print messages as WRITE list
  LOOP AT gt_return INTO gs_return.
    IF ( gs_return-type = 'E' ).
      ADD 1 TO ld_failure.

    ELSEIF ( gs_return-type = 'W' ).
      ADD 1 TO ld_warning.
    ELSE.
      ADD 1 TO ld_success.
    ENDIF.

  ENDLOOP.
  ld_total = ld_success + ld_warning + ld_failure.


  WRITE: / 'Total Message =', ld_total.
  WRITE: / 'Failures      =', ld_failure.
  WRITE: / 'Warnings      =', ld_warning.
  WRITE: / 'Successes     =', ld_success.
  WRITE: / syst-uline.
  SKIP.

" Colouring depending on message type
  LOOP AT gt_return INTO gs_return.
    IF ( gs_return-type = 'E' ).
      FORMAT COLOR COL_NEGATIVE.


    ELSEIF ( gs_return-type = 'W' ).
      FORMAT COLOR COL_TOTAL.

    ELSE.
      FORMAT RESET.
    ENDIF.

    WRITE: / gs_return-type, gs_return-message+0(100).
  ENDLOOP.


ENDFORM.                    " message_handling_2



*&---------------------------------------------------------------------*
*&      Form  message_handling_3
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM message_handling_3 .
* define local data
  DATA:
    ls_outtab    TYPE ty_s_outtab.

  DATA:
    ld_success(6)  TYPE n,
    ld_warning(6)  TYPE n,
    ld_failure(6)  TYPE n,
    ld_total(6)    TYPE n.


  CHECK ( p_opt3 = abap_true ).
  gd_title = 'Information System 3 (IS3)'.
  SET TITLEBAR 'TITLE' WITH gd_title.

  PERFORM generate_messages.  " simulation of messages

  CALL METHOD go_msglist->get_list_as_bapiret
    IMPORTING
      et_list = gt_return.

  REFRESH: gt_outtab.
  " Calculate message types and total
  ld_total   = 0.
  ld_success = 0.
  ld_warning = 0.
  ld_failure = 0.

" Define the logic for setting exception status (LED)
  LOOP AT gt_return INTO gs_return.
    CLEAR: ls_outtab.

    ls_outtab-msg = gs_return.

    IF ( gs_return-type = 'E' ).
      ls_outtab-status = '1'.  " red
      ADD 1 TO ld_failure.

    ELSEIF ( gs_return-type = 'W' ).
      ls_outtab-status = '2'.  " yellow
      ADD 1 TO ld_warning.

    ELSE.
      ls_outtab-status = '3'.  " green
      ADD 1 TO ld_success.
    ENDIF.

    APPEND ls_outtab TO gt_outtab.
  ENDLOOP.

  ld_total = ld_failure + ld_warning + ld_success.

  CLEAR: gs_layout.
  gs_layout-cwidth_opt = abap_true.
  gs_layout-zebra      = abap_true.

  gs_layout-excp_fname = 'STATUS'.
  gs_layout-excp_led   = abap_true.
  gs_layout-smalltitle = abap_true.

  CONCATENATE 'T(' ld_total   ')  '
              'E(' ld_failure ')  '
              'W(' ld_warning ')  '
              'S(' ld_success ')  '
    INTO gd_title SEPARATED BY space.


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_structure_name = 'BAPIRET2'
      i_grid_title     = gd_title
      is_layout_lvc    = gs_layout
    TABLES
      t_outtab         = gt_outtab
    EXCEPTIONS
      OTHERS           = 1.


ENDFORM.                    " message_handling_3


*&---------------------------------------------------------------------*
*&      Form  message_handling_4
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM message_handling_4 .
* define local data



  CHECK ( p_opt4 = abap_true   OR
          p_opt5 = abap_true   OR
          p_opt6 = abap_true ).

  IF ( p_opt4 = abap_true ).
    gd_title = 'Information System 4 (IS4)'.
    SET TITLEBAR 'TITLE' WITH gd_title.
  ELSEIF ( p_opt5 = abap_true ).
    gd_title = 'Information System 5 (IS5)'.
    SET TITLEBAR 'TITLE' WITH gd_title.
  ELSE.
    gd_title = 'Information System 6 (IS6)'.
    SET TITLEBAR 'TITLE' WITH gd_title.
  ENDIF.

  PERFORM generate_messages.  " simulation of messages

  PERFORM display_log.



ENDFORM.                    " message_handling_4




*&---------------------------------------------------------------------*
*&      Form  GENERATE_MESSAGES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM generate_messages .
* define local data

  mac_build_msg 'Apollo 13 Mission: Spacecraft'
                 space space space 'I' '1'.
**  DEFINE mac_build_msg.
**    clear: gs_msg.
**    gs_msg-msgty = &5.
**    gs_msg-msgid = '00'.
**    gs_msg-msgno = '398'.
**    gs_msg-msgv1 = &1.
**    gs_msg-msgv2 = &2.
**    gs_msg-msgv3 = &3.
**    gs_msg-msgv4 = &4.
**    gs_msg-detlevel = &6.
**
**  END-OF-DEFINITION.

  go_msglist->add( is_message = gs_msg ).



  DO 6 TIMES.
    CASE syst-index.
      WHEN '1'.
        mac_build_msg 'Command and Service Module (CSM)'
           space space space 'I' '2'.

      WHEN '2'.
        mac_build_msg 'Lunar Module (LM)' space space space 'I' '2'.

      WHEN '3'.
        mac_build_msg 'Additional Module (M-1)'
          space space space 'I' '2'.

      WHEN '4'.
        mac_build_msg 'Additional Module (M-2)'
          space space space 'I' '2'.

      WHEN '5'.
        mac_build_msg 'Additional Module (M-3)'
          space space space 'I' '2'.

      WHEN '6'.
        mac_build_msg 'Additional Module (M-4)'
          space space space 'I' '2'.


      WHEN OTHERS.
        EXIT.
    ENDCASE.

    go_msglist->add( is_message = gs_msg ).
"   recursive call of routine
    PERFORM generate_messages_1 USING syst-index 'Modul' '3'.
  ENDDO.



ENDFORM.                    " GENERATE_MESSAGES


*&---------------------------------------------------------------------*
*&      Form  GENERATE_MESSAGES_1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM generate_messages_1
                     USING
                        value(ud_index)     TYPE i
                        value(ud_msgv)      TYPE symsgv
                        value(ud_detlevel)  TYPE ballevel.
* define local data
  DATA:
    ld_integer         TYPE i,
    ld_msgty           TYPE symsgty,
    ld_msgv            TYPE symsgv,
    ld_detlevel        TYPE ballevel.


  DO p_count TIMES.
    WRITE syst-index TO ld_msgv NO-ZERO LEFT-JUSTIFIED.
    IF ( ud_detlevel = '3' ).
      CONCATENATE ud_msgv ld_msgv INTO ld_msgv
        SEPARATED BY space.
    ELSE.
      CONCATENATE ud_msgv ld_msgv INTO ld_msgv
        SEPARATED BY '.'.
    ENDIF.
    CONDENSE ld_msgv.
    gd_msgv = ld_msgv.


    IF ( ud_index = 1 ).
      ld_integer = gif_random->get_random_int( 300 ).
      IF ( ld_integer = 1 ).
        ld_msgty = 'E'.
        CONCATENATE gd_msgv 'failed' INTO gd_msgv SEPARATED BY ' -> '.

      ELSEIF ( ld_integer BETWEEN 1 AND 10 ).
        ld_msgty = 'W'.
        CONCATENATE gd_msgv 'check(?)' INTO gd_msgv SEPARATED BY ' -> '.

      ELSE.
        ld_msgty = 'S'.
        CONCATENATE gd_msgv 'OK' INTO gd_msgv SEPARATED BY ' -> '.
      ENDIF.

    ELSE.
      ld_msgty = 'S'.
      CONCATENATE gd_msgv 'OK' INTO gd_msgv SEPARATED BY ' -> '.
    ENDIF.


    mac_build_msg gd_msgv space space space ld_msgty ud_detlevel.
    go_msglist->add( is_message = gs_msg ).

    IF ( ud_detlevel < p_level ).
      ld_detlevel = ud_detlevel + 1.

      PERFORM generate_messages_1 USING ud_index ld_msgv ld_detlevel.
    ENDIF.

  ENDDO.


ENDFORM.                    " GENERATE_MESSAGES_1


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_LOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_log .
* define local data
  DATA:
    ld_handle           TYPE balloghndl,
    lt_log_handles      TYPE bal_t_logh,
    ls_profile          TYPE bal_s_prof.


" Get log handle of collected message list
  ld_handle = go_msglist->get_handle( ).
  APPEND ld_handle TO lt_log_handles.


  IF ( p_opt4 = 'X' ).
*   get a display profile which describes how to display messages
    CALL FUNCTION 'BAL_DSP_PROFILE_DETLEVEL_GET'
      IMPORTING
        e_s_display_profile = ls_profile.  " tree & ALV list

  ELSEIF ( p_opt5 = 'X' ).
*   get standard profile to display one log
    CALL FUNCTION 'BAL_DSP_PROFILE_SINGLE_LOG_GET'
      IMPORTING
        e_s_display_profile = ls_profile.

  ELSE.
    CALL FUNCTION 'BAL_DSP_PROFILE_NO_TREE_GET'
      IMPORTING
        e_s_display_profile = ls_profile.
  ENDIF.



* set report to allow saving of variants
  ls_profile-disvariant-report = sy-repid.
*   when you use also other ALV lists in your report,
*   please specify a handle to distinguish between the display
*   variants of these different lists, e.g:
  ls_profile-disvariant-handle = 'LOG'.


  CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
    EXPORTING
      i_s_display_profile          = ls_profile
      i_t_log_handle               = lt_log_handles
    EXCEPTIONS
      profile_inconsistent         = 1
      internal_error               = 2
      no_data_available            = 3
      no_authority                 = 4
      OTHERS                       = 5.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " DISPLAY_LOG

Regards

Uwe

11 REPLIES 11

Former Member
0 Kudos

Hi,

Can you tell me what is your exact requirement. As why you want to store message, to show it at later stage?

If yes then the better idea is show the error message as it happens and to store the other messages you can define table of type BDCMSGCOLL.

Regards,

Atish

0 Kudos

Thanks,Atish.

I'm sorry I didn't say exactly.

There are many messages,for example,select nothing from data base, "MESSAGE E001 WITH ''."

And I want to store them into a internal table ,and at last,list them in a screen.

Thanks.

0 Kudos

Hi,

As I said in my earlier reply, it is the best way to show the error message as it happens, and program should not do further processing.

You can store all other messages in the internal table of the type BDCMSGCOLL.

Regards,

Atish

0 Kudos

Thanks very much!

But I want to store them into internal table which has only one column.

For example, MESSAGE S001 WITH 'MATNR',so I want to save it as 'select nothing form MATNR'.

0 Kudos

Use function module FORMAT_MESSAGE. You need to pass message id, message no, Language to this function module and the output will be message text. This you can store in the internal table and at the end you can display the same in report output.

ashish

0 Kudos

Hi,

then just define a internal table with one column and field of type string.

and instead of

MESSAGE S001 WITH 'MATNR'

you can write the corresoponding message to that field in the table.

Regards,

Atish

0 Kudos

Thank you , Atish.

But I don't know how to write message into internal, use FORMAT_MESSAGE?

Regards.

uwe_schieferstein
Active Contributor
0 Kudos

Hello Feng

If you are already working on SAP basis release >= 6.20 I would recommend the most versatile message handler of all: interface <b>IF_RECA_MESSAGE_LIST</b>

Perhaps you will find the following sample report ZUS_SDN_APOLLO_13

(see also: <a href="https://wiki.sdn.sap.com/wiki/display/profile/2007/07/09/MessageHandling-FindingtheNeedleintheHaystack">Message Handling - Finding the Needle in the Haystack</a>) useful.


*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_APOLLO_13
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_apollo_13
  LINE-SIZE 200.


TYPE-POOLS: abap.

TYPES: BEGIN OF ty_s_outtab.
TYPES:   status     TYPE exception.
INCLUDE TYPE bapiret2  AS msg.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab  TYPE STANDARD TABLE OF ty_s_outtab
                    WITH DEFAULT KEY.

DATA:
  gs_layout         TYPE lvc_s_layo,
  gt_outtab         TYPE ty_t_outtab.


DATA:
  gd_title          TYPE lvc_title,
  gd_msgv           TYPE symsgv,
  gd_msg            TYPE bapi_msg,
  gs_msg            TYPE recamsg,
  gs_return         TYPE bapiret2,
  gt_return         TYPE bapirettab,
  go_msglist        TYPE REF TO if_reca_message_list,
  go_random         TYPE REF TO cl_random_number,
  gif_random        TYPE REF TO if_random_number.




PARAMETERS:
  p_opt1  RADIOBUTTON GROUP radi  DEFAULT 'X',
  p_opt2  RADIOBUTTON GROUP radi,
  p_opt3  RADIOBUTTON GROUP radi.
SELECTION-SCREEN ULINE.
PARAMETERS:
  p_opt4  RADIOBUTTON GROUP radi,
  p_opt5  RADIOBUTTON GROUP radi,
  p_opt6  RADIOBUTTON GROUP radi.


SELECTION-SCREEN ULINE.
PARAMETERS:
  p_count    TYPE numc3     DEFAULT '4',
  p_level    TYPE ballevel  DEFAULT '7'.


DEFINE mac_build_msg.
  clear: gs_msg.
  gs_msg-msgty = &5.
  gs_msg-msgid = '00'.
  gs_msg-msgno = '398'.
  gs_msg-msgv1 = &1.
  gs_msg-msgv2 = &2.
  gs_msg-msgv3 = &3.
  gs_msg-msgv4 = &4.
  gs_msg-detlevel = &6.

END-OF-DEFINITION.

*  msgty
*  msgid
*  msgno
*  msgv1
*  msgv2
*  msgv3
*  msgv4
*  msgv1_src
*  msgv2_src
*  msgv3_src
*  msgv4_src
*  detlevel
*  probclass
*  alsort
*  time_stmp
*  msg_count
*  context
*  params


START-OF-SELECTION.

  " Create message handler
  go_msglist = cf_reca_message_list=>create( ).



  " Create random number instance
  CREATE OBJECT go_random TYPE cl_random_number.
  gif_random ?= go_random.
  gif_random->init( ).




  PERFORM message_handling_1.
  PERFORM message_handling_2.
  PERFORM message_handling_3.
*
  PERFORM message_handling_4.


END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&      Form  MESSAGE_HANDLING_1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM message_handling_1 .

  CHECK ( p_opt1 = abap_true ).
  gd_title = 'Information System 1 (IS1)'.
  SET TITLEBAR 'TITLE' WITH gd_title.

  WRITE: / 'Apollo 13 Mission'.
  WRITE: / syst-uline.

  WRITE: / 'Take-Off             -> ok'.
  WRITE: / 'Leaving Orbit        -> ok'.
  WRITE: / 'Trajectory           -> ok'.
  WRITE: /.

  FORMAT COLOR COL_NEGATIVE.
  WRITE: / 'Explosion happened   -> not ok'.
  WRITE: / 'Command and Service module (CSM) -> damaged'.
  FORMAT RESET.
  WRITE: / 'Lunar module (LM)    -> not affected, ok'.

  MESSAGE text-hou TYPE 'S'.

ENDFORM.                    " MESSAGE_HANDLING_1


*&---------------------------------------------------------------------*
*&      Form  message_handling_2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM message_handling_2 .
* define local data
  DATA:
    ld_success(6)  TYPE n,
    ld_warning(6)  TYPE n,
    ld_failure(6)  TYPE n,
    ld_total(6)    TYPE n.

  CHECK ( p_opt2 = abap_true ).
  gd_title = 'Information System 2 (IS2)'.
  SET TITLEBAR 'TITLE' WITH gd_title.

  PERFORM generate_messages.  " simulation of messages

  CALL METHOD go_msglist->get_list_as_bapiret
    IMPORTING
      et_list = gt_return.

  " Calculate message types and total
  ld_total   = 0.
  ld_success = 0.
  ld_warning = 0.
  ld_failure = 0.


" Print messages as WRITE list
  LOOP AT gt_return INTO gs_return.
    IF ( gs_return-type = 'E' ).
      ADD 1 TO ld_failure.

    ELSEIF ( gs_return-type = 'W' ).
      ADD 1 TO ld_warning.
    ELSE.
      ADD 1 TO ld_success.
    ENDIF.

  ENDLOOP.
  ld_total = ld_success + ld_warning + ld_failure.


  WRITE: / 'Total Message =', ld_total.
  WRITE: / 'Failures      =', ld_failure.
  WRITE: / 'Warnings      =', ld_warning.
  WRITE: / 'Successes     =', ld_success.
  WRITE: / syst-uline.
  SKIP.

" Colouring depending on message type
  LOOP AT gt_return INTO gs_return.
    IF ( gs_return-type = 'E' ).
      FORMAT COLOR COL_NEGATIVE.


    ELSEIF ( gs_return-type = 'W' ).
      FORMAT COLOR COL_TOTAL.

    ELSE.
      FORMAT RESET.
    ENDIF.

    WRITE: / gs_return-type, gs_return-message+0(100).
  ENDLOOP.


ENDFORM.                    " message_handling_2



*&---------------------------------------------------------------------*
*&      Form  message_handling_3
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM message_handling_3 .
* define local data
  DATA:
    ls_outtab    TYPE ty_s_outtab.

  DATA:
    ld_success(6)  TYPE n,
    ld_warning(6)  TYPE n,
    ld_failure(6)  TYPE n,
    ld_total(6)    TYPE n.


  CHECK ( p_opt3 = abap_true ).
  gd_title = 'Information System 3 (IS3)'.
  SET TITLEBAR 'TITLE' WITH gd_title.

  PERFORM generate_messages.  " simulation of messages

  CALL METHOD go_msglist->get_list_as_bapiret
    IMPORTING
      et_list = gt_return.

  REFRESH: gt_outtab.
  " Calculate message types and total
  ld_total   = 0.
  ld_success = 0.
  ld_warning = 0.
  ld_failure = 0.

" Define the logic for setting exception status (LED)
  LOOP AT gt_return INTO gs_return.
    CLEAR: ls_outtab.

    ls_outtab-msg = gs_return.

    IF ( gs_return-type = 'E' ).
      ls_outtab-status = '1'.  " red
      ADD 1 TO ld_failure.

    ELSEIF ( gs_return-type = 'W' ).
      ls_outtab-status = '2'.  " yellow
      ADD 1 TO ld_warning.

    ELSE.
      ls_outtab-status = '3'.  " green
      ADD 1 TO ld_success.
    ENDIF.

    APPEND ls_outtab TO gt_outtab.
  ENDLOOP.

  ld_total = ld_failure + ld_warning + ld_success.

  CLEAR: gs_layout.
  gs_layout-cwidth_opt = abap_true.
  gs_layout-zebra      = abap_true.

  gs_layout-excp_fname = 'STATUS'.
  gs_layout-excp_led   = abap_true.
  gs_layout-smalltitle = abap_true.

  CONCATENATE 'T(' ld_total   ')  '
              'E(' ld_failure ')  '
              'W(' ld_warning ')  '
              'S(' ld_success ')  '
    INTO gd_title SEPARATED BY space.


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_structure_name = 'BAPIRET2'
      i_grid_title     = gd_title
      is_layout_lvc    = gs_layout
    TABLES
      t_outtab         = gt_outtab
    EXCEPTIONS
      OTHERS           = 1.


ENDFORM.                    " message_handling_3


*&---------------------------------------------------------------------*
*&      Form  message_handling_4
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM message_handling_4 .
* define local data



  CHECK ( p_opt4 = abap_true   OR
          p_opt5 = abap_true   OR
          p_opt6 = abap_true ).

  IF ( p_opt4 = abap_true ).
    gd_title = 'Information System 4 (IS4)'.
    SET TITLEBAR 'TITLE' WITH gd_title.
  ELSEIF ( p_opt5 = abap_true ).
    gd_title = 'Information System 5 (IS5)'.
    SET TITLEBAR 'TITLE' WITH gd_title.
  ELSE.
    gd_title = 'Information System 6 (IS6)'.
    SET TITLEBAR 'TITLE' WITH gd_title.
  ENDIF.

  PERFORM generate_messages.  " simulation of messages

  PERFORM display_log.



ENDFORM.                    " message_handling_4




*&---------------------------------------------------------------------*
*&      Form  GENERATE_MESSAGES
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM generate_messages .
* define local data

  mac_build_msg 'Apollo 13 Mission: Spacecraft'
                 space space space 'I' '1'.
**  DEFINE mac_build_msg.
**    clear: gs_msg.
**    gs_msg-msgty = &5.
**    gs_msg-msgid = '00'.
**    gs_msg-msgno = '398'.
**    gs_msg-msgv1 = &1.
**    gs_msg-msgv2 = &2.
**    gs_msg-msgv3 = &3.
**    gs_msg-msgv4 = &4.
**    gs_msg-detlevel = &6.
**
**  END-OF-DEFINITION.

  go_msglist->add( is_message = gs_msg ).



  DO 6 TIMES.
    CASE syst-index.
      WHEN '1'.
        mac_build_msg 'Command and Service Module (CSM)'
           space space space 'I' '2'.

      WHEN '2'.
        mac_build_msg 'Lunar Module (LM)' space space space 'I' '2'.

      WHEN '3'.
        mac_build_msg 'Additional Module (M-1)'
          space space space 'I' '2'.

      WHEN '4'.
        mac_build_msg 'Additional Module (M-2)'
          space space space 'I' '2'.

      WHEN '5'.
        mac_build_msg 'Additional Module (M-3)'
          space space space 'I' '2'.

      WHEN '6'.
        mac_build_msg 'Additional Module (M-4)'
          space space space 'I' '2'.


      WHEN OTHERS.
        EXIT.
    ENDCASE.

    go_msglist->add( is_message = gs_msg ).
"   recursive call of routine
    PERFORM generate_messages_1 USING syst-index 'Modul' '3'.
  ENDDO.



ENDFORM.                    " GENERATE_MESSAGES


*&---------------------------------------------------------------------*
*&      Form  GENERATE_MESSAGES_1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM generate_messages_1
                     USING
                        value(ud_index)     TYPE i
                        value(ud_msgv)      TYPE symsgv
                        value(ud_detlevel)  TYPE ballevel.
* define local data
  DATA:
    ld_integer         TYPE i,
    ld_msgty           TYPE symsgty,
    ld_msgv            TYPE symsgv,
    ld_detlevel        TYPE ballevel.


  DO p_count TIMES.
    WRITE syst-index TO ld_msgv NO-ZERO LEFT-JUSTIFIED.
    IF ( ud_detlevel = '3' ).
      CONCATENATE ud_msgv ld_msgv INTO ld_msgv
        SEPARATED BY space.
    ELSE.
      CONCATENATE ud_msgv ld_msgv INTO ld_msgv
        SEPARATED BY '.'.
    ENDIF.
    CONDENSE ld_msgv.
    gd_msgv = ld_msgv.


    IF ( ud_index = 1 ).
      ld_integer = gif_random->get_random_int( 300 ).
      IF ( ld_integer = 1 ).
        ld_msgty = 'E'.
        CONCATENATE gd_msgv 'failed' INTO gd_msgv SEPARATED BY ' -> '.

      ELSEIF ( ld_integer BETWEEN 1 AND 10 ).
        ld_msgty = 'W'.
        CONCATENATE gd_msgv 'check(?)' INTO gd_msgv SEPARATED BY ' -> '.

      ELSE.
        ld_msgty = 'S'.
        CONCATENATE gd_msgv 'OK' INTO gd_msgv SEPARATED BY ' -> '.
      ENDIF.

    ELSE.
      ld_msgty = 'S'.
      CONCATENATE gd_msgv 'OK' INTO gd_msgv SEPARATED BY ' -> '.
    ENDIF.


    mac_build_msg gd_msgv space space space ld_msgty ud_detlevel.
    go_msglist->add( is_message = gs_msg ).

    IF ( ud_detlevel < p_level ).
      ld_detlevel = ud_detlevel + 1.

      PERFORM generate_messages_1 USING ud_index ld_msgv ld_detlevel.
    ENDIF.

  ENDDO.


ENDFORM.                    " GENERATE_MESSAGES_1


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_LOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_log .
* define local data
  DATA:
    ld_handle           TYPE balloghndl,
    lt_log_handles      TYPE bal_t_logh,
    ls_profile          TYPE bal_s_prof.


" Get log handle of collected message list
  ld_handle = go_msglist->get_handle( ).
  APPEND ld_handle TO lt_log_handles.


  IF ( p_opt4 = 'X' ).
*   get a display profile which describes how to display messages
    CALL FUNCTION 'BAL_DSP_PROFILE_DETLEVEL_GET'
      IMPORTING
        e_s_display_profile = ls_profile.  " tree & ALV list

  ELSEIF ( p_opt5 = 'X' ).
*   get standard profile to display one log
    CALL FUNCTION 'BAL_DSP_PROFILE_SINGLE_LOG_GET'
      IMPORTING
        e_s_display_profile = ls_profile.

  ELSE.
    CALL FUNCTION 'BAL_DSP_PROFILE_NO_TREE_GET'
      IMPORTING
        e_s_display_profile = ls_profile.
  ENDIF.



* set report to allow saving of variants
  ls_profile-disvariant-report = sy-repid.
*   when you use also other ALV lists in your report,
*   please specify a handle to distinguish between the display
*   variants of these different lists, e.g:
  ls_profile-disvariant-handle = 'LOG'.


  CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
    EXPORTING
      i_s_display_profile          = ls_profile
      i_t_log_handle               = lt_log_handles
    EXCEPTIONS
      profile_inconsistent         = 1
      internal_error               = 2
      no_data_available            = 3
      no_authority                 = 4
      OTHERS                       = 5.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                    " DISPLAY_LOG

Regards

Uwe

former_member223537
Active Contributor
0 Kudos

Hi,

types : begin of t_data,
              messg(50) type c,
           end of t_data.

data : itab type standard table of t_data,
         watab type t_data.


clear watab.

move 'Selecting nothing from matnr' to watab-messg.
append watab to itab.

move 'Error saving the record!' to watab-messg.
append watab to itab.

Best regards,

Prashant

Former Member

Hi , all.

I found a easy way to solve this problem.

MESSAGE E001 WITH 'ERROR' INTO WA_ERROR-TEXT.

Regards.

0 Kudos

Yes This is what I want.