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

    Travel Manager in SAP

    Make sense of ‘Travel Supervisor’ in SAP. ‘Travel Supervisor,’ in SAP, assists representatives with having an outline of endlessly travel related things/objects, (for example, travel demands, itinerary items, and travel…

    FD11 Is For Analysis Of Customers

    In exchange FD11 which are the source tables for getting open things net qualities. As to Things Net worth is shown up from table BSID. Unpaid debts determined in view…

    Leave a Reply

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

    You Missed

    Write Application Log

    • By Varad
    • January 5, 2025
    • 20 views
    Write Application Log

    Travel Manager in SAP

    • By Varad
    • January 4, 2025
    • 31 views
    Travel Manager in SAP

    FD11 Is For Analysis Of Customers

    • By Varad
    • January 3, 2025
    • 44 views
    FD11 Is For Analysis Of Customers

    Default Values for FI posting FB50

    • By Varad
    • January 2, 2025
    • 37 views
    Default Values for FI posting FB50

    Comparison FAGLL03 FBL3N FBL5N

    • By Varad
    • January 1, 2025
    • 46 views
    Comparison FAGLL03 FBL3N FBL5N

    Steps For Using Trx F103 and F104

    • By Varad
    • December 31, 2024
    • 42 views
    Steps For Using Trx F103 and F104