SLG Log Demo

* Write SLG Log
  PERFORM write_slg_log    CHANGING lt_t_log_handle.

* Display SLG Log
  PERFORM display_slg_log  CHANGING lt_t_log_handle.


FORM  write_slg_log    CHANGING  pt_t_log_handle TYPE bal_t_logh.

  DATAls_s_log       TYPE bal_s_log,
        ls_msg         TYPE bal_s_msg,
        ls_context     TYPE ypm_upd_equnr,
        lv_log_handle  TYPE balloghndl,
        lt_new_lognumbers TYPE bal_t_lgnm.

  DATA  ls_imptt       TYPE ty_imptt_st.

  "Log Object - YLEGO and Sub object -PM
  ls_s_log-object      'YRAMESH'.
  ls_s_log-subobject   'PM'.
  ls_s_log-aluser      sy-uname.
  ls_s_log-alprog      'ZPLM_MY_1000'.
  ls_s_log-aldate_del  sy-datum .
  ls_s_log-del_before  abap_true.

  "  Create LOG header
  CALL FUNCTION 'BAL_LOG_CREATE'
    EXPORTING
      i_s_log                 ls_s_log
    IMPORTING
      e_log_handle            lv_log_handle
    EXCEPTIONS
      log_header_inconsistent 1
      OTHERS                  2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


  LOOP AT gt_imptt INTO ls_imptt.
    ls_context-point        ls_imptt-point.
    ls_context-mpobj        ls_imptt-mpobj.
    ls_context-erdat        ls_imptt-erdat.
    ls_context-equnr        ls_imptt-equnr.
    ls_msg-context-tabname  'YPM_UPD_EQUNR'.
    ls_msg-context-value    ls_context.
    ls_msg-msgty            ls_imptt-msgty.
    ls_msg-msgid            'YPLM_MOULDING_EQUIP'.
    ls_msg-msgno            '072'.
    ls_msg-msgv1            ls_imptt-message+0(50).
    ls_msg-msgv2            ls_imptt-message+50(50).
    ls_msg-msgv3            ls_imptt-message+100(50).
    ls_msg-msgv4            ls_imptt-message+150(50).

*    " Add logs
    CALL FUNCTION 'BAL_LOG_MSG_ADD'
      EXPORTING
        i_log_handle     lv_log_handle
        i_s_msg          ls_msg
      EXCEPTIONS
        log_not_found    1
        msg_inconsistent 2
        log_is_full      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.

    INSERT lv_log_handle INTO TABLE pt_t_log_handle.

    IF p_save EQ 'X'.
    "Save Log to Database
      CALL FUNCTION 'BAL_DB_SAVE'
        EXPORTING
          i_t_log_handle   pt_t_log_handle
        IMPORTING
          e_new_lognumbers lt_new_lognumbers
        EXCEPTIONS
          log_not_found    1
          save_not_allowed 2
          numbering_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.

    ENDIF.

  ENDLOOP.

ENDFORM.



FORM  display_slg_log     CHANGING p_lt_t_log_handle TYPE bal_t_logh.

  DATA ls_display_profile TYPE  bal_s_prof.
  DATA ls_fcat            TYPE  bal_s_fcat.

  " Get standard display profile
  CALL FUNCTION 'BAL_DSP_PROFILE_SINGLE_LOG_GET'
    IMPORTING
      e_s_display_profile ls_display_profile.

  " Add Measurement Point
  ls_fcat-ref_table 'YPM_UPD_EQUNR'.

  ls_fcat-ref_field 'POINT'.
  ls_fcat-col_pos   100.
  APPEND ls_fcat TO ls_display_profile-mess_fcat.

  " Add Object no.
  ls_fcat-ref_field 'MPOBJ'.
  ls_fcat-col_pos   110.
  APPEND ls_fcat TO ls_display_profile-mess_fcat.

  " Add Acquisition date/Creation date
  ls_fcat-ref_field 'ERDAT'.
  ls_fcat-col_pos   130.
  APPEND ls_fcat TO ls_display_profile-mess_fcat.

  " Add Equipment
  ls_fcat-ref_field 'EQUNR'.
  ls_fcat-col_pos   140.
  APPEND ls_fcat TO ls_display_profile-mess_fcat.

  " Display Slg log
  CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
    EXPORTING
      i_t_log_handle       p_lt_t_log_handle
      i_s_display_profile  ls_display_profile
    EXCEPTIONS
      profile_inconsistent 1
      internal_error       2
      no_data_available    3
      no_authority         4
      OTHERS               5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.                " WRITE_SLG_LOG

Comments

Popular posts from this blog

Export data to xls using OOPS

Factory method ALV sap abap

Delete Selected Record in ALV Report