Manage SAP SLG1 – Application Log in ABAP with samples

Sap Application Log with transactions SAP SLG0 and SAP SLG1. The First part covers the main SAP Application Log using the standard SAP Application Log SLG0 and SLG1.
The Second part details how you can create, manage SAP Log using ABAP with the different options.

What’s SAP Application Logging ?

Application logging records the progress of the execution of an application so that you can reconstruct it later if necessary. Whereas the system log records system events, you can use the application log to record application-specific events. Use the transaction SLG0 to define entries for your own applications in the application log. Use the transaction SLG1 to analyze the application log.
The application log is a table structure consisting of several tables. Applications write their entries to these tables using SAP function modules. (These modules conform to the SAP authorization concept.)

You can also find out who accessed these function modules over a where-used list by using the report RSFKT100 (function group: SLG0)

source: Application Logging

SAP SLG1 : Display SAP Application Log

Let’s start by Display SAP Application Log. The main transaction to display SAP log is SLG1.

Display Log using SLG1

Within the bar menu, launch the SAP Tcode for Log SLG1.
You can select Analyse Application Log by Object, Subobjest, External ID, Time , User, Transaction Codes, Program …

Here a screenshot of SLG1 Filter screen :

SAP LOG Display Log

Pop Up Show SAP Log Application

Within any other ABAP program, you can use Pop Up in order to display SAP Log Application.

Check this post for more detail ABAP PopUp: Types and Samples codes > ABAP PopUps Programs Sample

Create SAP Application Log (SLG0)

SLG0 : Create Log Object and SubObject

Create/Maintain SAP Application Log Objects and subobjects using tcode SLG0. You should define an Object and SubObjets.
Theses Structures will help you identify easily your generated Application Log in SLG1 from the standard generated Log by others programs.

SAP LOG Object SLG0

Add log in SAP SLG1 within ABAP Program

In this part, we will detail how to add log to SAP application Log using ABAP Code and so our log will be displayed in SLG1.

The Steps to create SLG1 log are:

  • Initialize Log (using BAL_LOG_CREATE)
  • Fill Log with free text or  Message BAPIRET
  • Save and close SAP SLG1 Application Log

Let’s detail each step with a full ABAP Snipper

Initialize log : Use of BAL_LOG_CREATE

In order to initialize Log, you should use the standard function BAL_LOG_CREATE.

Pass the Object and the SubOject, the date, the user and potentially an external Number ( can be Order Id, or Partner Id … ). The Output of BAL_LOG_CREATE will be a reference number to Log Handle.

Add Free text to SAP SLG1 Log

Once the Application Log is initialized, the next step is to fill information within the log.
Let’s start by the easy way on how to add free text to SAP SLG1 Log.

Simply use the standard function BAL_LOG_MSG_ADD with the log handle and your free text fited into BAPIRET2 structure.
You don’t need to create an new message class or number, just use the standard message class and number for Application Log (BL 001).

Add Message Table BAPIRET2 to  the SAP SLG1 log

Sometimes, you need to log all BAPI Message to Application Log. In this case, loop to your BAPIRETTAB message and for each line in the BAPI return table, add a new line to Application Log using the BAL_LOG_MSG_ADD.

Save and close SAP SLG1 Application Log

Once all the information is added to SLG1 Log, you have to SAVE the Application Log using BAL_DB_SAVE. It will commit modification to database.
Now you can check the SLG1 transaction Code for Log and you will find your new log.

Sab125

Hi. I have been working as SAP Technical and functional for a decade. Through this blog, I am trying to share with you my experience. Hopefull, it makes your ways easier path ...Sab