欢迎来到萧静默的博客

书山有路勤为径,学海无涯苦作舟。

SAP的PI日志查看工具

被很多人吐槽的SAP PI能坚挺的活下来,真是不容易。。。

SXI_MONITOR是PI的标准的消息查看器,如果又权限的话,甚至可以做自定义字段的查询增强(如果对单据创建接口,增加单号。。。速度杠杠的)

SXI_MONITOR为什么不好呢,一是不直观,东西太多,太复杂了。二呢就是展示消息太麻烦了,这让很多人深恶痛绝。

下面说一下PI日志的几个表:

SXMSPEMAS——Integration Engine: Enhanced Message Queue (Master) 队列消息的框架信息,包含发送接收方的接口名字,命名空间,系统等。
SXMSPMAST——Integration Engine: Message Queue (Master) 队列消息的主要信息,包含了用户啊,开始结束时间等等。

 

SXMSCLUR——XMB: Resources Cluster 消息报文

下面上代码:(随便写写的,有不当的地方可以自行完善)

REPORT ZLYLOG123.
DATA:V_DA TYPE SXMSCLUR.
DATA LT_BIN_CONTENT     TYPE SDOKCNTBINS.
DATA:V_TAB TYPE TABLE OF XSTRING,
     W_TAB TYPE XSTRING.
TYPES:BEGIN OF TY_SHOW,
        OBJECT_ID TYPE CRMT_PO_NUMBER_SOLD,
        MSGTYPE   TYPE C,
        OB_SYSTEM TYPE AIT_SNDR,
        OB_NS     TYPE RM_OIFNS,
        OB_NAME   TYPE RM_OIFNAME,
        IB_SYSTEM TYPE AIT_RCVR,
        IB_NS     TYPE RM_IIFNS,
        IB_NAME   TYPE RM_IIFNAME,
        MSGINFO   TYPE CHAR100,
        IXML      TYPE STRING,
        OXML      TYPE STRING,
      END OF TY_SHOW,
      BEGIN OF TY_DETAIL,
        MSGGUID    TYPE SXMSMGUID,
        PID        TYPE SXMSPID,
        MSGTYPE       TYPE SXMSPMTYPE,
        MSGSTATE   TYPE    SXMSPMSTAT,
        QOSMODE    TYPE SXMSQOS,
        SENDTIMEST TYPE    TIMESTAMPL,
        REF_TO_MSG TYPE    SXMSMGUID,
        OB_SYSTEM  TYPE AIT_SNDR,
        OB_NS      TYPE RM_OIFNS,
        OB_NAME    TYPE RM_OIFNAME,
        IB_SYSTEM  TYPE AIT_RCVR,
        IB_NS      TYPE RM_IIFNS,
        IB_NAME    TYPE RM_IIFNAME,
      END OF TY_DETAIL.
DATA:IM_CLUSTKEY TYPE  SXMSCLUSTKEY,
     EX_RES      TYPE  SXMSREST,
     EX_XRES     TYPE  SXMSXREST,
     EW_XRES     TYPE SXMSXRESS,
     EX_NS       TYPE  SXMSNST,
     IM_MANDT    TYPE  SYMANDT,
     WA_CLUR     TYPE SXMSCLUR,
     GV_FROM     TYPE TIMESTAMPL,
     GV_TO       TYPE TIMESTAMPL,
     GT_SHOW     TYPE TABLE OF TY_SHOW,
     GW_SHOW     LIKE LINE OF GT_SHOW,
     GT_LOG      TYPE TABLE OF ZCRMTVSLOG,
     GW_LOG      TYPE ZCRMTVSLOG,
     GT_DETAIL   TYPE TABLE OF TY_DETAIL,
     GW_DETAIL   LIKE LINE OF GT_DETAIL.
DATA:GT_FIELDCAT TYPE LVC_T_FCAT.
DATA GS_FIELDCAT LIKE LINE OF GT_FIELDCAT.
DATA LS_LAYOUT TYPE LVC_S_LAYO.
DATA:RESULT TYPE STRING.
DATA:LV_B TYPE I,
     LV_E TYPE I,
     LV_L TYPE I.

TABLES:SXMSPEMAS.

DEFINE APPEND_FIELDCAT .
  CLEAR GS_FIELDCAT.
  GS_FIELDCAT-FIELDNAME = &1.
  GS_FIELDCAT-SCRTEXT_L = &2.
  GS_FIELDCAT-OUTPUTLEN = &3.
  GS_FIELDCAT-NO_ZERO = &4.
  APPEND GS_FIELDCAT TO GT_FIELDCAT.
END-OF-DEFINITION.
*table:SXMSPEMAS 接口信息

SELECTION-SCREEN:BEGIN OF BLOCK BLK01 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:S_SEND FOR SXMSPEMAS-OB_SYSTEM.
SELECT-OPTIONS:S_OBNS FOR SXMSPEMAS-OB_NS.
SELECT-OPTIONS:S_OBNAME FOR SXMSPEMAS-OB_NAME.
SELECT-OPTIONS:S_IEND FOR SXMSPEMAS-OB_SYSTEM.
SELECT-OPTIONS:S_IBNS FOR SXMSPEMAS-OB_NS.
SELECT-OPTIONS:S_IBNAME FOR SXMSPEMAS-OB_NAME.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (31) TEXT-CM7 FOR FIELD EXEDATE.
PARAMETERS: EXEDATE TYPE SY-DATUM.
SELECTION-SCREEN COMMENT 46(2) TEXT-CM9 FOR FIELD EXETIME.
PARAMETERS: EXETIME  TYPE SY-UZEIT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (31) TEXT-CM8 FOR FIELD EXE2DATE.
PARAMETERS: EXE2DATE  TYPE SY-DATUM.
SELECTION-SCREEN COMMENT 46(2) TEXT-CM9 FOR FIELD EXE2TIME.
PARAMETERS: EXE2TIME  TYPE SY-UZEIT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BLK01.


INITIALIZATION.
  IF EXETIME IS INITIAL.
    EXEDATE = SY-DATLO.
    IF SY-TIMLO < 010000.
      EXEDATE = EXEDATE - 00000001.
    ENDIF.
    EXETIME = SY-TIMLO - 003600.
  ENDIF.
  IF EXE2DATE IS INITIAL.
    EXE2DATE = SY-DATLO + 00000001.
  ENDIF.



START-OF-SELECTION.
  "优先查询logb表记录,然后再拼接时间戳否则按时间戳查询
*  IF S_NOBJ IS NOT INITIAL OR S_OBJ IS NOT INITIAL OR S_TYPE IS NOT INITIAL.
*    SELECT SINGLE * INTO GW_LOG FROM ZCRMTVSLOG WHERE NEW_OBJECT_ID IN S_NOBJ AND OBJECT_ID IN S_OBJ AND PROCESS_TYPE IN S_TYPE.
*    IF GW_LOG-UZEIT < '000059'.
*      GW_LOG-UZEIT = '000000'.
*    ELSEIF GW_LOG-UZEIT > '235900'.
*      GW_LOG-UZEIT = '235900'.
*    ELSE.
*      GW_LOG-UZEIT = GW_LOG-UZEIT - 60.
*    ENDIF.
*    CONVERT DATE GW_LOG-DATUM TIME GW_LOG-UZEIT INTO TIME STAMP GV_FROM TIME ZONE SY-ZONLO.
*    GW_LOG-UZEIT = GW_LOG-UZEIT + 120.
*    CONVERT DATE GW_LOG-DATUM TIME GW_LOG-UZEIT INTO TIME STAMP GV_TO TIME ZONE SY-ZONLO.
*  ELSE.
* EXE timestamp (UTC) supplied: Convert to date/time in local user timezone:
  IF EXEDATE IS NOT INITIAL.
    CONVERT DATE EXEDATE TIME EXETIME INTO TIME STAMP GV_FROM TIME ZONE SY-ZONLO.
  ENDIF.
* EXE TO timestamp (UTC) supplied: Convert to date/time in local user timezone:
  IF EXE2DATE IS NOT INITIAL.
    CONVERT DATE EXE2DATE TIME EXE2TIME INTO TIME STAMP GV_TO TIME ZONE SY-ZONLO.
  ENDIF.

*  ENDIF.
  "get mast data from SXMSPMAST
  SELECT
        SXMSPMAST~MSGGUID
        SXMSPMAST~PID
        SXMSPMAST~MSGTYPE
        SXMSPMAST~MSGSTATE
        SXMSPMAST~QOSMODE
        SXMSPMAST~SENDTIMEST
        SXMSPMAST~REF_TO_MSG
        SXMSPEMAS~OB_SYSTEM
        SXMSPEMAS~OB_NAME
        SXMSPEMAS~IB_SYSTEM
        SXMSPEMAS~IB_NAME
    INTO TABLE GT_DETAIL
    FROM SXMSPMAST
    INNER JOIN SXMSPEMAS
    ON SXMSPMAST~MSGGUID = SXMSPEMAS~MSGGUID
    AND SXMSPMAST~PID = SXMSPEMAS~PID
    WHERE SXMSPMAST~SENDTIMEST BETWEEN GV_FROM AND GV_TO AND SXMSPMAST~MSGTYPE = 'S' AND SXMSPMAST~PID = 'RECEIVER'
    AND   SXMSPEMAS~OB_SYSTEM IN S_SEND
    AND   SXMSPEMAS~OB_NS IN S_OBNS
    AND   SXMSPEMAS~OB_NAME IN S_OBNAME
    AND   SXMSPEMAS~IB_SYSTEM IN S_IEND
    AND   SXMSPEMAS~IB_NS IN S_IBNS
    AND   SXMSPEMAS~IB_NAME IN S_IBNAME
    .
  SORT GT_DETAIL BY REF_TO_MSG.
  LOOP AT GT_DETAIL INTO GW_DETAIL.
    CLEAR:EX_RES[],EX_XRES[],EX_NS[],WA_CLUR.
    IM_CLUSTKEY-MSGGUID = GW_DETAIL-MSGGUID.
    IM_CLUSTKEY-PID     = GW_DETAIL-PID.
    IM_MANDT = 300.
    "导入XML各项数据
    IMPORT LT_RES  TO EX_RES LT_XRES TO EX_XRES LT_NS TO EX_NS FROM DATABASE SXMSCLUR(IS) TO WA_CLUR CLIENT IM_MANDT ID IM_CLUSTKEY.
    "读取XML报文
    READ TABLE EX_XRES INTO EW_XRES INDEX 1.
    IF SY-SUBRC = 0.

      "XML报文解码
      RESULT = CL_ABAP_CODEPAGE=>CONVERT_FROM(
          SOURCE      = EW_XRES-RESCONTENT ).
      SEARCH RESULT FOR '<OBJECT_ID>'.
      IF SY-SUBRC = 0.
        LV_B = SY-FDPOS + 11.
        SEARCH RESULT FOR '</OBJECT_ID>'.
        IF SY-SUBRC = 0.
          LV_E = SY-FDPOS.
          LV_L = LV_E - LV_B.
          GW_SHOW-OBJECT_ID = RESULT+LV_B(LV_L).
          GW_SHOW-IXML = RESULT.
        ENDIF.
      ENDIF.
    ENDIF.
    "读取报文对应的返回报文
    READ TABLE GT_DETAIL INTO GW_DETAIL WITH KEY REF_TO_MSG = GW_DETAIL-MSGGUID.
    IF SY-SUBRC = 0.
      DELETE GT_DETAIL WHERE MSGGUID = GW_DETAIL-MSGGUID.
      CLEAR:EX_RES[],EX_XRES[],EX_NS[],WA_CLUR.
      IM_CLUSTKEY-MSGGUID = GW_DETAIL-MSGGUID.
      IM_CLUSTKEY-PID     = GW_DETAIL-PID.
      IM_MANDT = 300.
      MOVE-CORRESPONDING GW_DETAIL TO GW_SHOW.
      "导入各项数据
      IMPORT LT_RES  TO EX_RES LT_XRES TO EX_XRES LT_NS TO EX_NS FROM DATABASE SXMSCLUR(IS) TO WA_CLUR CLIENT IM_MANDT ID IM_CLUSTKEY.
      "读取XML报文
