Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exporting exception messages #152

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/zcl_logger.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -737,13 +737,15 @@ CLASS zcl_logger IMPLEMENTATION.
METHOD zif_logger~export_to_table.
DATA: message_handles TYPE bal_t_msgh,
message TYPE bal_s_msg,
bapiret2 TYPE bapiret2.
bapiret2 TYPE bapiret2,
exception_msg TYPE c LENGTH 255.

FIELD-SYMBOLS <msg_handle> TYPE balmsghndl.

message_handles = get_message_handles( ).

LOOP AT message_handles ASSIGNING <msg_handle>.
CLEAR bapiret2.
CALL FUNCTION 'BAL_LOG_MSG_READ'
EXPORTING
i_s_msg_handle = <msg_handle>
Expand All @@ -769,6 +771,25 @@ CLASS zcl_logger IMPLEMENTATION.
bapiret2-message_v4 = message-msgv4.
bapiret2-system = sy-sysid.
APPEND bapiret2 TO rt_bapiret.
ELSE.
CALL FUNCTION 'BAL_LOG_EXCEPTION_READ'
EXPORTING
i_s_msg_handle = <msg_handle>
i_langu = sy-langu
IMPORTING
e_txt_msg = exception_msg
EXCEPTIONS
log_not_found = 1
msg_not_found = 2
OTHERS = 3.
IF sy-subrc = 0.
bapiret2-type = message-msgty.
bapiret2-log_no = <msg_handle>-log_handle.
bapiret2-log_msg_no = <msg_handle>-msgnumber.
bapiret2-message = exception_msg.
bapiret2-system = sy-sysid.
APPEND bapiret2 TO rt_bapiret.
ENDIF.
ENDIF.
ENDLOOP.
ENDMETHOD.
Expand Down
34 changes: 27 additions & 7 deletions src/zcl_logger.clas.testclasses.abap
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ CLASS lcl_test DEFINITION FOR TESTING
return_proper_length FOR TESTING,
can_add_table_msg_context FOR TESTING RAISING cx_static_check,
can_log_string_and_export FOR TESTING,
can_log_exception_and_export FOR TESTING,
can_change_description FOR TESTING RAISING cx_static_check,
can_log_callback_params FOR TESTING RAISING cx_static_check,
can_log_log.
can_log_log FOR TESTING.

ENDCLASS.

Expand Down Expand Up @@ -604,10 +605,10 @@ CLASS lcl_test IMPLEMENTATION.

METHOD can_log_rcomp.
DATA:
msg_handle TYPE balmsghndl,
expected_details TYPE bal_s_msg,
actual_details TYPE bal_s_msg,
actual_text TYPE char200.
msg_handle TYPE balmsghndl,
expected_details TYPE bal_s_msg,
actual_details TYPE bal_s_msg,
actual_text TYPE char200.

"Solution manager doens't have PROTT. Therefore avoid using the concrete type
DATA rcomp_data_ref TYPE REF TO data.
Expand Down Expand Up @@ -1025,10 +1026,10 @@ CLASS lcl_test IMPLEMENTATION.
comp1 TYPE string,
comp2 TYPE i,
END OF ty_struct,
BEGIN OF ty_deep_struct,
BEGIN OF ty_deep_struct,
comp1 TYPE string,
deep TYPE ty_struct,
END OF ty_deep_struct.
END OF ty_deep_struct.
DATA: struct TYPE ty_deep_struct,
act_table TYPE table_of_strings,
exp_table TYPE table_of_strings,
Expand Down Expand Up @@ -1409,6 +1410,25 @@ CLASS lcl_test IMPLEMENTATION.
msg = 'Did not log system message properly' ).
ENDMETHOD.

METHOD can_log_exception_and_export.
DATA:
table TYPE bapirettab,
error TYPE REF TO cx_sy_zerodivide.

TRY.
RAISE EXCEPTION TYPE cx_sy_zerodivide.
CATCH cx_sy_zerodivide INTO error.
anon_log->add( error ).
ENDTRY.

table = anon_log->export_to_table( ).

cl_abap_unit_assert=>assert_equals(
exp = 1
act = lines( table )
msg = 'Did not log exception message properly' ).
ENDMETHOD.

METHOD can_change_description.

DATA desc TYPE bal_s_log-extnumber.
Expand Down