Universal Application Log Routines

Nützliche Abap Codes und Code Fragmente

Universal Application Log Routines

Postby Tron » Sun Jan 26, 2020 2:25 pm

Y_BAL_LOG erzeugt Log Einträge im Speicher und zeigt das Ergebneis als POPUP.

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. FUNCTION y_bal_log.
  2. *"----------------------------------------------------------------------
  3. *"*"Local Interface:
  4. *"  IMPORTING
  5. *"     REFERENCE(I_MSGTY) TYPE  SYMSGTY OPTIONAL
  6. *"     REFERENCE(I_MSGID) TYPE  SYMSGID OPTIONAL
  7. *"     REFERENCE(I_MSGNO) TYPE  SYMSGNO OPTIONAL
  8. *"     REFERENCE(I_MSGV1) OPTIONAL
  9. *"     REFERENCE(I_MSGV2) OPTIONAL
  10. *"     REFERENCE(I_MSGV3) OPTIONAL
  11. *"     REFERENCE(I_MSGV4) OPTIONAL
  12. *"     REFERENCE(I_DISPLAY) TYPE  XFELD OPTIONAL
  13. *"     REFERENCE(I_REFRESH) TYPE  XFELD OPTIONAL
  14. *"     REFERENCE(I_REPID) TYPE  SYREPID
  15. *"  EXCEPTIONS
  16. *"      ERROR_CREATE
  17. *"      ERROR_ADD_MESSAGE
  18. *"      ERROR_REFRESH
  19. *"      ERROR_DISPLAY_PROFILE
  20. *"      ERROR_DISPLAY
  21. *"----------------------------------------------------------------------
  22. * Konstanten TRU, FALSE global
  23.  
  24.   DATA:
  25.       l_log_handle TYPE balloghndl,
  26.       l_s_log      TYPE bal_s_log,
  27.       l_s_display_profile TYPE bal_s_prof,
  28.       l_msg TYPE bal_s_msg,
  29.       l_t_handle TYPE bal_t_logh,
  30.       l_create     TYPE xfeld.
  31.  
  32.   CONSTANTS: cx_true(1) VALUE 'X',
  33.   cx_false(1) VALUE ' '.
  34.  
  35. * Handle aus memory lesen
  36.   IMPORT l_log_handle TO l_log_handle FROM MEMORY ID 'Z_LOG_HANDLE'.
  37.   IF sy-subrc NE 0 OR
  38.      l_log_handle IS INITIAL.
  39.     l_create = cx_true.
  40.   ELSE.
  41.     l_create = cx_false.
  42.   ENDIF.
  43.  
  44.   IF l_create EQ cx_false.
  45. * Suche nach Protokoll (bereits im Speicher angelegt??)
  46.     INSERT l_log_handle INTO TABLE l_t_handle.
  47.  
  48.     CALL FUNCTION 'BAL_GLB_SEARCH_LOG'
  49.       EXPORTING
  50.         i_t_log_handle = l_t_handle
  51.       EXCEPTIONS
  52.         log_not_found  = 1
  53.         OTHERS         = 2.
  54.     IF sy-subrc NE 0.
  55.       l_create = cx_true.
  56.     ENDIF.
  57.   ENDIF.
  58.   DATA:
  59.     def TYPE bal_s_mdef .
  60.  
  61.   IF l_create EQ cx_true.
  62. * Noch nicht angelegt, also kreieren
  63.     CALL FUNCTION 'BAL_GLB_MSG_DEFAULTS_GET'
  64.       IMPORTING
  65.         e_s_msg_defaults = def.
  66.     CALL FUNCTION 'BAL_GLB_MSG_DEFAULTS_SET'
  67.       EXPORTING
  68. *   I_AUTHORIZATION             =
  69.         i_s_msg_defaults            = def
  70.      EXCEPTIONS
  71.        not_authorized              = 1
  72.        defaults_inconsistent       = 2
  73.        OTHERS                      = 3
  74.               .
  75.     IF sy-subrc <> 0.
  76.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  77.               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  78.     ENDIF.
  79.  
  80.     l_s_log-extnumber  = 'Application Log'(001).
  81.     CALL FUNCTION 'BAL_LOG_CREATE'
  82.       EXPORTING
  83.         i_s_log      = l_s_log
  84.       IMPORTING
  85.         e_log_handle = l_log_handle
  86.       EXCEPTIONS
  87.         OTHERS       = 1.
  88.     IF sy-subrc <> 0.
  89.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  90.                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
  91.                RAISING error_create.
  92.     ELSE.
  93.       EXPORT l_log_handle FROM l_log_handle TO MEMORY ID 'Z_LOG_HANDLE'.
  94.  
  95.     ENDIF.
  96.  
  97.   ENDIF.
  98.  
  99. ************************************************************************
  100. * Message hinzufügen
  101. ************************************************************************
  102.   IF NOT i_msgty IS INITIAL.
  103.     l_msg-msgty = i_msgty.
  104.     l_msg-msgid = i_msgid.
  105.     l_msg-msgno = i_msgno.
  106.     l_msg-msgv1 = i_msgv1.
  107.     l_msg-msgv2 = i_msgv2.
  108.     l_msg-msgv3 = i_msgv3.
  109.     l_msg-msgv4 = i_msgv4.
  110. *'BAL_LOG_MSG_ADD'
  111.     CALL FUNCTION 'BAL_LOG_MSG_CUMULATE'
  112.       EXPORTING
  113.         i_log_handle = l_log_handle
  114.         i_s_msg      = l_msg
  115.       EXCEPTIONS
  116.         OTHERS       = 1.
  117.     IF sy-subrc <> 0.
  118.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  119.                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
  120.                RAISING error_add_message.
  121.     ENDIF.
  122.   ENDIF.
  123. ************************************************************************
  124. * Protokoll anzeigen
  125. ************************************************************************
  126.   IF NOT i_display IS INITIAL.
  127.     CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
  128.       IMPORTING
  129.         e_s_display_profile = l_s_display_profile
  130.       EXCEPTIONS
  131.         OTHERS              = 1.
  132.     IF sy-subrc <> 0.
  133.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  134.                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
  135.                RAISING error_display_profile.
  136.     ENDIF.
  137.  
  138.     l_s_display_profile-use_grid = cx_true.
  139.     l_s_display_profile-disvariant-report = i_repid.
  140.     l_s_display_profile-disvariant-handle = 'LOG'.
  141.     l_s_display_profile-cwidth_opt = cx_true.
  142.     l_s_display_profile-pop_adjst = cx_true.
  143.  
  144.     DATA:
  145.       l_s_msg_filter  TYPE bal_s_mfil,
  146.       l_r_msgty       TYPE bal_s_msty,
  147.       l_r_probclass   TYPE bal_s_prcl.
  148.  
  149. * Meldungstyp definieren
  150. *    l_r_msgty-option   = 'EQ'.
  151. *    l_r_msgty-sign     = 'I'.
  152. *    l_r_msgty-low      = 'E'. "Fehler
  153. *    APPEND l_r_msgty TO l_s_msg_filter-msgty.
  154. *    l_r_msgty-option   = 'EQ'.
  155. *    l_r_msgty-sign     = 'I'.
  156. *    l_r_msgty-low      = 'S'. "Fehler
  157. *    APPEND l_r_msgty TO l_s_msg_filter-msgty.
  158. * Problemklasse definieren
  159. *    l_r_probclass-option   = 'NE'.
  160. *    l_r_probclass-sign     = 'I'.
  161. *    l_r_probclass-low      = '4'. "Zusatzinformationen
  162. *    APPEND l_r_probclass TO l_s_msg_filter-probclass.
  163. *
  164.  
  165.     CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
  166.       EXPORTING
  167.         i_s_display_profile = l_s_display_profile
  168.         i_s_msg_filter      = l_s_msg_filter
  169.         i_amodal            = cx_false
  170.       EXCEPTIONS
  171.         OTHERS              = 1.
  172.  
  173.     IF sy-subrc <> 0.
  174.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  175.                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
  176.                RAISING error_display.
  177.     ENDIF.
  178.   ENDIF.
  179. ************************************************************************
  180. * Protokoll löschen
  181. ************************************************************************
  182.   IF NOT i_refresh IS INITIAL.
  183.     CALL FUNCTION 'BAL_LOG_REFRESH'
  184.       EXPORTING
  185.         i_log_handle  = l_log_handle
  186.       EXCEPTIONS
  187.         log_not_found = 1
  188.         OTHERS        = 2.
  189.     IF sy-subrc <> 0.
  190.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  191.               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
  192.               RAISING error_refresh.
  193.     ENDIF.
  194.     FREE MEMORY ID 'Z_LOG_HANDLE'.
  195.  
  196.   ENDIF.
  197.  
  198.  
