Группа функций SBAL

Иногда бывает полезно не выводить сообщения по одному, а собрать их все в один список и вывести вместе. Для этого полезны ФМ группы функций SBAL:
BAL_LOG_CREATE – создание нового лога для последующего добавления в него сообщений
BAL_LOG_MSG_ADD – добавление сообщения в лог
BAL_LOG_MSG_DELETE_ALL – удаление всех сообщений из лога
BAL_DSP_LOG_DISPLAY – вывод списка сообщений на экран
BAL_LOG_HDR_READ – бывает удобно использовать, для проверки наличия сообщений в списке.

В группе функций SBAL есть и другие ФМ, я привел наиболее часто используемые.

Пример использования лога сообщений:

  DATA:
  s_log TYPE bal_s_log,
  g_log_handle TYPE balloghndl,
  gt_log_handle TYPE bal_t_logh,
  s_msg TYPE bal_s_msg,
  s_display_profile TYPE bal_s_prof,
  gt_mess_fcat TYPE TABLE OF bal_s_fcat WITH HEADER LINE,
  f_log_init,
  gv_exit_command TYPE bal_s_excm,
  l_message TYPE string,
  MSG_CNT type i.

MESSAGE e001(bc) INTO l_message.
perform add_log.

MESSAGE w001(bc) INTO l_message.
perform add_log.

MESSAGE i001(bc) INTO l_message.

perform add_log.

PERFORM CHECK_LOG
          CHANGING
           MSG_CNT.
if MSG_CNT > 0.
  perform display_log using 'Тест'.
endif.

write:/ 'BACK ->', gv_exit_command-BACK.
write:/ 'EXIT ->', gv_exit_command-EXIT.
write:/ 'CANCEL ->', gv_exit_command-CANCEL.
write:/ 'CONTINUE ->', gv_exit_command-CONTINUE.
write:/ 'EXTERNAL ->', gv_exit_command-EXTERNAL.

PERFORM delete_log.

*&---------------------------------------------------------------------*
*&      Form  init_log
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
FORM init_log.

  CHECK f_log_init IS INITIAL.

  f_log_init = 'X'.
  CLEAR s_log.
  s_log-extnumber = sy-uzeit.
  s_log-alprog    = sy-repid.
  s_log-aldate    = sy-datum.
  s_log-altime    = sy-uzeit.
  s_log-aluser    = sy-uname.
  CALL FUNCTION 'BAL_LOG_CREATE'
    EXPORTING
      i_s_log      = s_log
    IMPORTING
      e_log_handle = g_log_handle.

ENDFORM.                    "init_log

*&---------------------------------------------------------------------*
*&      Form  add_log
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
FORM add_log.

  IF f_log_init IS INITIAL.
    PERFORM init_log.
  ENDIF.

  CLEAR s_msg.
  s_msg-msgty = sy-msgty.
  s_msg-msgid = sy-msgid.
  s_msg-msgno = sy-msgno.
  s_msg-msgv1 = sy-msgv1.
  s_msg-msgv2 = sy-msgv2.
  s_msg-msgv3 = sy-msgv3.
  s_msg-msgv4 = sy-msgv4.

  CALL FUNCTION 'BAL_LOG_MSG_ADD'
    EXPORTING
      i_log_handle              = g_log_handle
      i_s_msg                  = s_msg
*  IMPORTING
*    E_S_MSG_HANDLE            =
*    E_MSG_WAS_LOGGED          =
*    E_MSG_WAS_DISPLAYED      =
*  EXCEPTIONS
*    LOG_NOT_FOUND            = 1
*    MSG_INCONSISTENT          = 2
*    LOG_IS_FULL              = 3
*    OTHERS                    = 4
    .
ENDFORM.                    "add_log

