Skip to Content
Author's profile photo Debopriya Ghosh

Global Class and Method for Application Log

The goal of the object is to create the Global Class and Method for Application Log so that it can be reused where necessary in any RICEF object.

Application Log provides an infrastructure for collecting messages and exceptions in a log, saving, reading and deleting logs in the database and displaying them.

Application Log provides multiple advantages:

  • System-wide uniform event logging
  • Accessible standardized UI based on ABAP List Viewer (ALV)
  • High capabilities for analysis of log data  

Application logging records the progress of the execution of an application. Whereas the system log records system events, you can use the application log to record application-specific events.

Application Log is designed to temporarily store messages. Logs should be deleted in intervals (e.g. weekly batch job for deleting logs) to avoid too high database load.

A typical use of the Application Log is within delivery processing. Negative results of a dangerous goods check are written to the Application Log. Application messages and reactions are collected based on a customer defined examination schema (reactions determine how the document will be handled further). This approach increases the transparency of the process for end users. Messages are collected temporarily and are not saved to the database.


First create object and sub object, Go to transaction SLG0.

Go to change mode and click on New entries button on the application tool bar. 


/wp-content/uploads/2014/05/1_448371.jpg

Then define the sub object for the object.

Select the object and double click on sub object.

/wp-content/uploads/2014/05/2_448400.jpg

Create Global Class and Method to define the Application log code

/wp-content/uploads/2014/05/3_448401.jpg


Define the following Parameter in Method

/wp-content/uploads/2014/05/6_448408.jpg

Define following Data in the Method

/wp-content/uploads/2014/05/7_448413.jpg

Populate the Header data with the following details

/wp-content/uploads/2014/05/8_448414.jpg

Create the log with FM BAL_LOG_CREATE

/wp-content/uploads/2014/05/9_448415.jpg

Add all the message in the log using FM BAL_LOG_MSG_ADD

/wp-content/uploads/2014/05/10_448416.jpg

Save the Log using FM BAL_DB_SAVE

/wp-content/uploads/2014/05/11_448417.jpg

Display the log using FM  BAL_DSP_LOG_DISPLAY

/wp-content/uploads/2014/05/12_448418.jpg

Define that Class and method in the code wherever necessary

/wp-content/uploads/2014/05/4_448402.jpg


The Method will create log with all the messages and generate log (Transaction SLG1)


/wp-content/uploads/2014/05/5_448406.jpg

Code is attached.

Assigned Tags

      9 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Christian Drumm
      Christian Drumm

      Hi Debopriya,

      creating an OO wrapper for the functions modules of the application log is a good idea. I guess it's one of the classes most development organizations have build themselfs in one way or the other.

      However, the version of an OO wrapper for the application log you presented isn't suitable for reuse. Furthermore, it is not even an OO implemention, but rather a PERFORM disguised as a method. You could, for example, simply make this method static as no attributes of the class are used. If you really want to implemente a reusable OO API for the application log you should consider the following:

      • Create a class with the attributes object and sub-object and log handle
      • provide a constructor the instantiates the class using object and sub-object as a parameter and sets the log handle
      • provide methods for logging exceptions, logging messages, logging messages in a message table, logging messages in the BAPIRET2 structures, logging additional data....
      • create a separate class to collect methods related to displaying the application log

      Using such a class as a basis, you could implement the method you presented here using just a few message calls. Furthermore you'd really have a reusable API for the application logs.

      In summary, it is a pity, that SAP doesn't provide a clean OO API for the application log out of the box and forces customers to develop such an API themself.

      Best,

      Christian

      Author's profile photo Debopriya Ghosh
      Debopriya Ghosh
      Blog Post Author

      Hi Christian,

      Thanks a lot for the suggestion.

      Will come up with the new version as you said.

      BR

      Debopriya Ghosh

      Author's profile photo Former Member
      Former Member

      Why do you want to re-invent the wheel?

      IF_RECA_MESSAGE_LIST is the most robust message handling API i have used until now. I know that it is not in the SAP_BASIS component & but you can build your custom framework based on it.

      - Suhas

      Author's profile photo Debopriya Ghosh
      Debopriya Ghosh
      Blog Post Author

      Hi Suhas,

      Thanks a lot for the suggestions.

      BR

      Debopriya Ghosh

      Author's profile photo deepak hada
      deepak hada

      IF_RECA_MESSAGE_LIST is not available in the system by default.

       

      Author's profile photo Peter C. Sandgaard
      Peter C. Sandgaard

      Hi,

      What type is your field symbo <lfs_msg> ?

      Author's profile photo Jelena Perfiljeva
      Jelena Perfiljeva

      This blog is a bit old but it comes up on top of Google search, so if you're reading this in 2019 or later please take a look at ABAP Logger on Github that works very well.

      Author's profile photo Krishna Kishor Kammaje
      Krishna Kishor Kammaje

      SAP Already provides a global class for it. (Assuming you are on ECC). If you still do not have it (if you are on CRM/SRM/GW etc) search for a class with *APP*LOG*. Different teams of SAP would have already created enough OO implementations for this purpose. Here is what I did.

      " Step 1. Create a Log Object and Sub Object using TCode SLG0
      
      " Step 2. Create an instance of a log class
        DATA mo_application_log TYPE REF TO cl_app_log_handler .
        mo_application_log = NEW cl_app_log_handler(
          i_obj = 'ZEMT'   "Log Object
          i_subobj = 'ZUI' "Sub Object
           ).
      
      " Step 3. Write Log
        DATA: lv_message1 TYPE char255.
        MESSAGE e038(zemt_supp_message) INTO lv_message1.
        mo_application_log->write_text(
          EXPORTING
            i_text =  lv_message1
            i_msgty = 'W' ).  "E or I
             
      " Step 4. Save Log
        mo_application_log->save( ).

       

      Author's profile photo Ashish Kumar Yadav
      Ashish Kumar Yadav

      Hi Krishna,

       

      I tried the above code it's not creating a log.