GeSHi ©


Y_BAL_LOG_DB erzeugt Log Einträge auf der Datenbank und zeigt das Ergebneis über Ta SLG1.
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. FUNCTION y_bal_log_db.
  2. *"----------------------------------------------------------------------
  3. *"*"Local Interface:
  4. *"  IMPORTING
  5. *"     REFERENCE(I_S_LOG) TYPE  BAL_S_LOG OPTIONAL
  6. *"     REFERENCE(I_MSGTY) TYPE  SYMSGTY OPTIONAL
  7. *"     REFERENCE(I_MSGID) TYPE  SYMSGID OPTIONAL
  8. *"     REFERENCE(I_MSGNO) TYPE  SYMSGNO OPTIONAL
  9. *"     REFERENCE(I_MSGV1) OPTIONAL
  10. *"     REFERENCE(I_MSGV2) OPTIONAL
  11. *"     REFERENCE(I_MSGV3) OPTIONAL
  12. *"     REFERENCE(I_MSGV4) OPTIONAL
  13. *"     REFERENCE(I_SAVE) TYPE  XFELD DEFAULT ' '
  14. *"     REFERENCE(I_DISPLAY) TYPE  XFELD DEFAULT ' '
  15. *"     REFERENCE(I_REFRESH) TYPE  XFELD OPTIONAL
  16. *"     REFERENCE(I_REPID) TYPE  SYREPID
  17. *"  EXCEPTIONS
  18. *"      ERROR_CREATE
  19. *"      ERROR_ADD_MESSAGE
  20. *"      ERROR_REFRESH
  21. *"      ERROR_DISPLAY_PROFILE
  22. *"      ERROR_SAVE
  23. *"      ERROR_DISPLAY
  24. *"----------------------------------------------------------------------
  25. * Konstanten TRU, FALSE global
  26.  
  27.   DATA:
  28.       l_log_handle TYPE balloghndl,
  29.       l_s_display_profile TYPE bal_s_prof,
  30.       l_msg TYPE bal_s_msg,
  31.       gs_log_head TYPE bal_s_log,
  32.       l_t_handle TYPE bal_t_logh,
  33.       l_create     TYPE xfeld.
  34.  
  35.   CONSTANTS: cx_true(1) VALUE 'X',
  36.   cx_false(1) VALUE ' '.
  37.  
  38. * Handle aus memory lesen
  39.   IMPORT l_log_handle TO l_log_handle FROM MEMORY ID 'Z_LOG_HANDLE'.
  40.   IF sy-subrc NE 0 OR
  41.      l_log_handle IS INITIAL.
  42.     l_create = cx_true.
  43.   ELSE.
  44.     l_create = cx_false.
  45.   ENDIF.
  46.  
  47.   IF l_create EQ cx_false.
  48. * Suche nach Protokoll (bereits im Speicher angelegt??)
  49.     INSERT l_log_handle INTO TABLE l_t_handle.
  50.  
  51.     CALL FUNCTION 'BAL_GLB_SEARCH_LOG'
  52.       EXPORTING
  53.         i_t_log_handle = l_t_handle
  54.       EXCEPTIONS
  55.         log_not_found  = 1
  56.         OTHERS         = 2.
  57.     IF sy-subrc NE 0.
  58.       l_create = cx_true.
  59.     ENDIF.
  60.   ENDIF.
  61.   DATA:
  62.     def TYPE bal_s_mdef .
  63.  
  64.   IF l_create EQ cx_true.
  65. * Noch nicht angelegt, also kreieren
  66.     CALL FUNCTION 'BAL_GLB_MSG_DEFAULTS_GET'
  67.       IMPORTING
  68.         e_s_msg_defaults = def.
  69.     CALL FUNCTION 'BAL_GLB_MSG_DEFAULTS_SET'
  70.       EXPORTING
  71. *       I_AUTHORIZATION       =
  72.         i_s_msg_defaults      = def
  73.       EXCEPTIONS
  74.         not_authorized        = 1
  75.         defaults_inconsistent = 2
  76.         OTHERS                = 3.
  77.     IF sy-subrc <> 0.
  78.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  79.               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  80.     ENDIF.
  81.  
  82. *    i_s_log-extnumber  = 'Application Log'(001).
  83.     IF NOT i_s_log IS INITIAL.
  84.       gs_log_head = i_s_log.
  85.     ELSE.
  86.       gs_log_head-object = 'ARCHIVING'.
  87.       gs_log_head-subobject = 'SUMLOG'.
  88.       gs_log_head-aldate = sy-datum.
  89.       gs_log_head-altime = sy-uzeit.
  90.       gs_log_head-aluser = sy-uname.
  91.       gs_log_head-altcode = sy-tcode.
  92.       gs_log_head-alprog = sy-repid.
  93.       gs_log_head-almode = 'D'.
  94. *     gs_log_head-ALDATE_DEL = sy-datum + 100. " 100 Tage
  95. *     gs_log_head-DEL_BEFORE = 'X'.
  96.     ENDIF.
  97.  
  98.     CALL FUNCTION 'BAL_LOG_CREATE'
  99.       EXPORTING
  100.         i_s_log      = gs_log_head
  101.       IMPORTING
  102.         e_log_handle = l_log_handle
  103.       EXCEPTIONS
  104.         OTHERS       = 1.
  105.     IF sy-subrc <> 0.
  106.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  107.                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
  108.                RAISING error_create.
  109.     ELSE.
  110.       EXPORT l_log_handle FROM l_log_handle TO MEMORY ID 'Z_LOG_HANDLE'.
  111.  
  112.     ENDIF.
  113.  
  114.   ENDIF.
  115.  
  116. ************************************************************************
  117. * Message hinzufügen
  118. ************************************************************************
  119.   IF NOT i_msgty IS INITIAL.
  120.     l_msg-msgty = i_msgty.
  121.     l_msg-msgid = i_msgid.
  122.     l_msg-msgno = i_msgno.
  123.     l_msg-msgv1 = i_msgv1.
  124.     l_msg-msgv2 = i_msgv2.
  125.     l_msg-msgv3 = i_msgv3.
  126.     l_msg-msgv4 = i_msgv4.
  127. *'BAL_LOG_MSG_ADD'
  128.     CALL FUNCTION 'BAL_LOG_MSG_CUMULATE'
  129.       EXPORTING
  130.         i_log_handle = l_log_handle
  131.         i_s_msg      = l_msg
  132.       EXCEPTIONS
  133.         OTHERS       = 1.
  134.     IF sy-subrc <> 0.
  135.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  136.                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
  137.                RAISING error_add_message.
  138.     ENDIF.
  139.   ENDIF.
  140. ************************************************************************
  141. * Protokoll anzeigen
  142. ************************************************************************
  143.   IF NOT i_display IS INITIAL.
  144.  
  145.     CLEAR l_s_display_profile.
  146.  
  147. *CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
  148. *  IMPORTING
  149. *    e_s_display_profile = ls_anzeigeprofil.
  150.  
  151.     CALL FUNCTION 'BAL_DSP_PROFILE_SINGLE_LOG_GET'
  152.       IMPORTING
  153.         e_s_display_profile = l_s_display_profile.
  154.  
  155.     CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
  156.       EXPORTING
  157.         i_s_display_profile  = l_s_display_profile
  158.         i_t_log_handle       = l_t_handle
  159.         i_amodal             = ' '
  160.       EXCEPTIONS
  161.         profile_inconsistent = 1
  162.         internal_error       = 2
  163.         no_data_available    = 3
  164.         no_authority         = 4
  165.         OTHERS               = 5.
  166.  
  167.     IF sy-subrc <> 0.
  168.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  169.               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  170.     ENDIF.
  171.  
  172.   ENDIF.
  173.  
  174. ************************************************************************
  175. * Protokoll auf Datenbank speichern
  176. ************************************************************************
  177.  
  178.   IF NOT i_save IS INITIAL.
  179. *   save logs
  180.     CALL FUNCTION 'BAL_DB_SAVE'
  181.       EXPORTING
  182.         i_save_all = 'X'
  183.       EXCEPTIONS
  184.         OTHERS     = 1.
  185.     IF sy-subrc <> 0.
  186.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  187.               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  188.     ENDIF.
  189.  
  190.   ENDIF.
  191.  
  192.  
  193. ************************************************************************
  194. * Protokoll löschen
  195. ************************************************************************
  196.   IF NOT i_refresh IS INITIAL.
  197.     CALL FUNCTION 'BAL_LOG_REFRESH'
  198.       EXPORTING
  199.         i_log_handle  = l_log_handle
  200.       EXCEPTIONS
  201.         log_not_found = 1
  202.         OTHERS        = 2.
  203.     IF sy-subrc <> 0.
  204.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  205.               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
  206.               RAISING error_refresh.
  207.     ENDIF.
  208.     FREE MEMORY ID 'Z_LOG_HANDLE'.
  209.  
  210.   ENDIF.
  211.  
  212.  
GeSHi ©
Tron
.....
.....
 
Posts: 1094
Joined: Sat Aug 04, 2007 10:21 pm

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest

cron
  • Latest Topics