Application Log

Aus SAP-Wiki
Wechseln zu: Navigation, Suche

Das Application Log ist eine Standardlösung von SAP, um sehr komfortable Möglichkeit Meldungen (Fehler, Erfolgsmeldungen etc.) lokal (temporär) oder persistent (dauerhaft) zu speichern und darzustellen.

Um übermäßig große Tabellengrößen zu verhindern, sollten Application Logs auf der Datenbank in regelmäßigen Abständen gelöscht werden, z. B. im Monatsrhythmus.

Funktionsbausteine

  • BAL_LOG_CREATE
  • BAL_LOG_MSG_ADD
  • BAL_DSP_LOG_DISPLAY

Dokumentation in SAP

  • Programm = SBAL_DOCUMENTATION
  • Transaktion = SBAL_DOCU_DISPLAY

Application Log Transaktionen

SLG0 (Objekte und Unterobjekte pflegen)

  • In der Transaktion werden die Objekte gepflegt. Optional können einem Objekt auch Unterobjekte zugewiesen werden, um eine feinere Untergliederung eines Objekts zu haben.

SLG1 (Protokoll anzeigen)

  • Transaktion SLG1

SLG1 1.JPG

SLG1 2.JPG

SLG2 (Protokoll löschen)

  • Transaktion SLG2

SLGD (Protokollanzeige mit Selektionsbild)

  • Transaktion SLGD = Report SBAL_DISPLAY_2

SBAL_TEST_REPORT (Test Application Log)

  • Transaktion SBAL_TEST_REPORT

SLGN (Pflege Nummernkreise)

  • Transaktion SLGN

Testprogramm SBAL_DEMO_01

Grundlagen

ApplicationLog1.jpg

Sobald eine Meldung mit dem Typ E = Error in der Liste steht, wird die Problemklasse rot dargestellt, damit man schon auf den ersten Blick erkennt, dass eine Einzelmeldung Aufmerksamkeit erfordert.

ApplicationLog2.jpg

Es können auch Meldungen ausgeblendet werden. Hier wurden die Erfolgsmeldungen ausgeblendet, sodass nur die Warnungen und Fehler verbleiben.

ApplicationLog3.jpg

Coding

report SBAL_DEMO_01 message-id bl.

***********************************************************************
***********************************************************************
*                   REPORT SBAL_DEMO_01
*
* This report shows a simple example how the application log function
* modules could be used.
* For this purpose this reports simulates the check of a flight
* (specified by carrier, connection ID and flight date).
* A log is created with BAL_LOG_CREATE.
* Messages are sent to this log using BAL_LOG_MSG_ADD
* (see form msg_add).
* Finally the log is displayed with BAL_DSP_LOG_DISPLAY.
* Nothing is saved on the database.
*
***********************************************************************
***********************************************************************


***********************************************************************
******************** SELECTION SCREEN *********************************
***********************************************************************
selection-screen begin of block b01 with frame title text-001.
parameters:
  p_carrid type bal_carrid default 'SF',
  p_connid type bal_connid default '0003',
  p_fldate type bal_fldate default sy-datum.
selection-screen end of block b01.


***********************************************************************
******************** CONSTANTS, TYPES, DATA ***************************
***********************************************************************
  set extended check off.
    include sbal_constants.
  set extended check on.
  data:
    g_s_log            type bal_s_log,
    g_value            type i,
    g_passenger        type bal_custmr,
    g_everything_ok(1) type c,
    g_dummy            type c.                               "#EC NEEDED


***********************************************************************
************************ MAIN PROGRAM *********************************
***********************************************************************
end-of-selection.

***************************************************************
* create a log where all messages should be added to
***************************************************************
* define some header data of this log
  g_s_log-extnumber = 'Application Log Demo'.             "#EC NOTEXT
  g_s_log-aluser    = sy-uname.
  g_s_log-alprog    = sy-repid.
* ... see structure BAL_S_LOG for further data ...
* ... which can be added to a log header       ...
* create a log
  call function 'BAL_LOG_CREATE'
       exporting
            i_s_log = g_s_log
       exceptions
            others  = 1.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.


***************************************************************
* do something to check if flight is allowed
***************************************************************
* ... result is negative:
* 305(BL): 'Flight allowance does not exist'
  message e305 into g_dummy.
  perform msg_add using probclass_very_high.


***************************************************************
* do something to check if weight is OK
***************************************************************
* ... result is negative:
* 301(BL): 'Maximum weigth is exceeded'
  message e301(bl) into g_dummy.
  perform msg_add using probclass_very_high.


***************************************************************
* do something to check if there are too many passengers
***************************************************************
* ... result is negative:
* 302(BL): 'Flight is overbooked'
  message e302(bl) into g_dummy.
  perform msg_add using probclass_high.


***************************************************************
* do something to check if airplane is available
***************************************************************
* ... result is negative:
* 303(BL): 'Airplane &1 is not available'
  message id 'BL' type 'E' number 303 with '747-400' into g_dummy.
  perform msg_add using probclass_high.


