Write Application Log

The Application Log can be created using several function modules. Below is a code snippet with a collection of all the function modules to write application log entries. Simply pass the object and sub-object along with the log message, and by calling the code below, the application log will be written successfully.

Item and Sub-object is to be made utilizing T-code SLG0 and the application log composed can be view utilizing T-code SLG1.

FUNCTION z_o_write_application_log.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(OBJECT) LIKE BALHDR-OBJECT
*" VALUE(SUBOBJECT) LIKE BALHDR-SUBOBJECT
*" TABLES
*" MESSAGES STRUCTURE BALMI

* Local Internal Table Declaration
DATA: li_lognum TYPE TABLE OF balnri.

* Local Work-Area Declaration
DATA: lk_log_handle TYPE balloghndl, " Log handle
lk_log_number TYPE balognr, " Log Number
lk_header TYPE balhdri, " Log header
lk_lognum TYPE balnri. " Log number

* Populating header details
lk_header-object = object. " Object
lk_header-subobject = subobject. " SubObject
lk_header-aluser = sy-uname. " User
lk_header-aldate = sy-datum. " Date
lk_header-altime = sy-uzeit. " Time
lk_header-altcode = sy-tcode. " Tcode
lk_header-alprog = sy-repid. " Program

* Get the Log handle using the header
CALL FUNCTION 'APPL_LOG_WRITE_HEADER'
EXPORTING
header = lk_header
IMPORTING
e_log_handle = lk_log_handle
EXCEPTIONS
object_not_found = 1
subobject_not_found = 2
error = 3
OTHERS = 4.

* Sy-subrc check not required.

* Get the next avaliable Log number
CALL FUNCTION 'BAL_DB_LOGNUMBER_GET'
EXPORTING
i_client = sy-mandt
i_log_handle = lk_log_handle
IMPORTING
e_lognumber = lk_log_number
EXCEPTIONS
log_not_found = 1
lognumber_already_exists = 2
numbering_error = 3
OTHERS = 4.

* Sy-subrc check not required.

* Write the Log mesages to the memory
CALL FUNCTION 'APPL_LOG_WRITE_MESSAGES'
EXPORTING
object = object
subobject = subobject
log_handle = lk_log_handle
TABLES
messages = messages
EXCEPTIONS
object_not_found = 1
subobject_not_found = 2
OTHERS = 3.

* Sy-subrc check not required.

lk_lognum-object = object. " Object
lk_lognum-subobject = subobject. " SubObject
lk_lognum-lognumber = lk_log_number. " Log number
APPEND lk_lognum TO li_lognum.
CLEAR lk_lognum.

* Write the log message to Database which can be later analyzed
* from transaction SLG1
CALL FUNCTION 'APPL_LOG_WRITE_DB'
EXPORTING
object = object
subobject = subobject
log_handle = lk_log_handle
TABLES
object_with_lognumber = li_lognum
EXCEPTIONS
object_not_found = 1
subobject_not_found = 2
internal_error = 3
OTHERS = 4.

* Sy-subrc check not required.

ENDFUNCTION.

If it’s not too much trouble, note: There are additionally different FMs like ‘BAL_LOG_MSG_ADD’, ‘BAL_DB_SAVE’ and so on to compose application log. SAP upholds every one of the FMs referenced here.

The custom capability module bit composed above is only for simple reference for the designers.

If you have any desire to get such useful issues and goals directly to your inbox, if it’s not too much trouble, Buy in. We regard your security and view safeguarding it in a serious way.

If you found this post helpful, please consider hitting the share button on the left side of your screen. For more insights, don’t forget to check out our next article on how to write an application log in SAP.

Many thanks for your time!!

YOU MAY LIKE THIS

Transport ABAP Report Variants into a Work Bench Request

ALE and IDoc in SAP ABAP: A Deep Dive

Applying Enterprise Integration Patterns in SAP ABAP

Source link

  • Related Posts

    Why are developers so fond of ‘REUSE_ALV_GRID_DISPLAY’?

    Is it that hard to NOT utilize FM ‘REUSE_ALV_GRID_DISPLAY’ to show ALV? Or, on the other hand, is it human instinct to remain in our usual range of familiarity? ABAPers…

    Just a key and two clicks for ALV consistency check

    ALV consistency check. I actually recollect, that when one of my leaders surveyed my most memorable deliverable in the ALV report; it was over in 1 moment. He came and…

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    You Missed

    Why are developers so fond of ‘REUSE_ALV_GRID_DISPLAY’?

    • By Varad
    • March 23, 2025
    • 10 views
    Why are developers so fond of ‘REUSE_ALV_GRID_DISPLAY’?

    Just a key and two clicks for ALV consistency check

    • By Varad
    • March 22, 2025
    • 24 views
    Just a key and two clicks for ALV consistency check

    Know Who is doing What in your SAP System

    • By Varad
    • March 21, 2025
    • 25 views
    Know Who is doing What in your SAP System

    OOPs Report Using Splitter and ALV Tree Combination

    • By Varad
    • March 20, 2025
    • 28 views
    OOPs Report Using Splitter and ALV Tree Combination

    ALV with an Editable Row

    • By Varad
    • March 19, 2025
    • 37 views
    ALV with an Editable Row

    Extensive Tips and Tricks for Interactive SAP ALV

    • By Varad
    • March 18, 2025
    • 40 views
    Extensive Tips and Tricks for Interactive SAP ALV