SAP ALL Create and View LOG Using SLG0 and SLG1 Transaction - SAP Blogs
SAP ALL Create and View LOG Using SLG0 and SLG1 Transaction - SAP Blogs
Community
Former Member
April 18, 2012 5 minute read
When we need to display all messages together then this set of messages is a log. Logs usually also contain general header information (log type, creator, creation time, etc.).
Several logs can be created in a transaction. The Application Log provides a comprehensive infrastructure for collecting messages, saving them in the database and displaying
them as logs. It has also traffic icons for the messages based on the message type.
Important Transactions
The important transactions codes used for application log are as following:
For generating a custom application log we need to create a new log object and sub object. For this we use transaction SLG0.
Go to transaction SLG0 and click on new entries. Then give the name of object and save. For any of the object we can create the sub object as well. Sub objects are simply
further classifications of the application log.
Open Log
The FM BAL_LOG_CREATE is used to open application log. This FM returns log handle. This log handle is a unique identifier for a particular log. We use this log handle
later for accessing the log like for example adding messages to the log etc.
Using the log handle we can add as many messages we want to the LOG through the FM BAL_LOG_MSG_ADD to the importing parameter I_S_MSG (structure
BAL_S_MSG). This data is very much similar to the T100 data that is message type, message number and the four message variables.
Save messages
Logs there in the memory can be saved to database using the FM BAL_DB_SAVE by passing the importing parameter I_SAVE_ALL = ‘X’.The function module
BAL_DB_SAVE returns a table (Exporting parameter E_NEW_LOGNUMBERS), which relates LOG_HANDLE, external number EXTNUMBER, temporary
https://blogs.sap.com/2012/04/18/create-and-view-log-using-slg0-and-slg1-transaction/ 1/6
8/13/2020 Create and view LOG using SLG0 and SLG1 transaction | SAP Blogs
LOGNUMBER and permanent LOGNUMBER, so you can find out which number was assigned to a log after saving.
Display messages
***Open Log
EXPORTING
i_s_log = ls_log
IMPORTING
e_log_handle = ls_log_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
IF sy-subrc EQ 0.
***Create message
ls_msg-msgv2 = lv_message2.
ls_msg-msgv3 = lv_message3.
ls_msg-msgv4 = lv_message4.
ls_msg-probclass = 2.
EXPORTING
i_log_handle = ls_log_handle
i_s_msg = ls_msg
* IMPORTING
* E_S_MSG_HANDLE =
* E_MSG_WAS_LOGGED =
* E_MSG_WAS_DISPLAYED =
EXCEPTIONS
log_not_found =1
msg_inconsistent =2
https://blogs.sap.com/2012/04/18/create-and-view-log-using-slg0-and-slg1-transaction/ 2/6
8/13/2020 Create and view LOG using SLG0 and SLG1 transaction | SAP Blogs
log_is_full =3
OTHERS = 4.
IF sy-subrc NE 0.
“Do nothing
ENDIF.
***Save message
EXPORTING
i_client = sy-mandt
* I_IN_UPDATE_TASK =‘‘
i_save_all = lc_set
i_t_log_handle = li_log_handle
* IMPORTING
* E_NEW_LOGNUMBERS =
EXCEPTIONS
log_not_found =1
save_not_allowed =2
numbering_error =3
OTHERS = 4.
IF sy-subrc EQ 0.
REFRESH: li_log_handle.
ENDIF.
When we want to save the List/Log for the long time: Generally, we have the spool retention period of 8 days. So, the list or log will be deleted automatically.
When we want more information compared to Log generated with WRITE: Application Log has more information like User, date of creation, Severity of the message.
In ALE / EDI Processing: When we do the cross client processing (IDoc Processing), we can generate the Application log to keep track of the generated errors or the
messages.
Summary of the steps to Create and View logs:
1) Create object and sub object in SLG0 transaction.
2) The program where you want to create the LOG call the FMs:
BAL_LOG_CREATE
BAL_LOG_MSG_ADD
BAL_DB_SAVE
3) For viewing the logs go to SLG1 transaction and give the object name, sub object name (if any) and other related information like the Username and date etc.
Then click on Execute. You will be able to see the logs. Double click on any one of them to see the detailed error message.
4) One can even view the logs through the program itself by using the FM BAL_DSP_LOG_DISPLAY.
Alert Moderator
https://blogs.sap.com/2012/04/18/create-and-view-log-using-slg0-and-slg1-transaction/ 3/6
8/13/2020 Create and view LOG using SLG0 and SLG1 transaction | SAP Blogs
Assigned tags
Related Questions
slg1/slg0-Log Display
By Former Member , Nov 24, 2008
BAL_LOG_CREATE
By Former Member , Oct 07, 2008
Application log
By Former Member , Mar 01, 2007
11 Comments
Former Member
Like(0)
Former Member
Good One 🙂
Like(0)
Former Member
one question how many days by default we have our logs in SLG1?
Like(0)
Hi Akankshi,
https://blogs.sap.com/2012/04/18/create-and-view-log-using-slg0-and-slg1-transaction/ 4/6
8/13/2020 Create and view LOG using SLG0 and SLG1 transaction | SAP Blogs
Nice posting, it’s helped me a lot.
This article cuts to the chase and you even posted a cool summary to speed up learning.
Do you know if is there some ABAP class that could provide/encapsulate the same functionality?
Best regards,
Like(0)
Sanjay Shah
CL_BAL_LOGGER
Like(0)
Former Member
Thank akankshi,
Regards,
Punleu
Like(0)
Former Member
Like(0)
Former Member
Hi Akankshi,
Currently in SLG1 we can see failures and warning messages which are in red/yellow light, may I know how we can display success logs which are in green light in SLG1?
Regards
NTG
Like(0)
Former Member
Like(0)
https://blogs.sap.com/2012/04/18/create-and-view-log-using-slg0-and-slg1-transaction/ 5/6
8/13/2020 Create and view LOG using SLG0 and SLG1 transaction | SAP Blogs
Former Member
Very Good.
Thanks
Like(0)
Bhakti joshi
i like the way you have laid out here. This format of detailed step wise explanation preceded and followed by summary makes it easy to grasp and helps
simplify. thanks for the e ort, totally worth it.
Like(0)
Find us on
Newsletter Support
https://blogs.sap.com/2012/04/18/create-and-view-log-using-slg0-and-slg1-transaction/ 6/6