***************************************************************
* do something to check if the crew is OK
***************************************************************
* ... result is negative ....
* 308(BL): 'Stewardess &1 is ill and therefore not available'
  message e308(bl) with 'JONES' into g_dummy.
  perform msg_add using probclass_high.


***************************************************************
* do something to check if the crew has enough time to sleep
***************************************************************
* ... result is negative:
* 309(BL): 'Relax phases for the crew are too short'
  message e309(bl) into g_dummy.
  perform msg_add using probclass_high.


***************************************************************
* check passenger list
***************************************************************
  do 60 times.

*   derive passenger number
    write sy-index to g_passenger left-justified.

*   assumption: everything is OK for this passenger
    g_everything_ok = 'X'.


***************************************************************
*   non-smoker seat available ?
***************************************************************
*   ... for some passengers a non-smoker seat is not available:
    if g_passenger = 22 or g_passenger = 34 or g_passenger = 66.
*     310(BL): 'Passenger &1 can only be booked on smoker seat'
      message e310(bl) with g_passenger into g_dummy.
      perform msg_add using probclass_medium.
      g_everything_ok = ' '.
    endif.


***************************************************************
*   is payment checked ?
***************************************************************
*   ... for some passengers payment is not yet checked:
    g_value = sy-index mod 16.
    if g_value = 0.
*     304(BL): 'Payment for passenger &1 is not yet checked'
      message w304(bl) with g_passenger into g_dummy.
      perform msg_add using probclass_medium.
      g_everything_ok = ' '.
    else.
*     306(BL): 'Payment for passenger &1 is done'
      message s306(bl) with g_passenger into g_dummy.
      perform msg_add using probclass_medium.
    endif.


***************************************************************
*   did passenger cancel his flight ?
***************************************************************
*   ... some passnegers have cancelled their flight:
    g_value = sy-index mod 26.
    if g_value = 0.
*     307(BL): 'Flight for passenger &1 was cancelled'
      message s307(bl) with g_passenger into g_dummy.
      perform msg_add using probclass_medium.
      g_everything_ok = ' '.
    endif.


***************************************************************
*   Everything is OK
***************************************************************
*   ... when no errors occured everything is OK for this passenger:
    if g_everything_ok = 'X'.
*     311(BL): 'Booked flight for passenger &1 is checked and OK'
      message s311(bl) with g_passenger into g_dummy.
      perform msg_add using probclass_low.
    endif.

  enddo.


***************************************************************
* display log file
***************************************************************
* - we do not specify a display profile I_S_DISPLAY_PROFILE
*   since we want to use the standard profile
* - we also do not specify any filter (I_S_LOG_FILTER, ...
*   I_T_MSG_HANDLE) since we want to display all messages available
  call function 'BAL_DSP_LOG_DISPLAY'
*      EXPORTING
*           I_S_LOG_FILTER         =
*           I_T_LOG_CONTEXT_FILTER =
*           I_S_MSG_FILTER         =
*           I_T_MSG_CONTEXT_FILTER =
*           I_T_LOG_HANDLE         =
*           I_T_MSG_HANDLE         =
*           I_S_DISPLAY_PROFILE    =
*           I_AMODAL               = ' '
       exceptions
            others                 = 1.
  if sy-subrc <> 0.
    message id sy-msgid type 'S' number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.


***********************************************************************
******************  FORMS *********************************************
***********************************************************************
*--------------------------------------------------------------------
* FORM MSG_ADD
*--------------------------------------------------------------------
form msg_add using value(i_probclass) type bal_s_msg-probclass.
  data:
    l_s_msg type bal_s_msg.

* define data of message for Application Log
  l_s_msg-msgty     = sy-msgty.
  l_s_msg-msgid     = sy-msgid.
  l_s_msg-msgno     = sy-msgno.
  l_s_msg-msgv1     = sy-msgv1.
  l_s_msg-msgv2     = sy-msgv2.
  l_s_msg-msgv3     = sy-msgv3.
  l_s_msg-msgv4     = sy-msgv4.
  l_s_msg-probclass = i_probclass.
* ... see structure BAL_S_LOG or report SBAL_DEMO_02 for ...
* ... further data which can be added to a message       ...

* add this message to log file
* we do not specify I_LOG_HANDLE since we want to add this message
* to the default log. If it does not exist we do not care
* (EXCEPTIONS log_not_found = 0).
  call function 'BAL_LOG_MSG_ADD'
       exporting
            i_s_msg       = l_s_msg
*           I_LOG_HANDLE  =
       exceptions
            log_not_found = 0
            others        = 1.
  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.

Application Log mit Zusatzfeldern (Kontext)

  • Der Application Log kann auch um zusätzliche Felder angereichert werden
  • Beispielreport = SBAL_DEMO_02

Siehe auch Tricktresor: Application Log mit Kontext

Tabellen

  • In der Tabelle BALHDR stehen die persistent abgespeicherten Application Logs.
  • Hier lässt sich dann gut prüfen welche Application Log Objekte und Unterobjekte genutzt werden, bzw. nicht genutzt werden.

YouTube

Application Log

Web-Links

Literatur