SAP ABAP PO 根据关键词找消息ID

@根据关键词查PO消息ID

背景
查问题时要根据关键词定位PO消息ID,而用SXI_MONITOR直接查不方便,尤其是数据多的时候。所以写了段小程序,根据关键词和查询条件直接定位,省点事~。

选择屏幕
在这里插入图片描述
条件可以根据需要自行添加。

查找结果

在这里插入图片描述

源码

REPORT zfind_keyword_in_payload.

TABLES:
  sxmspmast.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (33) t1 FOR FIELD begda.
PARAMETERS: begda TYPE sy-datum DEFAULT sy-datum.
SELECTION-SCREEN COMMENT 48(2) t2 FOR FIELD begti.
PARAMETERS: begti TYPE sy-uzeit.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (33) t3 FOR FIELD endda.
PARAMETERS: endda TYPE sy-datum DEFAULT sy-datum.
SELECTION-SCREEN COMMENT 48(2) t4 FOR FIELD endti.
PARAMETERS: endti TYPE sy-uzeit DEFAULT '235959'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP.

PARAMETERS key_word TYPE c LENGTH 100.

SELECT-OPTIONS stamp FOR sxmspmast-inittimest NO-DISPLAY.

INITIALIZATION.

  t1 = `起始日期/时间`.
  t2 = `/`.
  t3 = `截止日期/时间`.
  t4 = `/`.

START-OF-SELECTION.

  PERFORM process_data.

*&---------------------------------------------------------------------*
*&      Form  PROCESS_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM process_data .

  DATA ls_messagekey      TYPE sxmsmkey.
  DATA lv_payload_size    TYPE sxms_payload_size.
  DATA lv_version_type     TYPE sxms_versiontype.
  DATA lv_version_request TYPE sxmslsqnbr.
  DATA lt_messagepayload  TYPE sxms_messagepayload_tab.

  DATA xpl       TYPE xstring.
  DATA xml       TYPE string.
  DATA lv_length TYPE i.
  DATA lt_cntbin TYPE sdokcntbins.

  CONVERT DATE begda TIME begti INTO TIME STAMP DATA(low) TIME ZONE sy-zonlo.
  CONVERT DATE endda TIME endti INTO TIME STAMP DATA(high) TIME ZONE sy-zonlo.

  stamp[] = VALUE #( ( sign = `I` option = `BT` low = low high = high ) ).

  SELECT *
    INTO TABLE @DATA(lt_sxmspmast)
    FROM sxmspmast
   WHERE inittimest IN @stamp[].


  LOOP AT lt_sxmspmast INTO DATA(ls_sxmspmast).

    CLEAR ls_messagekey.
    ls_messagekey-msgid = ls_sxmspmast-msgguid.
    ls_messagekey-pid   = ls_sxmspmast-pid.
    lv_payload_size     = ls_sxmspmast-msg_size .

    CLEAR lt_messagepayload[].
    CALL FUNCTION 'SXMB_READ_MESSAGE_VERSION_RAW'
      EXPORTING
        selection        = 1
        messagekey       = ls_messagekey
        version_request  = lv_version_request
        versiontype      = lv_version_type
        max_payload_size = lv_payload_size
      IMPORTING
        messagepayload   = lt_messagepayload.

    CHECK lt_messagepayload[] IS NOT INITIAL.

    xpl = lt_messagepayload[ 1 ]-payload.

    CLEAR lt_cntbin.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer        = xpl
      IMPORTING
        output_length = lv_length
      TABLES
        binary_tab    = lt_cntbin.

    CALL FUNCTION 'SCMS_BINARY_TO_STRING'
      EXPORTING
        input_length = lv_length
      IMPORTING
        text_buffer  = xml
      TABLES
        binary_tab   = lt_cntbin.

    IF xml CS key_word.
      WRITE: / ls_sxmspmast-msgguid.
    ENDIF.

  ENDLOOP.

ENDFORM.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值