"      *******************定制字段内容***************
      READ TABLE EX_XRES INTO EW_XRES INDEX 1.
      IF SY-SUBRC = 0.
        "XML报文解码
        RESULT = CL_ABAP_CODEPAGE=>CONVERT_FROM(
            SOURCE      = EW_XRES-RESCONTENT ).
        SEARCH RESULT FOR '<MSGTYPE>'.
        IF SY-SUBRC = 0.
          LV_B = SY-FDPOS + 9.
          SEARCH RESULT FOR '</MSGTYPE>'.
          IF SY-SUBRC = 0.
            LV_E = SY-FDPOS.
            LV_L = LV_E - LV_B.
            GW_SHOW-MSGTYPE = RESULT+LV_B(LV_L).
          ENDIF.
        ENDIF.
        SEARCH RESULT FOR '<MSGINFO>'.
        IF SY-SUBRC = 0.
          LV_B = SY-FDPOS + 9.
          SEARCH RESULT FOR '</MSGINFO>'.
          IF SY-SUBRC = 0.
            LV_E = SY-FDPOS.
            LV_L = LV_E - LV_B.
            GW_SHOW-MSGINFO = RESULT+LV_B(LV_L).
          ENDIF.
        ENDIF.
        GW_SHOW-OXML = RESULT.
        APPEND GW_SHOW TO GT_SHOW.
      ENDIF.
"      *******************定制字段内容***************
    ELSE.
      APPEND GW_SHOW TO GT_SHOW.
    ENDIF.
    CLEAR:GW_SHOW.
  ENDLOOP.

  REFRESH GT_FIELDCAT.
  LS_LAYOUT-CWIDTH_OPT    = 'X'. "优化列宽选项是否设置
  LS_LAYOUT-ZEBRA                = 'X'.
*  ls_layout-box_fname        = 'SEL'.
  APPEND_FIELDCAT:'OBJECT_ID'             '单号'              35   'X',
                  'MSGTYPE'             '接口结果'              1000   'X',
                  'MSGINFO'             '返回消息'              1000   'X',
                  'OB_SYSTEM'           '发送系统'              20     'X',
                  'OB_NS'               '发送命名空间'          40     'X',
                  'OB_NAME'             '发送接口名称'          40     'X',
                  'IB_SYSTEM'           '接收系统'              20     'X',
                  'IB_NS'               '接收命名空间'          40     'X',
                  'IB_NAME'             '接收接口名称'          40     'X',
                  'IXML'             '传入XML报文'              1000   'X',
                  'OXML'             '返回XML报文'              1000   'X'.


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-REPID
      I_CALLBACK_PF_STATUS_SET = 'PRM_SET_STATUS'
      I_CALLBACK_USER_COMMAND  = 'PRM_USER_COMMAND'
      IS_LAYOUT_LVC            = LS_LAYOUT
      IT_FIELDCAT_LVC          = GT_FIELDCAT[]
*     I_GRID_TITLE             = LV_TITLE
      I_DEFAULT                = 'X'
      I_SAVE                   = 'A'
    TABLES
      T_OUTTAB                 = GT_SHOW
    EXCEPTIONS
      PROGRAM_ERROR            = 1
      OTHERS                   = 2.
  IF SY-SUBRC <> 0.
  ENDIF.

FORM PRM_SET_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
  SET PF-STATUS 'ZSTAT'.
ENDFORM.
FORM PRM_USER_COMMAND USING P_UCOMM    LIKE SY-UCOMM
                        P_SELFIELD TYPE SLIS_SELFIELD.

  CHECK P_UCOMM = '&IC1'.

  READ TABLE GT_SHOW INTO GW_SHOW INDEX P_SELFIELD-TABINDEX.
  IF SY-SUBRC = 0.
    DATA: LDO_XML TYPE REF TO CL_XML_DOCUMENT.
    DATA: LDF_SUBRC TYPE SYSUBRC.

* 创建XML对象
    LDO_XML = NEW CL_XML_DOCUMENT( ).
    IF P_SELFIELD-FIELDNAME = 'IXML'.
      LDF_SUBRC = LDO_XML->PARSE_STRING( GW_SHOW-IXML ).
    ELSEIF P_SELFIELD-FIELDNAME = 'OXML'.
      LDF_SUBRC = LDO_XML->PARSE_STRING( GW_SHOW-OXML ).
    ELSE.
      CHECK 1 = 2.
    ENDIF.

    IF LDF_SUBRC = 0.
      LDO_XML->DISPLAY( ).
    ELSE.
*      MESSAGE S000 WITH '解析XML失败!' DISPLAY LIKE 'E'.
*      PERFORM FRM_SHOW_STRING USING IM_XML.
    ENDIF.

    CLEAR LDO_XML.
  ENDIF.
ENDFORM.

 转自:https://www.cnblogs.com/sapSB/p/12157681.html

posted @ 2020-05-06 09:04  萧静默  阅读(3153)  评论(0编辑  收藏  举报