美文网首页
一个查看 SAP CRM One Order 运行时生成的应用日

一个查看 SAP CRM One Order 运行时生成的应用日

作者: _扫地僧_ | 来源:发表于2023-12-09 11:20 被阅读0次

    方法参数定义:


    方法源代码:

      METHOD GET_ORDER_ERROR_MESSAGE_OPT.
        DATA:
          ls_log_filter TYPE bal_s_lfil,
          ls_extnumber  TYPE bal_s_extn,
          ls_object     LIKE ls_extnumber,
          ls_subobject  LIKE ls_extnumber,
          lt_log_header TYPE balhdr_t,
          lt_allmsgs    TYPE bal_t_msgh,
          ls_msg        TYPE bal_s_msg,
          ls_log        TYPE crmt_odata_task_logs,
          ls_protype    LIKE ls_extnumber.
    
        FIELD-SYMBOLS: <order_guid>  TYPE crmt_object_guid,
                       <msg_handler> LIKE LINE OF lt_allmsgs,
                       <log_header>  LIKE LINE OF lt_log_header.
    
        LOOP AT it_order_guid_tab ASSIGNING <order_guid>.
          ls_extnumber-sign = 'I'.
          ls_extnumber-option = 'EQ'.
          ls_extnumber-low = <order_guid>.
          APPEND ls_extnumber TO ls_log_filter-extnumber.
        ENDLOOP.
    
        ls_object-sign = ls_subobject-sign = ls_protype-sign = 'I' .
        ls_object-option = ls_subobject-option = 'EQ'.
        ls_object-low = 'CRM_DOCUMENT'.
        APPEND ls_object TO ls_log_filter-object.
    
        ls_subobject-low = 'SINGLE'.
        APPEND ls_subobject TO ls_log_filter-subobject.
    
        ls_protype-option = 'LE'.
        ls_protype-low = '2'. " priority very important & important
        APPEND ls_protype TO ls_log_filter-probclass.
    
        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.
    
        CHECK sy-subrc = 0.
    
        CALL FUNCTION 'BAL_DB_LOAD'
          EXPORTING
            i_t_log_header     = lt_log_header
          IMPORTING
            e_t_msg_handle     = lt_allmsgs
          EXCEPTIONS
            no_logs_specified  = 1
            log_not_found      = 2
            log_already_loaded = 3.
    
        CHECK sy-subrc = 0.
    
        DATA: lt_logh  TYPE bal_t_logh,
              ls_mfil  TYPE bal_s_mfil,
              lt_cfil  TYPE bal_t_cfil,
              ls_cfil  LIKE LINE OF lt_cfil,
              lr_field LIKE LINE OF ls_cfil-t_range,
              lr_level LIKE LINE OF ls_mfil-detlevel.
    
        LOOP AT lt_log_header ASSIGNING <log_header>.
          INSERT <log_header>-log_handle INTO TABLE lt_logh.
        ENDLOOP.
    
        lr_level-sign   = 'I'.
        lr_level-option = 'LE'.
    *   default level - employee, refer to FM CRM_ORDER_VALUE_RANGE_CHECK for detail
        lr_level-low    = '3'.
        APPEND lr_level TO ls_mfil-detlevel.
    
        ls_cfil-tabname   = 'CRMT_MSG_CONTEXT'.
        ls_cfil-fieldname = 'INACTIVE'.
    
        lr_field-option = 'EQ'.
        lr_field-sign   = 'I'.
        lr_field-low    = space.
        APPEND lr_field TO ls_cfil-t_range.
        APPEND ls_cfil TO lt_cfil.
    
        CALL FUNCTION 'BAL_GLB_SEARCH_MSG'
          EXPORTING
            i_t_log_handle         = lt_logh
            i_s_msg_filter         = ls_mfil
            i_t_msg_context_filter = lt_cfil
          IMPORTING
            e_t_msg_handle         = lt_allmsgs
          EXCEPTIONS
            msg_not_found          = 1
            OTHERS                 = 2.
    
        CHECK sy-subrc = 0.
    
        LOOP AT lt_allmsgs ASSIGNING <msg_handler>.
          CLEAR: ls_msg.
          CALL FUNCTION 'CRM_MESSAGES_GET_MSG_INFO'
            EXPORTING
              is_msg_handle = <msg_handler>
            IMPORTING
              es_msg        = ls_msg
            EXCEPTIONS
              OTHERS        = 99.
          CHECK sy-subrc = 0.
    *     message priority and message type are two different perspective so here we still need to filter by message type
          CHECK ls_msg-msgty = 'E'.
          CLEAR ls_log.
          ls_log-msgid = ls_msg-msgid.
          ls_log-msgno = ls_msg-msgno.
          ls_log-msg_type = ls_msg-msgty.
          READ TABLE lt_log_header ASSIGNING <log_header> WITH KEY log_handle = <msg_handler>-log_handle.
          ASSERT sy-subrc = 0.
          ls_log-header_guid = <log_header>-extnumber.
          MESSAGE ID ls_msg-msgid TYPE ls_msg-msgty NUMBER ls_msg-msgno
                  WITH ls_msg-msgv1 ls_msg-msgv2 ls_msg-msgv3 ls_msg-msgv4 INTO ls_log-log_msg.
          APPEND ls_log TO et_messages.
        ENDLOOP.
    
      ENDMETHOD.
    

    用到的 Function Module BAL_GLB_SEARCH_MSG 介绍:

    BAL_GLB_SEARCH_MSG 的参数包括 I_MSGID(消息 ID)、I_MSGNO(消息编号)、I_MSGV1I_MSGV4(消息变量)、E_LOGNUMBER(日志编号)和 E_LOG_HANDLE(日志句柄)。当你使用这个 Function Module 查找消息时,你需要提供消息的 ID 和编号,你也可以选择性地提供消息变量。Function Module 会返回找到的消息的日志编号和日志句柄。

    举个例子,假设你在运行某个 SAP 事务时遇到了一个错误消息,这个消息的 ID 是 ZMYMSGID,编号是 001,并且它有一个变量 VAR1。你可以使用 BAL_GLB_SEARCH_MSG 来查找这个消息:

    DATA: lv_lognumber TYPE balloghndl,
          lv_log_handle TYPE balloghndl.
    
    CALL FUNCTION 'BAL_GLB_SEARCH_MSG'
      EXPORTING
        i_msgid  = 'ZMYMSGID'
        i_msgno  = '001'
        i_msgv1  = 'VAR1'
      IMPORTING
        e_lognumber  = lv_lognumber
        e_log_handle = lv_log_handle.
    
    IF lv_lognumber IS INITIAL.
      WRITE: '没有找到匹配的消息'.
    ELSE.
      WRITE: '找到了匹配的消息,日志编号是 ', lv_lognumber.
    ENDIF.
    

    在这个例子中,如果找到了匹配的消息,lv_lognumber 将会被赋予相应的日志编号。如果没有找到匹配的消息,lv_lognumber 将会保持初始值。

    BAL_GLB_SEARCH_MSG 是一个非常有用的 Function Module,它可以帮助你在系统中查找特定的消息。但是,你需要注意的是,查找的范围可能会受到你的系统设置的限制。例如,如果你的系统设置为只保留一定时间内的日志,那么你可能无法找到更早期的消息。

    相关文章

      网友评论

          本文标题:一个查看 SAP CRM One Order 运行时生成的应用日

          本文链接:https://www.haomeiwen.com/subject/ycquwdtx.html