SAP Appln Log

4
Application events can be centrally logged in the application log. The advantage is system-wide message logging, which is convenient, easy to analyze. Several different logs (for various objects) can be written at the same time by an application. The application log can also be used as a message collector. Depending upon the message type, messages are displayed in a user friendly interface. Easy to understand at first glance. Before we start with the coding some config has to be done. Lets get started. Define application log objects via T-Code SLG0 Call the maintenance transaction with Tools - ABAP/4 Workbench - Development - Other tools - Application log. Choose New entries. An empty input area is displayed. Enter an object name according to the naming convention: - first character "Y" or "Z" - second and third character: application ID (e.g. FI) - fourth position, any character Enter a descriptive short text. Save your entries. If you want to define sub-objects: 1. Choose the line with the object. 2. Choose Table view - Other view. A structure overview is displayed for selection. 3. Position the cursor on "Sub-objects", and choose Choose. The sub-object display window for the chosen object is displayed. 4. Choose New entries. 5. Enter a sub-object name (beginning with "Y" or "Z") and a descriptive short text. 6. Save your entries. In our example we will use the Objects / Subobjects which are already created in the system. (Create your own objects when implimenting in live systems). Object - /BA1/B0 SubObject - DEFAULT

description

Createa an application log of the process

Transcript of SAP Appln Log

Page 1: SAP Appln Log

Application events can be centrally logged in the application log. The advantage is system-wide message logging,

which is convenient, easy to analyze.

Several different logs (for various objects) can be written at the same time by an application. The application log

can also be used as a message collector.

Depending upon the message type, messages are displayed in a user friendly interface. Easy to understand at first

glance.

Before we start with the coding some config has to be done. Lets get started.

Define application log objects via T-Code SLG0

Call the maintenance transaction with Tools - ABAP/4 Workbench - Development - Other tools - Application log.

Choose New entries. An empty input area is displayed.

Enter an object name according to the naming convention:

- first character "Y" or "Z"

- second and third character: application ID (e.g. FI)

- fourth position, any character

Enter a descriptive short text.

Save your entries.

If you want to define sub-objects:

1. Choose the line with the object.

2. Choose Table view - Other view. A structure overview is displayed for selection.

3. Position the cursor on "Sub-objects", and choose Choose. The sub-object display window for the chosen object is displayed.

4. Choose New entries.

5. Enter a sub-object name (beginning with "Y" or "Z") and a descriptive short text.

6. Save your entries.

In our example we will use the Objects / Subobjects which are already created in the system. (Create your own objects when

implimenting in live systems).

Object  -      /BA1/B0

SubObject  -    DEFAULT

Page 2: SAP Appln Log

 

 Go to SE80 and create a Function Module ZLOG.

 FUNCTION zlog.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     REFERENCE(FI_OBJECT) TYPE  BALOBJ_D DEFAULT '/BA1/B0'

*"     REFERENCE(FI_SUBOBJECT) TYPE  BALSUBOBJ DEFAULT 'DEFAULT'

*"  TABLES

*"      FT_MESSAGES TYPE  BAPIRET2_T

*"----------------------------------------------------------------------

  FIELD-SYMBOLS:

    <lv_msg> TYPE bapiret2.

  DATA:

    lv_message(300)   TYPE c,

    ls_log            TYPE bal_s_log,

    lv_loghandle      TYPE balloghndl,

    lt_loghandle      TYPE bal_t_logh.

* open log

  ls_log-object    = fi_object.

  ls_log-subobject = fi_subobject.

  ls_log-aluser    = sy-uname.

  ls_log-alprog    = sy-repid.

  CALL FUNCTION 'BAL_LOG_CREATE'                            "#EC *

     EXPORTING

       i_s_log      = ls_log

     IMPORTING

       e_log_handle = lv_loghandle

     EXCEPTIONS

       OTHERS       = 1.

  LOOP AT ft_messages ASSIGNING <lv_msg>.

    lv_message = <lv_msg>-message.

    IF NOT <lv_msg>-message_v1 IS INITIAL. REPLACE FIRST OCCURRENCE OF '&' IN lv_message WITH <lv_msg>-

Page 3: SAP Appln Log

message_v1. ENDIF.

    IF NOT <lv_msg>-message_v2 IS INITIAL. REPLACE FIRST OCCURRENCE OF '&' IN lv_message WITH <lv_msg>-

message_v2. ENDIF.

    IF NOT <lv_msg>-message_v3 IS INITIAL. REPLACE FIRST OCCURRENCE OF '&' IN lv_message WITH <lv_msg>-

message_v3. ENDIF.

    IF NOT <lv_msg>-message_v4 IS INITIAL. REPLACE FIRST OCCURRENCE OF '&' IN lv_message WITH <lv_msg>-

message_v4. ENDIF.

    CALL FUNCTION 'BAL_LOG_MSG_ADD_FREE_TEXT'               "#EC *

      EXPORTING

        i_log_handle              = lv_loghandle

        i_msgty                   = <lv_msg>-type

        i_text                    = lv_message

      EXCEPTIONS

        log_not_found             = 1

        msg_inconsistent          = 2

        log_is_full               = 3

        OTHERS                    = 4.

  ENDLOOP.

  INSERT lv_loghandle INTO TABLE lt_loghandle.

  CALL FUNCTION 'BAL_DB_SAVE'                               "#EC *

    EXPORTING

      i_save_all       = ' '

      i_t_log_handle   = lt_loghandle

    EXCEPTIONS

      log_not_found    = 1

      save_not_allowed = 2

      numbering_error  = 3

      OTHERS           = 4.

ENDFUNCTION.

 

Results

Lets execute the function module with default parameters

 FI_OBJECT                       /BA1/B0

 FI_SUBOBJECT                    DEFAULT

and populate the ft_message table in the Test Environment.

Page 4: SAP Appln Log

 

 

For getting into more details of Application log you have following Function Groups in hand.

Create application log  - Function group SLG0

Display application log - Function group SLG3

Read application log    - Function group SLG1

Delete application log  - Function group SLG2