*---------------------------------------------------------------------*
*      FORM display_log                                              *
*---------------------------------------------------------------------*
FORM display_log USING p_title.
  DATA: l_title LIKE s_display_profile-title.

  CHECK NOT f_log_init IS INITIAL.

  IF p_title IS INITIAL.
    l_title = 'Список сообщений'.                          "#EC NOTEXT
  ELSE.
    l_title = p_title.
  ENDIF.

  REFRESH gt_mess_fcat.
  CLEAR gt_mess_fcat.
  gt_mess_fcat-ref_table = 'BAL_S_SHOW'.
  gt_mess_fcat-ref_field = 'LOGNUMBER'.
  gt_mess_fcat-no_out    = 'X'.
  gt_mess_fcat-col_pos = '0'.
  APPEND gt_mess_fcat.

  CLEAR gt_mess_fcat.
  gt_mess_fcat-ref_table = 'BAL_S_SHOW'.
  gt_mess_fcat-ref_field = 'MSGNUMBER'.
  gt_mess_fcat-no_out    = 'X'.
  gt_mess_fcat-col_pos = '0'.
  APPEND gt_mess_fcat.

  CLEAR gt_mess_fcat.
  gt_mess_fcat-ref_table = 'BAL_S_SHOW'.
  gt_mess_fcat-ref_field = 'T_MSG'.
  gt_mess_fcat-col_pos = '2'.
  APPEND gt_mess_fcat.

  CLEAR gt_mess_fcat.
  gt_mess_fcat-ref_table = 'BAL_S_SHOW'.
  gt_mess_fcat-ref_field = 'MSGID'.
  gt_mess_fcat-no_out    = 'X'.
  gt_mess_fcat-col_pos = '0'.
  APPEND gt_mess_fcat.

  CLEAR gt_mess_fcat.
  gt_mess_fcat-ref_table = 'BAL_S_SHOW'.
  gt_mess_fcat-ref_field = 'MSGNO'.
  gt_mess_fcat-no_out    = 'X'.
  gt_mess_fcat-col_pos = '0'.
  APPEND gt_mess_fcat.

  CLEAR gt_mess_fcat.
  gt_mess_fcat-ref_table = 'BAL_S_SHOW'.
  gt_mess_fcat-ref_field = 'MSGTY'.
  gt_mess_fcat-no_out    = 'X'.
  gt_mess_fcat-col_pos = '0'.
  APPEND gt_mess_fcat.

  CLEAR gt_mess_fcat.
  gt_mess_fcat-ref_table = 'BAL_S_SHOW'.
  gt_mess_fcat-ref_field = 'DETLEVEL'.
  gt_mess_fcat-no_out    = 'X'.
  gt_mess_fcat-col_pos = '0'.
  APPEND gt_mess_fcat.

  CLEAR gt_mess_fcat.
  gt_mess_fcat-ref_table = 'BAL_S_SHOW'.
  gt_mess_fcat-ref_field = 'T_PROBCLSS'.
  gt_mess_fcat-no_out    = 'X'.
  gt_mess_fcat-col_pos = '0'.
  APPEND gt_mess_fcat.

  CLEAR gt_mess_fcat.
  gt_mess_fcat-ref_table = 'BAL_S_SHOW'.
  gt_mess_fcat-ref_field = 'ALSORT'.
  gt_mess_fcat-no_out    = 'X'.
  gt_mess_fcat-col_pos = '0'.
  APPEND gt_mess_fcat.

  CLEAR gt_mess_fcat.
  gt_mess_fcat-ref_table = 'RBPROT'.
  gt_mess_fcat-ref_field = 'RBLGP'.
  gt_mess_fcat-col_pos = '5'.
  APPEND gt_mess_fcat.

  CLEAR gt_mess_fcat.
  gt_mess_fcat-ref_table = 'RBPROT'.
  gt_mess_fcat-ref_field = 'SOURCETXT'.
  gt_mess_fcat-col_pos = '6'.
  APPEND gt_mess_fcat.

  CLEAR s_display_profile.
  s_display_profile-langu = sy-langu.
  s_display_profile-title = l_title.
  s_display_profile-mess_fcat = gt_mess_fcat[].
  s_display_profile-start_col = 5.
  s_display_profile-start_row = 5.
  s_display_profile-end_col = 124.
  s_display_profile-end_row = 25.
  s_display_profile-pop_adjst = 'X'.
  s_display_profile-show_all = 'X'.
  s_display_profile-exp_level = 1.

  REFRESH gt_log_handle.
  APPEND g_log_handle TO gt_log_handle.

  CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
    EXPORTING
      i_s_display_profile = s_display_profile
      i_t_log_handle      = gt_log_handle
    IMPORTING
      e_s_exit_command    = gv_exit_command.

ENDFORM.                    "display_log

*&---------------------------------------------------------------------*
*&      Form  check_log
*&---------------------------------------------------------------------*
*      text
*----------------------------------------------------------------------*
*      -->C_MSG_CNT  text
*----------------------------------------------------------------------*
* проверка наличия сообщений
FORM check_log
  CHANGING
    c_msg_cnt TYPE i.

  DATA ls_scnt TYPE bal_s_scnt.

  IF NOT g_log_handle IS INITIAL.
    CALL FUNCTION 'BAL_LOG_HDR_READ'
      EXPORTING
        i_log_handle  = g_log_handle
      IMPORTING
        e_statistics  = ls_scnt
      EXCEPTIONS
        log_not_found = 0
        OTHERS        = 0.
  ENDIF.
  c_msg_cnt = ls_scnt-msg_cnt_al.

ENDFORM.                    "check_log

*---------------------------------------------------------------------*
*      FORM delete_log                                              *
*---------------------------------------------------------------------*
FORM delete_log.

  CHECK NOT g_log_handle IS INITIAL.

  CALL FUNCTION 'BAL_LOG_MSG_DELETE_ALL'
    EXPORTING
      i_log_handle  = g_log_handle
    EXCEPTIONS
      log_not_found = 0
      OTHERS        = 0.

ENDFORM.                    "delete_log

[/paid_content]

   
© 2013 sap-blog.ru
Яндекс.Метрика