in src/zrest/zcl_rest_utility_class.clas.abap [0:0]
METHOD write_application_log.
*********************************************************************
* Variable Declaration *
*********************************************************************
DATA: lw_log TYPE bal_s_log,
lw_msg TYPE bal_s_msg,
lv_log_handle TYPE balloghndl,
lw_message TYPE zrest_applog_message.
*********************************************************************
* Constants Declaration *
*********************************************************************
CONSTANTS: lc_bl TYPE char2 VALUE 'BL',
lc_no TYPE char4 VALUE '0001',
lc_e TYPE char1 VALUE 'E',
lc_s TYPE char1 VALUE 'S'.
*// Populate the Data for the Hierarchial update
lw_log-extnumber = iv_extnumber.
lw_log-object = iv_object.
lw_log-subobject = iv_subobject.
lw_log-aldate = sy-datum.
lw_log-altime = sy-uzeit.
lw_log-aluser = sy-uname.
lw_log-altcode = sy-tcode.
lw_log-alprog = sy-repid.
*// Calling Function Module to Create the Application Log
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = lw_log
IMPORTING
e_log_handle = lv_log_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
IF sy-subrc EQ 0.
LOOP AT it_message INTO lw_message.
IF lw_message-zmsgid IS NOT INITIAL.
lw_msg-msgid = lw_message-zmsgid.
ELSE.
lw_msg-msgid = lc_bl. "'BL'.
ENDIF.
IF lw_message-zmsgno IS NOT INITIAL.
lw_msg-msgno = lw_message-zmsgno.
ELSE.
lw_msg-msgno = lc_no. "'0001'.
ENDIF.
lw_msg-msgty = lw_message-zmsgty.
lw_msg-msgv1 = lw_message-zmsgv1.
lw_msg-msgv2 = lw_message-zmsgv2.
lw_msg-msgv3 = lw_message-zmsgv3.
lw_msg-msgv4 = lw_message-zmsgv4.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = lv_log_handle
i_s_msg = lw_msg
EXCEPTIONS
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
OTHERS = 4.
CLEAR: lw_msg-msgv1,
lw_msg-msgv2,
lw_msg-msgv3,
lw_msg-msgv4.
ENDLOOP.
*// FM to save the Application Log Messages
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_save_all = 'X'
EXCEPTIONS
log_not_found = 1
save_not_allowed = 2
numbering_error = 3
OTHERS = 4.
IF sy-subrc EQ 0.
*// 'Messages posted to Application Log Successfully'
MESSAGE TEXT-002 TYPE lc_s. "'S'.
ENDIF.
ELSE.
*// 'Application Log Creation Failed'
MESSAGE TEXT-001 TYPE lc_e DISPLAY LIKE lc_s.
ENDIF.