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

export_to_table do not generate messages from exceptions #83

Closed
marcelloganzaroli opened this issue Apr 1, 2021 · 4 comments · Fixed by #152
Closed

export_to_table do not generate messages from exceptions #83

marcelloganzaroli opened this issue Apr 1, 2021 · 4 comments · Fixed by #152

Comments

@marcelloganzaroli
Copy link

marcelloganzaroli commented Apr 1, 2021

Hi All,

I realized method ZIF_LOGGER~EXPORT_TO_TABLE does not generate a message table from logged exception classes.
The method uses function module 'BAL_LOG_MSG_READ' that cannot read an exception based message.

How to replicate:

  1. Create an instance of the logger.
  2. Log any other message
  3. Raise any exception with T100
  4. log the exception
  5. execute export_to_table

I believe something can be done with BAL_LOG_EXCEPTION_READ function but it's quite limited as well.
For my local system and scenario usage, the enhancement bellow was enough, didn't had much time to look further

DATA: 
      message_handles TYPE bal_t_msgh,
      message         TYPE bal_s_msg,
      bapiret2        TYPE bapiret2,
      exception_log   TYPE bal_s_excr,
      exception_msg   TYPE char255.

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>
    IMPORTING
      e_s_msg        = message
    EXCEPTIONS
      OTHERS         = 3.
  IF sy-subrc IS INITIAL.
    MESSAGE ID message-msgid
            TYPE message-msgty
            NUMBER message-msgno
            INTO bapiret2-message
            WITH message-msgv1 message-msgv2 message-msgv3 message-msgv4.

    bapiret2-type       = message-msgty.
    bapiret2-id         = message-msgid.
    bapiret2-number     = message-msgno.
    bapiret2-log_no     = <msg_handle>-log_handle.     "last 2 chars missing!!
    bapiret2-log_msg_no = <msg_handle>-msgnumber.
    bapiret2-message_v1 = message-msgv1.
    bapiret2-message_v2 = message-msgv2.
    bapiret2-message_v3 = message-msgv3.
    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_s_exc        = exception_log
        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.
      APPEND bapiret2 TO rt_bapiret.
    ENDIF.
  ENDIF.
ENDLOOP.

Thanks :)

@HuprichT
Copy link
Contributor

HuprichT commented Nov 4, 2023

I tested it too and it works for me. Can anyone enlighten me and explain why this should be limited in its function?

mbtools added a commit that referenced this issue Dec 8, 2023
@mbtools
Copy link
Contributor

mbtools commented Dec 8, 2023

Can you test if #152 fixes this issue?

@HuprichT Where else should this be added?

@HuprichT
Copy link
Contributor

HuprichT commented Dec 9, 2023

Hi, @mbtools. LGTM, exported Table now has Exception in it. Display Methods are working like expected.

What I noticed regarding the initial error description from @marcelloganzaroli :
The problem is not with the T100, but with the type of exception. CX_SY_DYNAMIC_CHECK is not loaded by BAL_LOG_MSG_READ but an exception of type CX_SY_STATIC_CHECK is.

image

Not sure if this is relevant, the main thing is that it is now running.

@mbtools
Copy link
Contributor

mbtools commented Dec 11, 2023

it does matter... for implementing a nice unit test 😄

AlexandreHT pushed a commit that referenced this issue Dec 12, 2023
* Fix exporting exception messages

Closes #83

* Add UT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants