Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Author: Ricardo Nobrega da Silva
Submitted: 30/06/2008
Related Links:

This report selects XI/PI messages according to the selection criteria and try to find the NF-e Access Key string in the payload XML.

 Selection Screen:


 
 

  List with XI/PI messages (Hotspot)


  Payload View


Report code:

ZFIND_NFE_SXMB
*&---------------------------------------------------------------------*
*& Report  ZFIND_NFE_SXMB
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zfind_nfe_sxmb.

TYPES: BEGIN OF ts_resource,
        resource TYPE REF TO if_xms_resource,
        name TYPE string,
        ref TYPE string,
        kind TYPE char1,
       END OF ts_resource.

DATA:
 persist     TYPE REF TO cl_xms_persist,
 persist_adm TYPE REF TO cl_xms_persist_adm,
 g_message   TYPE REF TO if_xms_message,
 l_pro_t     TYPE REF TO sxms_pro_t,
 l_manifest  TYPE REF TO cl_xms_msghdr30_manifest,
 l_resource  TYPE REF TO if_xms_resource,
 conv        TYPE REF TO cl_abap_conv_in_ce,
 t_msg       TYPE TABLE OF sxmsmguid WITH HEADER LINE,
 gt_msgtab   TYPE sxmsmsgtab,
 gs_msgtab   TYPE sxmsmsglst,
 l_mf_s      TYPE sxms_mf_s,
 l_mf_t      TYPE sxms_mf_t,
 l_pro_s     TYPE sxms_pro_s,
 gt_verstab  TYPE sxmsvtab,
 g_verstab   TYPE sxmsvlst,
 string_data TYPE string,
 bin_data    TYPE xstring,
 result_tab  TYPE match_result_tab,
 result_wa   TYPE match_result,
 start_time  TYPE sy-uzeit VALUE '000001',
 end_time    TYPE sy-uzeit VALUE '235959',
 v_lin       TYPE i.

FIELD-SYMBOLS:
  <fs1> TYPE sxms_pro_t.

SELECTION-SCREEN BEGIN OF BLOCK bl01.
PARAMETERS:
  nfeid    TYPE c LENGTH 44,
  l_number TYPE i,
  exedate  TYPE sy-datum,
  exe2date TYPE sy-datum.
SELECTION-SCREEN END OF BLOCK bl01.

AT LINE-SELECTION.
  GET CURSOR LINE v_lin.

  SUBTRACT 2 FROM v_lin.

  READ TABLE t_msg INDEX v_lin.
  SUBMIT rsxmb_display_msg_vers_new
  WITH msgguid = t_msg
  AND RETURN.

START-OF-SELECTION.
  CALL FUNCTION 'SXMB_SELECT_MESSAGES'
    EXPORTING
*   IM_SENDDATE                =
*   IM_SENDTIME                =
*   IM_SND2DATE                =
*   IM_SND2TIME                =
   im_exedate                 = exedate
   im_exetime                 = start_time
   im_exe2date                = exe2date
   im_exe2time                = end_time
*   IM_PID                     =
*   IM_PIDS                    =
*   IM_CLIENT                  =
*   IM_USER                    =
*   IM_ADAPTER_TYPE_IN         =
*   IM_ADAPTER_TYPE            =
*   IM_ADAPTER_STATE           =
*   IM_S_SENDER_RECEIVER       =
*   IM_ERRCAT                  =
*   IM_ERRCODE                 =
*   IM_MSGGUID_TAB             =
*   IM_MSGSTATE_TAB            =
*   IM_QUEUEID                 =
*   IM_MSGTYPE                 =
      im_number                  = l_number
*   IM_ADAPTER_OR              = '0'
*   IM_PROCESS_MODE            = '0'
 IMPORTING
   ex_msgtab                  = gt_msgtab
*   EX_RESULT                  =
*   EX_FIRST_TS                =
 EXCEPTIONS
   persist_error              = 1
   missing_parameter          = 2
   negative_time_range        = 3
   too_many_parameters        = 4
   OTHERS                     = 5.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    TRY.
        CREATE OBJECT persist.
        CREATE OBJECT persist_adm.

        LOOP AT gt_msgtab INTO gs_msgtab.

          CALL METHOD persist_adm->read_all_msg_vers_pub
            EXPORTING
              im_msgguid = gs_msgtab-msgguid
*          im_pid     =
           IMPORTING
              ex_verstab = gt_verstab.

          LOOP AT gt_verstab INTO g_verstab.
            CALL METHOD persist->read_msg_pub
              EXPORTING
                im_msgguid      = gs_msgtab-msgguid
                im_pid          = g_verstab-pid
                im_version      = g_verstab-version
                im_client       = g_verstab-client
*            im_read_payload = 'X'
              IMPORTING
                ex_message      = g_message.
*            ex_msgstate     =
*            ex_last_version =


            l_pro_t = g_message->getbodies( ).

            ASSIGN l_pro_t->* TO <fs1>.

            LOOP AT <fs1> INTO l_pro_s.
              string_data = l_pro_s-prop->writetoxmlstring( external = if_xms_main=>co_false ).

              l_manifest ?= l_pro_s-prop.
              l_mf_t = l_manifest->get_payload_refs( ).

              LOOP AT l_mf_t INTO l_mf_s.
                l_resource = g_message->getattachmentbyname( l_mf_s-href ).

                CALL METHOD l_resource->getbinarydata
                  RECEIVING
                    data = bin_data.

                conv = cl_abap_conv_in_ce=>create( input = bin_data ).
                conv->read( IMPORTING data = string_data ).

                FIND FIRST OCCURRENCE OF nfeid IN string_data IN CHARACTER MODE RESULTS result_tab.

                READ TABLE result_tab INTO result_wa INDEX 1.
                IF sy-subrc IS INITIAL.
                  APPEND gs_msgtab-msgguid TO t_msg.
                ENDIF.

              ENDLOOP.
            ENDLOOP.
          ENDLOOP.
        ENDLOOP.

      CATCH cx_xms_syserr_persist.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      CATCH cx_xms_exception cx_xms_system_error.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDTRY.

    SORT t_msg.
    DELETE ADJACENT DUPLICATES FROM t_msg.

    LOOP AT t_msg.
      WRITE / t_msg HOTSPOT.
    ENDLOOP.
  ENDIF.

Contribute

Please, feel free to improve the code.

  • No labels

3 Comments

  1. Guest

    This was very useful. I also added functionality to call transaction sxmb_moni and send the date and message id variables through.

       SUBMIT RSXMB_SELECT_MESSAGES WITH MSGGUID IN SELTAB WITH LINES = L_NUMBER
                                     WITH EXEDATE = EXEDATE WITH EXETIME = START_TM
                                     WITH EXE2DATE = EXE2DATE WITH EXE2TIME = END_TIME
                                     USING SELECTION-SCREEN '1000' AND RETURN.  

  2. Hello,

    Indeed this tool is very useful, nevertheless it is not working to find NFes for 2011, could be related to the new NFe Layout?

    I´m not a ABAP developer, so any help is appreciated.

    Thanks,

    Sigfrid Murillo

  3. Guest

    Hi,

    I've changed the FIND line to ignore case of the string being searched. 

    FIND FIRST OCCURRENCE OF nfeid IN string_data IGNORING CASE IN CHARACTER MODE RESULTS result_tab.