Monday 16 June 2014

SAP Application Log : Creation of application Log Object & Sub object and its Uses.



Step1. Create the below table which stores the Employee records.
















Step2. Create the below message class in Trax- SE91 with below messages.
















Step3. Go to Trax: SM30 and provide the Application Log Name : APPL_LOG & click on the highlighted button.




















Step4. Click on continue button.














Step5. This is a view cluster. Now click on the Maintain button.















Step6. Click on the New Entries Button. Provide the Object name & text. Select the Object and double click on the Sub Objects button from the left side panel.









Step7. Provide the three sub object names and their relevant texts & save it.
Each sub object is used for different purposes.













Step8. Go to Trax- SE11 . Open the table BALOBJ. The above created Object is stored in this table.












Step9. Go to Trax- SE11 . Open the table BALSUB. The above created Sub Object is stored in this table.











Step10. Create a Report which allows to create a employee or update a employee or delete a employee record.
To create & display the application  log mostly 4 function modules are used.
1. FM-'BAL_LOG_CREATE'- Pass the Object and subobject name for which message log is to be created.
2.FM-'BAL_LOG_MSG_ADD'- Pass the message that needs to be shown .It just adds the message to the memory not to the data base table.
3.FM-'BAL_DB_SAVE'- Saves the messge to the database table BALHDR.
4.FM-'BAL_DSP_LOG_DISPLAY'- Used to display the stored application log from the table on the UI.


________________________________________________________________________________
*&---------------------------------------------------------------------*
*& Report  ZTEST_APPL_LOG
*&---------------------------------------------------------------------*

REPORT  ztest_appl_log.

DATA : ls_ins TYPE  zemp_his,
              ls_upd TYPE  zemp_his,
              ls_del TYPE  zemp_his.

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 : r1 RADIOBUTTON GROUP g1  USER-COMMAND cmd1 DEFAULT 'X' ,
             r2 RADIOBUTTON GROUP g1 ,
             r3 RADIOBUTTON GROUP g1.
SELECTION-SCREEN : END OF BLOCK b1.

SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
*** new record creation **********
PARAMETERS : p_id_i TYPE zemp_his-emp_id MODIF ID m1,
             p_name_i TYPE zemp_his-name MODIF ID m1,
             p_desg_i TYPE zemp_his-design MODIF ID m1,
             p_doj_i TYPE zemp_his-doj MODIF ID m1,
             p_dept_i TYPE zemp_his-dept MODIF ID m1,
             p_sal_i TYPE zemp_his-salary MODIF ID m1.

*** Updation of existing record **********
PARAMETERS : p_id_u TYPE zemp_his-emp_id MODIF ID m2,
             p_desg_u TYPE zemp_his-design MODIF ID m2,
             p_dop_u TYPE zemp_his-dop MODIF ID m2,
             p_dor_u TYPE zemp_his-dor MODIF ID m2,
             p_dept_u TYPE zemp_his-dept MODIF ID m2,
             p_sal_u TYPE zemp_his-salary MODIF ID m2.

*** deletin of record **********
PARAMETERS : p_id_d TYPE zemp_his-emp_id MODIF ID m3.

SELECTION-SCREEN : END OF BLOCK b2.

AT SELECTION-SCREEN OUTPUT.

  LOOP AT SCREEN .
    IF r1 = 'X'.
      IF screen-group1 = 'M2'  OR screen-group1 = 'M3'.
        screen-active = 0.
        screen-input = 0.
        screen-output = 0.
        screen-invisible = 1.
      ENDIF.
    ELSEIF r2 = 'X'.
      IF screen-group1 = 'M1'  OR screen-group1 = 'M3'.
        screen-active = 0.
        screen-output = 0.
        screen-input = 0.
        screen-invisible = 1.
      ENDIF.
    ELSEIF r3 = 'X'.
      IF screen-group1 = 'M1'  OR screen-group1 = 'M2'.
        screen-active = 0.
        screen-input = 0.
        screen-output = 0.
        screen-invisible = 1.
      ENDIF.
    ENDIF.
    MODIFY SCREEN.
  ENDLOOP.


START-OF-SELECTION.

  IF r1 = 'X'.

    ls_log-object = 'ZOBJ_EMP'.
    ls_log-subobject = 'ZSOBJ_INSERT'.

    CALL FUNCTION 'BAL_LOG_CREATE'
      EXPORTING
        i_s_log      = ls_log
      IMPORTING
        e_log_handle = ls_hnd.

    ls_ins-emp_id  = p_id_i.
    ls_ins-name  = p_name_i.
    ls_ins-design  = p_desg_i.
    ls_ins-doj  = p_doj_i.
    ls_ins-dept  = p_dept_i.
    ls_ins-salary  = p_sal_i .
    INSERT into zemp_his values ls_ins.

    IF sy-subrc = 0.
      ls_msg-msgty = 'S'.
      ls_msg-msgid = 'ZLOG_MSG'.
      ls_msg-msgno = '001'.
      ls_msg-msgv1 = ls_ins-emp_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 = 'ZLOG_MSG'.
      ls_msg-msgno = '002'.
      ls_msg-msgv1 = ls_ins-emp_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 ls_ins.

  ELSEIF r2 = 'X'.

    ls_log-object = 'ZOBJ_EMP'.
    ls_log-subobject = 'ZSOBJ_UPDATE'.

    CALL FUNCTION 'BAL_LOG_CREATE'
      EXPORTING
        i_s_log      = ls_log
      IMPORTING
        e_log_handle = ls_hnd.

    ls_upd-emp_id  = p_id_u.
    ls_upd-design  = p_desg_u.
    ls_upd-dop  = p_dop_u.
    ls_upd-dor  = p_dor_u.
    ls_upd-dept  = p_dept_u.
    ls_ins-salary  = p_sal_u .
    UPDATE zemp_his FROM ls_upd.

    IF sy-subrc = 0.
      ls_msg-msgty = 'S'.
      ls_msg-msgid = 'ZLOG_MSG'.
      ls_msg-msgno = '003'.
      ls_msg-msgv1 = ls_upd-emp_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 = 'ZLOG_MSG'.
      ls_msg-msgno = '004'.
      ls_msg-msgv1 = ls_upd-emp_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 ls_upd.

  ELSEIF r3 = 'X'.

    ls_log-object = 'ZOBJ_EMP'.
    ls_log-subobject = 'ZSOBJ_DELETE'.

    CALL FUNCTION 'BAL_LOG_CREATE'
      EXPORTING
        i_s_log      = ls_log
      IMPORTING
        e_log_handle = ls_hnd.

    ls_del-emp_id  = p_id_d.
    DELETE zemp_his  FROM ls_del.

    IF sy-subrc = 0.

      ls_msg-msgty = 'S'.
      ls_msg-msgid = 'ZLOG_MSG'.
      ls_msg-msgno = '005'.
      ls_msg-msgv1 = ls_del-emp_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 = 'ZLOG_MSG'.
      ls_msg-msgno = '006'.
      ls_msg-msgv1 = ls_del-emp_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 ls_del.

  ENDIF.

_________________________________________________________________________________

Step11. Execute the report. Select the First radio button which allows You to create a New Employee Record. Provide the Employee details and Click on Execute Button.















Step12. The below message log is created and displayed on the screen.










Step13. Go to Trax- SE11 . Open the table BALHDR. The above created MSG LOG  is stored in this table.






_________________________________XXX__________________________________________


1 comment:

Unknown said...

Thank you sir...

Comments system

Disqus Shortname