Nova forma de fazer.
*============ LEITURA DE LOG
METHOD get_log.
TRY.
DATA(lo_filter) = cl_bali_log_filter=>create(
)->set_create_info( user = sy-uname
)->set_descriptor( object = 'ZSD_INDINT'
subobject = 'LOG_PROC'
external_id = CONV balnrext( iv_id ) ).
DATA(lv_data_final) = utclong_current( ).
DATA(lv_data_inicio) = utclong_add( val = lv_data_final
days = '30-' ).
lo_filter->set_time_interval( start_time = lv_data_inicio
end_time = lv_data_final ).
lo_filter->set_maximum_log_number( max_log_number = 5 ).
DATA(lo_log_table) = cl_bali_log_db=>get_instance( )->load_logs_w_items_via_filter( filter = lo_filter ).
CATCH cx_bali_runtime INTO DATA(l_exception).
RETURN.
ENDTRY.
LOOP AT lo_log_table INTO DATA(lr_log).
" Get log header and output attributes of the header
DATA(lv_header) = lr_log->get_header( ).
APPEND INITIAL LINE TO rt_return ASSIGNING FIELD-SYMBOL(<lf_return>).
<lf_return> = VALUE #( id = 'ZSD' type = 'I' number = '000'
message_v1 = |Data/hora log:|
message_v2 = lv_header->log_timestamp ).
" Get all items and output some data which exist in all item categories
DATA(lt_item_table) = lr_log->get_all_items( ).
LOOP AT lt_item_table INTO DATA(lr_item_entry).
" Output attributes which are specific for messages and exceptions
IF lr_item_entry-item->category = if_bali_constants=>c_category_message.
DATA(lo_message_ref) = CAST if_bali_message_getter( lr_item_entry-item ).
APPEND INITIAL LINE TO rt_return ASSIGNING <lf_return>.
<lf_return> = VALUE #( id = lo_message_ref->id
type = lo_message_ref->severity
number = lo_message_ref->number
message_v1 = lo_message_ref->variable_1
message_v2 = lo_message_ref->variable_2
message_v3 = lo_message_ref->variable_3
message_v4 = lo_message_ref->variable_4
message = lo_message_ref->get_message_text( ) ).
ENDIF.
ENDLOOP.
ENDLOOP.
ENDMETHOD.
FORM f_grava_log USING fu_bapiret2 TYPE bapiret2_t
CHANGING fc_lognum TYPE balognr.DATA:
l_log_handle TYPE balloghndl,
ls_log TYPE bal_s_log,
ls_log_message TYPE bal_s_msg,
lt_log_handle TYPE bal_t_logh,
lt_log_num TYPE bal_t_lgnm.
CLEAR:
lt_log_handle,
lt_log_num.
FIELD-SYMBOLS <lt_ldat> TYPE ANY TABLE.
IF fc_lognum IS NOT INITIAL.
PERFORM f_delete_log USING fc_lognum.
ENDIF.
*--------------------------------------------------------------------*
* Set BAL LOG object
*--------------------------------------------------------------------*
ls_log-object = gc_log_obj.
ls_log-subobject = gc_log_subobj.
ls_log-aldate = sy-datum.
ls_log-altime = sy-uzeit.
ls_log-aluser = sy-uname.
*--------------------------------------------------------------------*
* Create new BAL LOG
*--------------------------------------------------------------------*
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = ls_log
IMPORTING
e_log_handle = l_log_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
*--------------------------------------------------------------------*
* Add messages to the LOG
*--------------------------------------------------------------------*
LOOP AT fu_bapiret2 INTO DATA(ls_return)
WHERE type = 'E'.
ls_log_message-msgty = ls_return-type.
ls_log_message-msgid = ls_return-id.
ls_log_message-msgno = ls_return-number.
ls_log_message-msgv1 = ls_return-message_v1.
ls_log_message-msgv2 = ls_return-message_v2.
ls_log_message-msgv3 = ls_return-message_v3.
ls_log_message-msgv4 = ls_return-message_v4.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = l_log_handle
i_s_msg = ls_log_message
EXCEPTIONS
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
OTHERS = 4.
ENDLOOP.
*--------------------------------------------------------------------*
* Save the LOG to the database
*--------------------------------------------------------------------*
APPEND l_log_handle TO lt_log_handle.
"Elimino log sem o objeto subobjeto na função.
ASSIGN ('(SAPLSBAL)G-T_LDAT[]') TO <lt_ldat>.
IF sy-subrc = 0.
DELETE <lt_ldat>
WHERE ('LOG-OBJECT = SPACE').
ENDIF.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_client = sy-mandt
i_save_all = abap_true
i_t_log_handle = lt_log_handle
IMPORTING
e_new_lognumbers = lt_log_num
EXCEPTIONS
log_not_found = 1
save_not_allowed = 2
numbering_error = 3
OTHERS = 4.
IF lt_log_num[] IS NOT INITIAL.
fc_lognum = lt_log_num[ lines( lt_log_num ) ]-lognumber.
ENDIF.
ENDFORM.
DATA:
lt_log_header TYPE balhdr_t,
ls_log_filter TYPE bal_s_lfil,
ls_display_prof TYPE bal_s_prof.
CLEAR:
lt_log_header,
ls_log_filter,
ls_display_prof.
CHECK fu_lognum IS NOT INITIAL.
APPEND INITIAL LINE TO ls_log_filter-lognumber ASSIGNING FIELD-SYMBOL(<fs_log_num>).
<fs_log_num>-sign = 'I'.
<fs_log_num>-option = 'EQ'.
<fs_log_num>-low = fu_lognum.
APPEND INITIAL LINE TO ls_log_filter-object ASSIGNING FIELD-SYMBOL(<fs_obj>).
<fs_obj>-sign = 'I'.
<fs_obj>-option = 'EQ'.
<fs_obj>-low = gc_log_obj.
APPEND INITIAL LINE TO ls_log_filter-subobject ASSIGNING FIELD-SYMBOL(<fs_subobj>).
<fs_subobj>-sign = 'I'.
<fs_subobj>-option = 'EQ'.
<fs_subobj>-low = gc_log_subobj.
CALL FUNCTION 'BAL_DB_SEARCH'
EXPORTING
i_s_log_filter = ls_log_filter
IMPORTING
e_t_log_header = lt_log_header
EXCEPTIONS
log_not_found = 1
no_filter_criteria = 2.
IF sy-subrc <> 0.
MESSAGE i030 DISPLAY LIKE 'E'.
ENDIF.
CALL FUNCTION 'BAL_DB_LOAD'
EXPORTING
i_t_log_header = lt_log_header
EXCEPTIONS
no_logs_specified = 1
log_not_found = 2
log_already_loaded = 3.
CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
IMPORTING
e_s_display_profile = ls_display_prof
EXCEPTIONS
OTHERS = 1.
IF sy-subrc IS NOT INITIAL.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
DISPLAY LIKE 'I'.
ENDIF.
* Display in ALV popup
ls_display_prof-use_grid = abap_true.
ls_display_prof-disvariant-report = sy-repid.
ls_display_prof-disvariant-handle = 'LOG'.
ls_display_prof-pop_adjst = abap_true.
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
* i_t_log_handle = lt_log_handle
i_s_display_profile = ls_display_prof
EXCEPTIONS
OTHERS = 1.
IF sy-subrc IS NOT INITIAL.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
DISPLAY LIKE 'I'.
ENDIF.
READ TABLE lt_log_header INTO DATA(ls_log_header) INDEX 1.
* Free messages from the memory
CALL FUNCTION 'BAL_LOG_REFRESH'
EXPORTING
i_log_handle = ls_log_header-log_handle
EXCEPTIONS
log_not_found = 1
OTHERS = 2.
IF sy-subrc IS NOT INITIAL.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
DISPLAY LIKE 'I'.
ENDIF.
ENDFORM.
*& Form F_DELETE_LOG
*&---------------------------------------------------------------------*
FORM f_delete_log USING fu_lognum TYPE balognr.
DATA: lt_log_del TYPE balhdr_t.
SELECT *
INTO TABLE lt_log_del
FROM balhdr
WHERE lognumber EQ fu_lognum.
CHECK sy-subrc = 0.
CALL FUNCTION 'BAL_DB_DELETE'
EXPORTING
i_t_logs_to_delete = lt_log_del
i_package_size = 100
i_in_update_task = abap_true
EXCEPTIONS
no_logs_specified = 1
OTHERS = 2.
ENDFORM.
Nenhum comentário:
Postar um comentário