• Inbound IDOC Status Report for Sales Orders



    Requirement:

    Sales Orders are being created through inbound IDocs using FM 'EDI_DATA_INCOMING'. Now a Report is required to check the status of these Inbound IDocs along with Sales Orders generated against customer Purchase Orders.

    Processing:

    The report selects, 'ORDERS' IDoc numbers & status, generated between given time range, from table EDIDC. Further, it calls Function Module 'IDOC_READ_COMPLETELY' to get the IDoc details. Then required information is extracted by reading relevant field data of IDoc segments.

    代码:
    REPORT  Z_EDI_FILE_LOAD_STATUS_REPORT           .
    *-----------------------------------------------------------------------
    * Staus Report for Inbound IDOCs ( Sales Orders )
    *-----------------------------------------------------------------------
    * Program        : Z_EDI_FILE_LOAD_STATUS_REPORT
    * Presented By   : www.rmtiwari.com
    *-----------------------------------------------------------------------
    TABLES : EDIDC.
    *-----------------------------------------------------------------------
    * ALV stuff
    TYPE-POOLS: SLIS.
    DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
          GS_LAYOUT   TYPE SLIS_LAYOUT_ALV,
          GT_SORT     TYPE SLIS_T_SORTINFO_ALV,
          GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

    DATA : BEGIN OF T_REPORT OCCURS 0,
             IDOC_NO       TYPE EDI_DOCNUM,
             IDOC_DATE     TYPE SY-DATUM,
             IDOC_TIME     TYPE SY-UZEIT,
             SORDER_NO     TYPE VBELN,
             STP_NO        TYPE KNA1-KUNNR,
             STP_NAME(35)  TYPE C,
             STP_PHONE(12) TYPE C,
             PO_NO(15)     TYPE C,
             STATUS        TYPE C,
             S_TEXT(70)    TYPE C,
             ERROR(70)     TYPE C,
           END OF T_REPORT.

    *------------------PARAMETER------------------------------------------*

    selection-screen begin of block date with frame title TEXT-S01.
    select-options: UDATE for  EDIDC-UPDDAT
                          default SY-datum obligatory,    "Changed On
                    UTIME for  EDIDC-UPDTIM .             "Changed Time

    selection-screen end   of block date.

    *----------------------------------------------------------------------*
    INITIALIZATION.

    START-OF-SELECTION.
    PERFORM SHOW_STATUS_REPORT.

    *&---------------------------------------------------------------------*
    *&      Form  alv_grid
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->   p1        text
    *  < --  p2        text
    *----------------------------------------------------------------------*
    FORM ALV_GRID.

      IF GT_FIELDCAT[] IS INITIAL.
        PERFORM FIELDCAT_INIT.
        PERFORM LAYOUT_INIT.
        PERFORM SORT_INIT.
      ENDIF.

      PERFORM GRID_DISPLAY.

    ENDFORM.                    "alv_grid
    *&---------------------------------------------------------------------*
    *&      Form  layout_init
    *&---------------------------------------------------------------------*
     
    FORM LAYOUT_INIT.
      GS_LAYOUT-ZEBRA             = 'X'.
      GS_LAYOUT-CELL_MERGE        = 'X'.
      GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
      GS_LAYOUT-NO_VLINE          = ' '.
      GS_LAYOUT-TOTALS_BEFORE_ITEMS = ' '.

    ENDFORM.                    " layout_init
    *&---------------------------------------------------------------------*
    *&      Form  fieldcat_init
    *&---------------------------------------------------------------------*
     
    FORM FIELDCAT_INIT.
      DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

       CLEAR LS_FIELDCAT.
      LS_FIELDCAT-FIELDNAME    = 'IDOC_NO'.
      LS_FIELDCAT-KEY          = 'X'.
      LS_FIELDCAT-REPTEXT_DDIC = 'IDOC'.
      LS_FIELDCAT-OUTPUTLEN    = 10.
    * Fix for ALV print bug, which puts 'N/A' over last digit
    * Set inttype to 'N' to stop corruption of printed ALV cell.
      LS_FIELDCAT-INTTYPE = 'N'.
      APPEND LS_FIELDCAT TO GT_FIELDCAT.

      CLEAR LS_FIELDCAT.
      LS_FIELDCAT-FIELDNAME    = 'IDOC_DATE'.
      LS_FIELDCAT-REPTEXT_DDIC = 'Creation Date'.
      LS_FIELDCAT-OUTPUTLEN    = 10.
      APPEND LS_FIELDCAT TO GT_FIELDCAT.

      CLEAR LS_FIELDCAT.
      LS_FIELDCAT-FIELDNAME    = 'IDOC_TIME'.
      LS_FIELDCAT-REPTEXT_DDIC = 'Creation Time'.
      LS_FIELDCAT-OUTPUTLEN    = 8.
      APPEND LS_FIELDCAT TO GT_FIELDCAT.

      CLEAR LS_FIELDCAT.
      LS_FIELDCAT-FIELDNAME    = 'STATUS'.
      LS_FIELDCAT-REPTEXT_DDIC = 'St'.
      LS_FIELDCAT-OUTPUTLEN    = 2.
      APPEND LS_FIELDCAT TO GT_FIELDCAT.

      CLEAR LS_FIELDCAT.
      LS_FIELDCAT-FIELDNAME    = 'ERROR'.
      LS_FIELDCAT-REPTEXT_DDIC = 'Message'.
      LS_FIELDCAT-OUTPUTLEN    = 70.
      APPEND LS_FIELDCAT TO GT_FIELDCAT.


      CLEAR LS_FIELDCAT.
      LS_FIELDCAT-FIELDNAME    = 'STP_NO'.
      LS_FIELDCAT-REPTEXT_DDIC = 'S.T.Party No'.
      LS_FIELDCAT-OUTPUTLEN    = 10.
      APPEND LS_FIELDCAT TO GT_FIELDCAT.

      CLEAR LS_FIELDCAT.
      LS_FIELDCAT-FIELDNAME    = 'STP_NAME'.
      LS_FIELDCAT-REPTEXT_DDIC = 'Sold to Party Name'.
      LS_FIELDCAT-OUTPUTLEN    = 35.
      APPEND LS_FIELDCAT TO GT_FIELDCAT.


      CLEAR LS_FIELDCAT.
      LS_FIELDCAT-FIELDNAME    = 'PO_NO'.
      LS_FIELDCAT-REPTEXT_DDIC = 'Purch Order'.
      LS_FIELDCAT-OUTPUTLEN    = 15.
      APPEND LS_FIELDCAT TO GT_FIELDCAT.

      CLEAR LS_FIELDCAT.
      LS_FIELDCAT-FIELDNAME    = 'STP_PHONE'.
      LS_FIELDCAT-REPTEXT_DDIC = 'S.T.Party Phone'.
      LS_FIELDCAT-OUTPUTLEN    = 15.
      APPEND LS_FIELDCAT TO GT_FIELDCAT.

    ENDFORM.                    "fieldcat_init

    *&---------------------------------------------------------------------*
    *&      Form  sort_init
    *&---------------------------------------------------------------------*
     
    FORM SORT_INIT.
      DATA: LS_SORT TYPE SLIS_SORTINFO_ALV.
    *
      CLEAR LS_SORT.
      LS_SORT-FIELDNAME = 'IDOC_DATE'.
      LS_SORT-SPOS      = 1.
      LS_SORT-UP        = 'X'.
      APPEND LS_SORT TO GT_SORT.

      CLEAR LS_SORT.
      LS_SORT-FIELDNAME = 'IDOC_TIME'.
      LS_SORT-SPOS      = 2.
      LS_SORT-UP        = 'X'.
      APPEND LS_SORT TO GT_SORT.

      CLEAR LS_SORT.
      LS_SORT-FIELDNAME = 'STATUS'.
      LS_SORT-SPOS      = 3.
      LS_SORT-UP        = 'X'.
      APPEND LS_SORT TO GT_SORT.

      CLEAR LS_SORT.
      LS_SORT-FIELDNAME = 'IDOC_NO'.
      LS_SORT-SPOS      = 4.
      LS_SORT-UP        = 'X'.
      APPEND LS_SORT TO GT_SORT.

    ENDFORM.                    "sort_init
    *&---------------------------------------------------------------------*
    *&      Form  grid_display
    *&---------------------------------------------------------------------*
     
    FORM GRID_DISPLAY.

      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          IS_LAYOUT     = GS_LAYOUT
          IT_FIELDCAT   = GT_FIELDCAT
          IT_SORT       = GT_SORT
          i_callback_program      = SY-REPID
          I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
          I_DEFAULT     = ' '
          I_SAVE        = 'X'
        TABLES
          T_OUTTAB      = T_REPORT
        EXCEPTIONS
          PROGRAM_ERROR = 1
          OTHERS        = 2.

    ENDFORM.                    "grid_display
    *&---------------------------------------------------------------------*
    *&      Form  COMMENT_BUILD
    *&---------------------------------------------------------------------*
    *       Processing of listheader
    *----------------------------------------------------------------------*
    FORM COMMENT_BUILD USING P_FK_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.

      DATA: LS_LINE TYPE SLIS_LISTHEADER.
      REFRESH P_FK_LIST_TOP_OF_PAGE.
    * List Heading : Typ H
      CLEAR LS_LINE.
      LS_LINE-TYP  = 'H'.
      LS_LINE-INFO  = 'Sales Order Interface: Z_EDI_FILE_LOAD'.
      APPEND LS_LINE TO P_FK_LIST_TOP_OF_PAGE.

    * List : Typ S
      clear LS_LINE.
      LS_LINE-typ  = 'S'.
      LS_LINE-key  = 'Date Range:'.
      LS_LINE-info  = UDATE-low.
      if not UDATE-high is initial.
        write ' To ' to  LS_LINE-info+30.
        LS_LINE-info+36 = UDATE-high.
      endif.


      APPEND LS_LINE TO P_FK_LIST_TOP_OF_PAGE.

    ENDFORM.                               " COMMENT_BUILD

    *---------------------------------------------------------------------*
    *       FORM TOP_OF_PAGE                                              *
    *---------------------------------------------------------------------*
    *       Ereigniss TOP_OF_PAGE                                       *
    *       event     TOP_OF_PAGE
    *---------------------------------------------------------------------*
    FORM TOP_OF_PAGE.

      PERFORM COMMENT_BUILD  USING gt_LIST_TOP_OF_PAGE[].
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.

    ENDFORM.                    "TOP_OF_PAGE

    *&---------------------------------------------------------------------*
    *&      Form  show_status_report
    *&---------------------------------------------------------------------*
     
    FORM SHOW_STATUS_REPORT .
    * Report to show status.

      DATA: BEGIN OF T_TEDS2 OCCURS 0.
              INCLUDE STRUCTURE TEDS2.
      DATA: END OF T_TEDS2.

      DATA: BEGIN OF T_IDOC_CONTROL_TMP OCCURS 0.
              INCLUDE STRUCTURE EDIDC.
      DATA: END OF T_IDOC_CONTROL_TMP.

      CONSTANTS: C_STATUS_IN_IDOC_POSTED       LIKE EDIDC-STATUS VALUE '53'.

      DATA : T_EDIDS TYPE STANDARD TABLE OF EDIDS WITH HEADER LINE.
      DATA : T_EDIDD TYPE STANDARD TABLE OF EDIDD WITH HEADER LINE.

      DATA : GV_PARTNER_SEG TYPE E1EDKA1,
             GV_PO_REF_SEG  TYPE E2EDK02.


    * Get text for status values
      SELECT * FROM TEDS2 INTO TABLE T_TEDS2 WHERE LANGUA = SY-LANGU.

    * Read the IDoc's status after processing
      SELECT * FROM EDIDC
        INTO TABLE T_IDOC_CONTROL_TMP
       WHERE UPDDAT IN UDATE
         AND UPDTIM IN UTIME
         AND MESTYP = 'ORDERS'.

      LOOP AT T_IDOC_CONTROL_TMP.

    *   IDoc has been processed, since control record changed.
        READ TABLE T_TEDS2 WITH KEY STATUS = T_IDOC_CONTROL_TMP-STATUS.
        T_REPORT-IDOC_NO = T_IDOC_CONTROL_TMP-DOCNUM.
        T_REPORT-IDOC_DATE = T_IDOC_CONTROL_TMP-CREDAT.
        T_REPORT-IDOC_TIME = T_IDOC_CONTROL_TMP-CRETIM.
        T_REPORT-S_TEXT = T_TEDS2-DESCRP.
        IF T_IDOC_CONTROL_TMP-STATUS = C_STATUS_IN_IDOC_POSTED.
    *     ok status
          T_REPORT-STATUS = 'S'.
        ELSE.
    *     error status
          T_REPORT-STATUS = 'E'.
        ENDIF.

    *     Get IDoc details.

        CALL FUNCTION 'IDOC_READ_COMPLETELY'
          EXPORTING
            DOCUMENT_NUMBER         = T_REPORT-IDOC_NO
          TABLES
            INT_EDIDS               = T_EDIDS
            INT_EDIDD               = T_EDIDD
          EXCEPTIONS
            DOCUMENT_NOT_EXIST      = 1
            DOCUMENT_NUMBER_INVALID = 2
            OTHERS                  = 3.

    *   Get Error status
        READ TABLE T_EDIDS WITH KEY STATUS = T_IDOC_CONTROL_TMP-STATUS.
        IF SY-SUBRC EQ 0.
          REPLACE FIRST OCCURRENCE OF '&1' IN T_EDIDS-STATXT
                                WITH T_EDIDS-STAPA1.
          REPLACE FIRST OCCURRENCE OF '&2' IN T_EDIDS-STATXT
                                WITH T_EDIDS-STAPA2.
          REPLACE FIRST OCCURRENCE OF '&3' IN T_EDIDS-STATXT
                                WITH T_EDIDS-STAPA3.
          REPLACE FIRST OCCURRENCE OF '&4' IN T_EDIDS-STATXT
                                WITH T_EDIDS-STAPA4.

          REPLACE FIRST OCCURRENCE OF '&' IN T_EDIDS-STATXT
                                WITH T_EDIDS-STAPA1.
          REPLACE FIRST OCCURRENCE OF '&' IN T_EDIDS-STATXT
                                WITH T_EDIDS-STAPA2.
          REPLACE FIRST OCCURRENCE OF '&' IN T_EDIDS-STATXT
                                WITH T_EDIDS-STAPA3.
          REPLACE FIRST OCCURRENCE OF '&' IN T_EDIDS-STATXT
                                WITH T_EDIDS-STAPA4.


          T_REPORT-ERROR = T_EDIDS-STATXT.
        ENDIF.
        LOOP AT T_EDIDD.

          CASE T_EDIDD-SEGNAM.

            WHEN 'E1EDKA1'.
              GV_PARTNER_SEG = T_EDIDD-SDATA.

              CLEAR : T_REPORT-STP_NAME.

              CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                EXPORTING
                  INPUT  = GV_PARTNER_SEG-PARTN
                IMPORTING
                  OUTPUT = T_REPORT-STP_NO.

              SELECT SINGLE NAME1 TELF1
                INTO (T_REPORT-STP_NAME,T_REPORT-STP_PHONE)
                FROM KNA1
               WHERE KUNNR = T_REPORT-STP_NO.

            WHEN 'E1EDK02'.
              GV_PO_REF_SEG = T_EDIDD-SDATA.
              T_REPORT-PO_NO = GV_PO_REF_SEG-BELNR.
          ENDCASE.

        ENDLOOP.

        APPEND T_REPORT.
      ENDLOOP .

      SORT T_REPORT BY STATUS IDOC_NO.

    * Show Report
      PERFORM ALV_GRID.

    ENDFORM.                    " show_status_report

  • 相关阅读:
    4815 江哥的dp题a
    CON1023 明明的计划
    5200 fqy的难题----2的疯狂幂
    [SCOI2005] 最大子矩阵
    1457 又是求和?
    2064 最小平方数
    vijos P1459车展
    1366 xth 的第 12 枚硬币
    1360 xth 的玫瑰花
    3223: Tyvj 1729 文艺平衡树
  • 原文地址:https://www.cnblogs.com/xiaomaohai/p/6157489.html
Copyright © 2020-2023  润新知