應用程式日誌Sample

sapkitty發表於2007-02-02

以下是一個應用程式日誌的例子,

主要用到了:BAL_LOG_CREATE、BAL_LOG_MSG_ADD、BAL_DB_SAVE這幾個FUNCTION。

[@more@]

REPORT Z_APP_LOG.

*----------------------------------------------------------------------*
* CONSTANTS DEFINITION
*----------------------------------------------------------------------*
CONSTANTS:
PROBCLASS_VERY_HIGH TYPE BAL_S_MSG-PROBCLASS VALUE '1'.

*----------------------------------------------------------------------*
* DATA DEFINITION
*----------------------------------------------------------------------*
DATA:
G_S_LOG TYPE BAL_S_LOG, "Log header data
G_LOG_HANDLE TYPE BALLOGHNDL, "Log handle
G_MSG(72) TYPE C.

DATA:
L_S_MSG TYPE BAL_S_MSG, "Message Data
LOGNUMBER TYPE BAL_T_LGNM, "Newly-Assigned LOGNUMBER Table
WA_LOGNUMBER LIKE BAL_S_LGNM, "Newly assigned LOGNUMBER
LT_BALLOGHNDL TYPE BAL_T_LOGH. "Log handle internal table

*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.

* Define header data of this log
G_S_LOG-EXTNUMBER = 'Application Log Demo'.
G_S_LOG-OBJECT = 'BCT1'.
G_S_LOG-ALDATE = SY-DATUM.
G_S_LOG-ALTIME = SY-UZEIT.
G_S_LOG-ALUSER = SY-UNAME.
G_S_LOG-ALPROG = SY-REPID.

* Create a log
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
I_S_LOG = G_S_LOG
IMPORTING
E_LOG_HANDLE = G_LOG_HANDLE
EXCEPTIONS
LOG_HEADER_INCONSISTENT = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.

* Store log handle in global internal table for DB save later & flush
APPEND G_LOG_HANDLE TO LT_BALLOGHNDL.

MESSAGE I000(VZ) INTO G_MSG.
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 = PROBCLASS_VERY_HIGH.

CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
I_S_MSG = L_S_MSG
I_LOG_HANDLE = G_LOG_HANDLE
EXCEPTIONS
LOG_NOT_FOUND = 0
OTHERS = 1.

IF SY-SUBRC <> 0.
ELSE.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
I_CLIENT = SY-MANDT
I_IN_UPDATE_TASK = ' '
I_SAVE_ALL = ' '
I_T_LOG_HANDLE = LT_BALLOGHNDL
IMPORTING
E_NEW_LOGNUMBERS = LOGNUMBER
EXCEPTIONS
LOG_NOT_FOUND = 1
SAVE_NOT_ALLOWED = 2
NUMBERING_ERROR = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
ELSE.
READ TABLE LOGNUMBER INTO WA_LOGNUMBER INDEX 1.
MESSAGE I000(VZ) WITH WA_LOGNUMBER-LOGNUMBER.
ENDIF.

ENDIF.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8214011/viewspace-897041/,如需轉載,請註明出處,否則將追究法律責任。

相關文章