Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

APPL_LOG_WRITE_DB how to use

Former Member
0 Kudos

hi guys,

I need to use FM APPL_LOG_WRITE_DB to update to customised table ztable, can anybody help on how to code

5 REPLIES 5

GauthamV
Active Contributor
0 Kudos

Try like this.


DATA: PROT_OBJ LIKE BALHDR-OBJECT VALUE 'HRPU'.
DATA: BEGIN OF PROT_NR OCCURS 1.        "interface for appl_log_write_db
         INCLUDE STRUCTURE BALNRI.
DATA: END OF PROT_NR.

  CALL FUNCTION 'APPL_LOG_WRITE_DB'
       EXPORTING
            OBJECT                = PROT_OBJ
       TABLES
            OBJECT_WITH_LOGNUMBER = PROT_NR
       EXCEPTIONS
            OBJECT_NOT_FOUND      = 1
            SUBOBJECT_NOT_FOUND   = 2
            INTERNAL_ERROR        = 3
            OTHERS                = 4.
  IF SY-SUBRC NE 0.
    MESSAGE W579(54).
  ENDIF.

former_member206377
Active Contributor
0 Kudos

Hi Ester,

Came across this code snippet but since I am not able to provide the link , I am pasting the code here :


DATA: lf_obj        TYPE balobj_d,
      lf_subobj     TYPE balsubobj,
      ls_header     TYPE balhdri,
      lf_log_handle TYPE balloghndl,
      lf_log_number TYPE balognr,
      lt_msg        TYPE balmi_tab,
      ls_msg        TYPE balmi,
      lt_lognum     TYPE TABLE OF balnri,
      ls_lognum     TYPE balnri.
*
* Application Log object & Subobject
  lf_obj     = 'ZTEST_NP'.
  lf_subobj  = 'ZTEST_1'.
*
* Header information for the log
  ls_header-object     = lf_obj.
  ls_header-subobject  = lf_subobj.
  ls_header-aldate     = sy-datum.
  ls_header-altime     = sy-uzeit.
  ls_header-aluser     = sy-uname.
  ls_header-aldate_del = sy-datum + 1.
*
* Get the Log handle using the header
  CALL FUNCTION 'APPL_LOG_WRITE_HEADER'
    EXPORTING
      header              = ls_header
    IMPORTING
      e_log_handle        = lf_log_handle
    EXCEPTIONS
      object_not_found    = 1
      subobject_not_found = 2
      error               = 3
      OTHERS              = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
*
* Get the next avaliable Log number
  CALL FUNCTION 'BAL_DB_LOGNUMBER_GET'
    EXPORTING
      i_client                 = sy-mandt
      i_log_handle             = lf_log_handle
    IMPORTING
      e_lognumber              = lf_log_number
    EXCEPTIONS
      log_not_found            = 1
      lognumber_already_exists = 2
      numbering_error          = 3
      OTHERS                   = 4.
*
* Fill the Application Log messages.
*   Here we can append our own messages as per our application
*   behaviour
*
* Information message will generate the Green Light
  ls_msg-msgty = 'I'.
  ls_msg-msgid = '00'.
  ls_msg-msgno = '398'.
  ls_msg-msgv1 = 'Testing 1234'.
  APPEND ls_msg TO lt_msg.
*
* Warning message will generate the Yellow light
  ls_msg-msgty = 'W'.
  ls_msg-msgid = '00'.
  ls_msg-msgno = '398'.
  ls_msg-msgv1 = 'Warning Testing 1234'.
  APPEND ls_msg TO lt_msg.
*
* Error message will generate the Red Light
  ls_msg-msgty = 'E'.
  ls_msg-msgid = '00'.
  ls_msg-msgno = '398'.
  ls_msg-msgv1 = 'Error Testing 1234'.
  APPEND ls_msg TO lt_msg.
*

0 Kudos

* Write the Log mesages to the memory
  CALL FUNCTION 'APPL_LOG_WRITE_MESSAGES'
    EXPORTING
      object              = lf_obj
      subobject           = lf_subobj
      log_handle          = lf_log_handle
    TABLES
      messages            = lt_msg
    EXCEPTIONS
      object_not_found    = 1
      subobject_not_found = 2
      OTHERS              = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
*
* write the log message to Database which can be later analyzed
*   from transaction SLG1
  MOVE-CORRESPONDING ls_header TO ls_lognum.
  ls_lognum-lognumber = lf_log_number.
  APPEND ls_lognum TO lt_lognum.
*
  CALL FUNCTION 'APPL_LOG_WRITE_DB'
    EXPORTING
      object                = lf_obj
      subobject             = lf_subobj
      log_handle            = lf_log_handle
    TABLES
      object_with_lognumber = lt_lognum
    EXCEPTIONS
      object_not_found      = 1
      subobject_not_found   = 2
      internal_error        = 3
      OTHERS                = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
*
* display the generate log from the memory.
  CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'.

0 Kudos

HI Vasuki,

Thanks so much for the coding, the result still came saying no log was updated. pls advice.

Former Member
0 Kudos

ss