Creation of application Log Object & Sub object and its Uses.
Steps to Create Application Log
Step1. Create the below table which stores the student records.
Step2. Create the message class in Tcode- SE91 with below messages.
Step 3. Create an Object and Sub object in Tcode-SLG0.
* Goto SLG0.
* Click on new entries.
* Give object name and description.
* Select object and double click on sub object.
* And give sub object name and description.
Step 4. Check the tables for object is BALOBJ and sub object is BALSUB.
* Goto SE11. And give table name BALOBJ. And click on display.
* Goto contents. Execute the table with object name(ZOBJ_STUDENT).
* Goto SE11. And give table name BALSUB. And click on display.
* Goto contents. Execute the table with object name (ZOBJ_STUDENT).
Step 5. Create a Report which allows to create a student or update a student or delete a student record.
* To create & display the application log mostly 4 function modules are used.Report Program
REPORT zab_appl_log.DATA: lv_insert TYPE zstu,
lv_update TYPE zstu,
lv_delete TYPE zstu.
DATA: ls_log TYPE bal_s_log,
ls_hnd TYPE balloghndl,
ls_msg TYPE bal_s_msg,
lt_hnd TYPE bal_t_logh,
lt_new TYPE bal_t_lgnm.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS: p_r1 RADIOBUTTON GROUP g1 USER-COMMAND usd DEFAULT 'X',
p_r2 RADIOBUTTON GROUP g1,
p_r3 RADIOBUTTON GROUP g1.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
******Parameters for inserting records**********************
PARAMETERS: i_id TYPE zstu-zstu_id MODIF ID m1,
i_name TYPE zstu-zstu_name MODIF ID m1,
i_dep TYPE zstu-zstu_dep MODIF ID m1,
i_fee TYPE zstu-zstu_fee MODIF ID m1.
****** end inserting records********************************
*****Parameters for updating records************************
PARAMETERS: u_id TYPE zstu-zstu_id MODIF ID m2,
u_name TYPE zstu-zstu_name MODIF ID m2,
u_dep TYPE zstu-zstu_dep MODIF ID m2,
u_fee TYPE zstu-zstu_fee MODIF ID m2.
***** end updating records***********************************
******Parameters for deleting records************************
****** end deleting records************************
SELECTION-SCREEN END OF BLOCK b2.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF p_r1 = 'X' AND screen-group1 = 'M1'.
screen-active = 1.
MODIFY SCREEN.
ELSEIF p_r1 = ' ' AND screen-group1 = 'M1'.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
IF p_r2 = 'X' AND screen-group1 = 'M2'.
screen-active = 1.
MODIFY SCREEN.
ELSEIF p_r2 = ' ' AND screen-group1 = 'M2'.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
IF p_r3 = 'X' AND screen-group1 = 'M3'.
screen-active = 1.
MODIFY SCREEN.
ELSEIF p_r3 = ' ' AND screen-group1 = 'M3'.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
START-OF-SELECTION.
*****************Start of create appl log******************
IF p_r1 = 'X'.
ls_log-object = 'ZOBJ_STUDENT'.
ls_log-subobject = 'ZSOBJ_INSERT'.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = ls_log
IMPORTING
e_log_handle = ls_hnd.
lv_insert-zstu_id = i_id.
lv_insert-zstu_name = i_name.
lv_insert-zstu_dep = i_dep.
lv_insert-zstu_fee = i_fee.
INSERT INTO zstu VALUES lv_insert.
IF sy-subrc = 0.
ls_msg-msgty = 'S'.
ls_msg-msgid = 'ZAJ_MSG'.
ls_msg-msgno = '001'.
ls_msg-msgv1 = lv_insert-zstu_id.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = ls_hnd
i_s_msg = ls_msg.
ELSE.
ls_msg-msgty = 'E'.
ls_msg-msgid = 'ZAJ_MSG'.
ls_msg-msgno = '002'.
ls_msg-msgv1 = lv_insert-zstu_id.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = ls_hnd
i_s_msg = ls_msg.
ENDIF.
APPEND ls_hnd TO lt_hnd.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
* I_CLIENT = SY-MANDT
* I_IN_UPDATE_TASK = ' '
* I_SAVE_ALL = ' '
i_t_log_handle = lt_hnd
IMPORTING
e_new_lognumbers = lt_new.
IF sy-subrc = 0.
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
i_t_log_handle = lt_hnd.
ENDIF.
CLEAR lv_insert.
ENDIF.
****************End of create APLL Log*******************
***************Start of Update APPL LOG******************
IF p_r2 = 'X'.
ls_log-object = 'ZOBJ_STUDENT'.
ls_log-subobject = 'ZSOBJ_UPDATE'.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = ls_log
IMPORTING
e_log_handle = ls_hnd.
lv_update-zstu_id = u_id.
lv_update-zstu_name = u_name.
lv_update-zstu_dep = u_dep.
lv_update-zstu_fee = u_fee.
UPDATE zstu FROM lv_update.
IF sy-subrc = 0.
ls_msg-msgty = 'S'.
ls_msg-msgid = 'ZAJ_MSG'.
ls_msg-msgno = '003'.
ls_msg-msgv1 = lv_update-zstu_id.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = ls_hnd
i_s_msg = ls_msg.
ELSE.
ls_msg-msgty = 'E'.
ls_msg-msgid = 'ZAJ_MSG'.
ls_msg-msgno = '004'.
ls_msg-msgv1 = lv_update-zstu_id.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = ls_hnd
i_s_msg = ls_msg.
ENDIF.
APPEND ls_hnd TO lt_hnd.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
* I_CLIENT = SY-MANDT
* I_IN_UPDATE_TASK = ' '
* I_SAVE_ALL = ' '
i_t_log_handle = lt_hnd
IMPORTING
e_new_lognumbers = lt_new.
IF sy-subrc = 0.
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
i_t_log_handle = lt_hnd.
ENDIF.
CLEAR lv_insert.
ENDIF.
******************end of update APPL LOG*****************
*******************Start of delete APPL LOG**************
IF p_r3 = 'X'.
ls_log-object = 'ZOBJ_STUDENT'.
ls_log-subobject = 'ZSOBJ_DELETE'.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = ls_log
IMPORTING
e_log_handle = ls_hnd.
lv_delete-zstu_id = d_id.
DELETE zstu FROM lv_delete.
IF sy-subrc = 0.
ls_msg-msgty = 'S'.
ls_msg-msgid = 'ZAJ_MSG'.
ls_msg-msgno = '005'.
ls_msg-msgv1 = lv_delete-zstu_id.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = ls_hnd
i_s_msg = ls_msg.
ELSE.
ls_msg-msgty = 'E'.
ls_msg-msgid = 'ZAJ_MSG'.
ls_msg-msgno = '006'.
ls_msg-msgv1 = lv_delete-zstu_id.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = ls_hnd
i_s_msg = ls_msg.
ENDIF.
APPEND ls_hnd TO lt_hnd.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
* I_CLIENT = SY-MANDT
* I_IN_UPDATE_TASK = ' '
* I_SAVE_ALL = ' '
i_t_log_handle = lt_hnd
IMPORTING
e_new_lognumbers = lt_new.
IF sy-subrc = 0.
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
i_t_log_handle = lt_hnd.
ENDIF.
CLEAR lv_insert.
ENDIF.
**************End of delete APPL LOG************************
* Student id 15 is not there so it can raise error.
Comments
Post a Comment