BALLOG Helper
Este é um helper que fiz para gravar logs na transação SLG1.
CLASS zcl_ptool_helper DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
TYPES:
BEGIN OF ty_s_result,
kostl TYPE kostl,
prctr TYPE prctr,
END OF ty_s_result .
TYPES:
ty_t_result TYPE HASHED TABLE OF ty_s_result
WITH UNIQUE KEY kostl prctr .
TYPES:
ty_r_kostl TYPE RANGE OF kostl .
CLASS-METHODS bal_db_delete
IMPORTING
!it_log_header TYPE balhdr_t .
CLASS-METHODS bal_db_save .
CLASS-METHODS bal_db_search
IMPORTING
!iv_subobject TYPE balsubobj OPTIONAL
!iv_object TYPE balobj_d
RETURNING
VALUE(rt_log_header) TYPE balhdr_t .
CLASS-METHODS bal_log_create
IMPORTING
!iv_extnumber TYPE balnrext OPTIONAL
!iv_subobject TYPE balsubobj OPTIONAL
!iv_object TYPE balobj_d
RETURNING
VALUE(r_handle) TYPE balloghndl .
CLASS-METHODS bal_log_hdr_read
IMPORTING
!iv_handle TYPE balloghndl
RETURNING
VALUE(rs_statistics) TYPE bal_s_scnt .
CLASS-METHODS bal_log_msg_add
IMPORTING
!iv_handle TYPE balloghndl
!iv_tabname TYPE baltabname OPTIONAL
!iv_sort_field TYPE char6 OPTIONAL
!iv_field TYPE text60 OPTIONAL
!iv_field_text TYPE text60 OPTIONAL .
CLASS-METHODS bal_log_refresh
IMPORTING
!iv_handle TYPE balloghndl
RETURNING
VALUE(r_bool) TYPE abap_bool .
CLASS-METHODS select_cost_centers
IMPORTING
!it_kostl TYPE ty_r_kostl
RETURNING
VALUE(rt_result) TYPE ty_t_result .
PROTECTED SECTION.
PRIVATE SECTION.
CONSTANTS c_object TYPE balobj_d VALUE 'ZPS' ##NO_TEXT.
CONSTANTS c_subobject TYPE balsubobj VALUE 'PTOOL' ##NO_TEXT.
ENDCLASS.
CLASS zcl_ptool_helper IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_DB_DELETE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_LOG_HEADER TYPE BALHDR_T
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_db_delete.
IF NOT it_log_header IS INITIAL.
DATA(lt_log_handle) = VALUE bal_t_logh( FOR <fs_handle> IN it_log_header ( <fs_handle>-log_handle ) ).
IF lt_log_handle[] IS NOT INITIAL.
CALL FUNCTION 'BAL_DB_DELETE'
EXPORTING
* I_T_LOGS_TO_DELETE =
i_t_log_handle = lt_log_handle
* I_T_LOGNUMBER =
i_client = sy-mandt
* I_IN_UPDATE_TASK = ' '
i_with_commit_work = abap_true
* I_PACKAGE_SIZE = 100
EXCEPTIONS
no_logs_specified = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_DB_SAVE
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_db_save.
* Encerrando BALLOG
DATA(lv_second_connection) = VALUE dbcon_name( ) .
DATA(lt_new) = VALUE bal_t_lgnm( ( ) ).
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_client = sy-mandt
* i_in_update_task = abap_true
i_save_all = abap_true
* i_t_log_handle = iv_handle
i_2th_connection = abap_true
i_2th_connect_commit = abap_true
* I_LINK2JOB = 'X'
IMPORTING
e_new_lognumbers = lt_new
* e_second_connection = lv_second_connection
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
INTO DATA(lv_dummy).
* Implement suitable error handling here
ENDIF.
*
* CALL FUNCTION 'BAL_DB_SAVE'
* EXPORTING
* i_save_all = abap_true
* EXCEPTIONS
* log_not_found = 1
* save_not_allowed = 2
* numbering_error = 3
* OTHERS = 4.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_DB_SEARCH
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_SUBOBJECT TYPE BALSUBOBJ(optional)
* | [--->] IV_OBJECT TYPE BALOBJ_D
* | [<-()] RT_LOG_HEADER TYPE BALHDR_T
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_db_search.
DATA(is_log_filter) = VALUE bal_s_lfil(
object = VALUE bal_r_obj( sign = |I| option = |EQ| ( low = iv_object ) )
subobject = VALUE bal_r_sub( sign = |I| option = |EQ| ( low = iv_subobject ) ) ).
CALL FUNCTION 'BAL_DB_SEARCH'
EXPORTING
i_client = sy-mandt
i_s_log_filter = is_log_filter
* I_T_SEL_FIELD =
* I_TZONE =
IMPORTING
e_t_log_header = rt_log_header
EXCEPTIONS
log_not_found = 1
no_filter_criteria = 2
OTHERS = 3.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_LOG_CREATE
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_EXTNUMBER TYPE BALNREXT(optional)
* | [--->] IV_SUBOBJECT TYPE BALSUBOBJ(optional)
* | [--->] IV_OBJECT TYPE BALOBJ_D
* | [<-()] R_HANDLE TYPE BALLOGHNDL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_log_create.
DATA(ls_log) = VALUE bal_s_log(
extnumber = iv_extnumber
object = iv_object
subobject = iv_subobject
aldate = sy-datum
altime = sy-uzeit
aluser = sy-uname
alprog = sy-repid
aldate_del = sy-datum + 7
del_before = abap_false ).
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = ls_log
IMPORTING
e_log_handle = r_handle
EXCEPTIONS
OTHERS = 1.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_LOG_HDR_READ
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_HANDLE TYPE BALLOGHNDL
* | [<-()] RS_STATISTICS TYPE BAL_S_SCNT
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_log_hdr_read.
CHECK NOT iv_handle IS INITIAL.
* are there any messages in this log ?
CALL FUNCTION 'BAL_LOG_HDR_READ'
EXPORTING
i_log_handle = iv_handle
IMPORTING
e_statistics = rs_statistics
EXCEPTIONS
OTHERS = 1.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_LOG_MSG_ADD
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_HANDLE TYPE BALLOGHNDL
* | [--->] IV_TABNAME TYPE BALTABNAME(optional)
* | [--->] IV_SORT_FIELD TYPE CHAR6(optional)
* | [--->] IV_FIELD TYPE TEXT60(optional)
* | [--->] IV_FIELD_TEXT TYPE TEXT60(optional)
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_log_msg_add.
DATA(ls_log_msg) = VALUE bal_s_msg(
msgty = sy-msgty
msgid = sy-msgid
msgno = sy-msgno
msgv1 = sy-msgv1
msgv2 = sy-msgv2
msgv3 = sy-msgv3
msgv4 = sy-msgv4
context = VALUE bal_s_cont( tabname = iv_tabname
value = VALUE bal_s_ex07( sort_field = iv_sort_field
field = iv_field
field_text = iv_field_text ) ) ).
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = iv_handle
i_s_msg = ls_log_msg
EXCEPTIONS
OTHERS = 1.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>BAL_LOG_REFRESH
* +-------------------------------------------------------------------------------------------------+
* | [--->] IV_HANDLE TYPE BALLOGHNDL
* | [<-()] R_BOOL TYPE ABAP_BOOL
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD bal_log_refresh.
IF NOT iv_handle IS INITIAL.
CALL FUNCTION 'BAL_LOG_REFRESH'
EXPORTING
i_log_handle = iv_handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
r_bool = abap_true.
ENDIF.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method ZCL_PTOOL_HELPER=>SELECT_COST_CENTERS
* +-------------------------------------------------------------------------------------------------+
* | [--->] IT_KOSTL TYPE TY_R_KOSTL
* | [<-()] RT_RESULT TYPE TY_T_RESULT
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD select_cost_centers.
SELECT DISTINCT
kostl, prctr
INTO TABLE @rt_result
FROM csks
WHERE kokrs = 'PWBR'
AND kostl IN @it_kostl
AND datbi > @sy-datum.
ENDMETHOD.
ENDCLASS.