SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Report IDOCs in Error



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | Интерфейсы
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Tue Sep 04, 2007 4:59 pm    Post subject: Report IDOCs in Error Reply with quote

Applies To:
SAP 4.6 C and SAP 4.7 Enterprise Edition

Summary
This report displays all the error IDOCs for both INBOUND and OUTBOUND based on message type, it also
having a provision to drill down the number of errorsand error type for each message type and also display
the current week as well as pervious 5 weeks of IDOCS. Provides a option to drill down for each message
type, error message to find the root cause of the error
By: Suresh S Revuru
Company: INTELLIGROUP INC.,
Date: 09 March 2006

Code Sample Description
Instead of using WE05 Transaction to list the IDOCS, we can use this report to display all the error records,
Error descriptions.
Normally we will goto WE05 and find the error record and double click the record to see the exact error
message. It is very difficult to see each and every error IDOC . Lets think how it difficult to do it for a week.
So this simple report extract all the error IDOCS for current week and also shows the past 5 weeks error
IDOCS.

Code:
REPORT ZIDOC_error_message MESSAGE-ID ID.
*---------------------------------------------------------------------*
* AUTHOR          : SURESH REVURU                                     *
*---------------------------------------------------------------------*
*Include Icons
INCLUDE <ICON>.

*Type pools for ALV data types
TYPE-POOLS: SLIS.

***********************************************************************
*Declaration for Tables
***********************************************************************
TABLES:EDIDC,                                          "Control record (IDoc)
         EDIDS,                                         "Status Record (IDOC)
         TEDS1,

         TEDS2,
         STACUST,
         STALIGHT,
         ZIDOC,
         FRUN.                                          "To store the execution date .

***********************************************************************
*-Declaration of Internal Tables

***********************************************************************

DATA:BEGIN OF IT_STATUS OCCURS 0,
         STATUS LIKE STACUST-STATUS,
         COUNT TYPE I,
       END OF IT_STATUS.

DATA: BEGIN OF IT_DOCNUM OCCURS 0,
            STATUS LIKE EDIDC-STATUS,
          MESTYP LIKE EDIDC-MESTYP,
          DOCNUM LIKE EDIDC-DOCNUM,
        END OF IT_DOCNUM.

DATA:BEGIN OF IT_COUNT OCCURS 0,
         STATUS LIKE STACUST-STATUS,
         COUNT LIKE SY-TABIX,
       END OF IT_COUNT.
* Internal table for displaying the output.
DATA:BEGIN OF IT_OUTPUT OCCURS 0,
         CHK,                                           " Field for checkbox

         BASEWEEK LIKE SY-DATUM,
         ERROR LIKE EDIDC-STATUS,
         IDOC LIKE EDIDC-DOCNUM,
         MESSAGE LIKE EDIDC-MESTYP,
         WK1 LIKE EDIDC-MAXSEGNUM,
         WK2 LIKE EDIDC-MAXSEGNUM,
         WK3 LIKE EDIDC-MAXSEGNUM,
         WK4 LIKE EDIDC-MAXSEGNUM,

         WK5 LIKE EDIDC-MAXSEGNUM,
       END OF IT_OUTPUT.

DATA: BEGIN OF IT_IDOCMESS OCCURS 0,
            SNO TYPE I,
            BASEWEEK LIKE SY-DATUM,
          MESSAGE LIKE EDIDC-MESTYP,

            ERROR LIKE EDIDC-STATUS,
          TEXT LIKE BDIDOCATTR-MESSAGE,
          NO_OF_ERR LIKE ZIPOPUP-NO_OF_ERR,
          WEEK LIKE ZIPOPUP-WEEK,
          WK1 LIKE EDIDC-MAXSEGNUM,
          WK2 LIKE EDIDC-MAXSEGNUM,
          WK3 LIKE EDIDC-MAXSEGNUM,
          WK4 LIKE EDIDC-MAXSEGNUM,
          WK5 LIKE EDIDC-MAXSEGNUM,
        END OF IT_IDOCMESS.
* Internal tables to store detailed errors of the idocs
DATA: IT_IDOCMESS1 LIKE ZIPOPUP OCCURS 0 WITH HEADER LINE.

DATA: IT_IDOCMESS2 LIKE IT_IDOCMESS OCCURS 0 WITH HEADER LINE,
        IT_IDOCMESS2_TEMP LIKE IT_IDOCMESS OCCURS 0 WITH HEADER LINE.

* Internal table to hold all the baseweeks
DATA:BEGIN OF IT_DATE OCCURS 0,
         LOW LIKE SY-DATUM,
         HIGH LIKE SY-DATUM,
END OF IT_DATE.

* Declaration of Variables

DATA: NO_OF_ERR LIKE SY-TABIX.
DATA: V_FLAG LIKE SY-TABIX,
        F_FLAG TYPE I.

* Fieldcatalog for IT_OUTPUT
DATA: IT_FIELDCAT_DATA TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
* Events in ALV
        IT_EVENTS_DATA TYPE SLIS_T_EVENT WITH HEADER LINE,
* Sorting
        IT_SORT_DATA TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE,
        IT_ZIDOC LIKE ZIDOC OCCURS 0 WITH HEADER LINE,
* Storing properties for fields displayed in Popup.
        IT_FIELDCAT_POPUP TYPE SLIS_T_FIELDCAT_ALV,
        X_FIEDLCAT TYPE SLIS_FIELDCAT_ALV.

*******************************************************************

*- Declaration for Variables
*******************************************************************
DATA:    V_TABIX LIKE SY-TABIX, " For internal table index
             V_REPID LIKE SY-REPID ,
             V_COUNT TYPE I,
             V_FLAG1 TYPE I,
             V_SNO TYPE I,
             V_MESSAGE TYPE BDIDOCATTR-MESSAGE,"EDIDC-MESTYP,

             V_ERROR TYPE EDIDC-STATUS,
             V_DOCNUM LIKE EDIDC-DOCNUM,
             X_LAYOUT_DATA       TYPE SLIS_LAYOUT_ALV, " Layout for data
             X_EVENTS_DATA       TYPE SLIS_ALV_EVENT.  "  " For events.
*******************************************************************
*- Declaration for Constants
*******************************************************************

************************************************************************
* SELECTION-SCREEN
************************************************************************
*Selection Screen for data extraction using order create date and
*order change date.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: P_DATE LIKE EDIDC-CREDAT OBLIGATORY.
*SELECT-OPTIONS: P_DATE FOR EDIDC-CREDAT OBLIGATORY NO-EXTENSION.

SELECTION-SCREEN END OF BLOCK B1.

****************************************************************

*_ Initialization
****************************************************************
V_REPID = SY-REPID.

AT SELECTION-SCREEN.

PERFORM DATE_EXTRACTION.

****************************************************************
* Start of Selection
****************************************************************
START-OF-SELECTION.

**Logic to avoid the users action.
*CLEAR V_SNO.

*  SELECT COUNT(*) FROM ZIDOC
*                           INTO V_SNO
*                           WHERE BASEWEEK = S_DATE-LOW OR BASEWEEK = S_DATE-HIGH
.
*  IF SY-SUBRC = 0.
*  MESSAGE E001.
*  ENDIF.
*frun table this will be usefull in selection variant for scheduling the
* batch jobs for delta runs.
  PERFORM UPDATE_LAST_RUN_TIME.
*This subroutine extracts the date from the given dates and stores in
* internal table it_date.
*  PERFORM DATE_EXTRACTION.

*This subroutine extracts the data from EDIDIC table.
  PERFORM GET_DATA_BASIC_LIST.
* This subroutine extracts the detail data from EDIDS table.
  PERFORM GET_DATA_DETAIL_LIST.
* This subroutines gets the previous 4 weeks of data for comparison.
  PERFORM PREVIOUS_WEEK.

  SORT IT_OUTPUT BY BASEWEEK.

  DELETE ADJACENT DUPLICATES FROM IT_OUTPUT COMPARING BASEWEEK
                                                       MESSAGE
                                                       ERROR.

*This subroutine displays the it_output internal table in screen
  PERFORM DISPLAY_DATA.

****************************************************************
* End of Selection
****************************************************************
END-OF-SELECTION.
* Top of list
FORM TOP-OF-LIST.

  FORMAT COLOR COL_HEADING INTENSIFIED ON.

* Display Steelcase header
  CALL FUNCTION 'Z_STEELCASE_HEADER'.
  FORMAT COLOR OFF.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  PF_STATUS_SET
*&---------------------------------------------------------------------*

*       text: This subroutine sets the pf-status
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM PF_STATUS_SET USING    P_EXTAB TYPE SLIS_T_EXTAB.
  SET PF-STATUS 'STANDARD'.

ENDFORM.                                 " PF_STATUS_SET

*&---------------------------------------------------------------------*
*&      Form  DATE_EXTRACTION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DATE_EXTRACTION.
DATA: IT_DATES LIKE ZWKDATES OCCURS 0 WITH HEADER LINE.

DATA: V_DATESTART LIKE SY-DATUM.
DATA: CURRBASEWEEK LIKE SY-DATUM.
DATA: NEXBASEWEEK LIKE SY-DATUM.
*DATA: V_DATE LIKE SY-DATUM.
*CLEAR V_DATE.
*V_DATE = P_DATE.
CALL FUNCTION 'Z_GET_WEEK_DATES'
       EXPORTING

              DATE             = P_DATE
             NUMWEEKS   = '000'
             DIRECT     = '-'
       TABLES
              DATES           = IT_DATES
*    EXCEPTIONS
*             CALC_ERROR = 1

*             INC_DIRECT = 2
*             OTHERS     = 3
              .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CLEAR V_DATESTART.
LOOP AT IT_DATES.

V_DATESTART = IT_DATES-WKSTART.

ENDLOOP.

CLEAR CURRBASEWEEK.
CLEAR NEXBASEWEEK.

IT_DATE-HIGH = V_DATESTART - 2.
IT_DATE-LOW = IT_DATE-HIGH - 6.
CURRBASEWEEK = IT_DATE-HIGH + 1.
NEXBASEWEEK = CURRBASEWEEK + 7.

SELECT SINGLE BASEWEEK FROM ZIDOC
                      INTO CURRBASEWEEK
                      WHERE BASEWEEK = NEXBASEWEEK.
IF SY-SUBRC = 0.
  MESSAGE E002.

ENDIF.

*  IT_DATE-LOW = S_DATE-LOW.
*  IT_DATE-HIGH = S_DATE-HIGH.
  F_FLAG = 1.
  WHILE F_FLAG < 6.
    APPEND IT_DATE.
    F_FLAG = F_FLAG + 1.
      IT_DATE-LOW  = IT_DATE-LOW - 7.
      IT_DATE-HIGH = IT_DATE-HIGH - 7.
  ENDWHILE.
ENDFORM.                                 " DATE_EXTRACTION

*&---------------------------------------------------------------------*

*&      Form  GET_DATA_BASIC_LIST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_DATA_BASIC_LIST.

  DATA: IT_ZIDOC LIKE ZIDOC OCCURS 0 WITHHEADER LINE.
  REFRESH IT_ZIDOC.

  SELECT STACUST~STATUS
             INTO TABLE IT_STATUS
             FROM STACUST

             JOIN STALIGHT
               ON STACUST~STATVA = STALIGHT~STATVA
               WHERE STALIGHT~STALIGHT = '03'.
  IF SY-SUBRC = 0.
* To extract idocs for all the 5 weeks
    LOOP AT IT_DATE.
        SELECT STATUS COUNT(*)
                  FROM EDIDC


                  INTO TABLE IT_COUNT
                  WHERE CREDAT BETWEEN IT_DATE-LOW AND IT_DATE-HIGH
                  GROUP BY STATUS.
    ENDLOOP.
      IF SY-SUBRC EQ 0.

        SORT IT_STATUS.
        SORT IT_COUNT.

        LOOP AT IT_COUNT.
            V_TABIX = SY-TABIX.
          READ TABLE IT_STATUS WITH KEY STATUS = IT_COUNT-STATUS.
            IF SY-SUBRC <> 0.
              DELETE IT_COUNT INDEX V_TABIX.

              CLEAR IT_COUNT.
            ENDIF.
        ENDLOOP.
        CLEAR V_TABIX.
    ENDIF.
  ENDIF.

******************FILLING THE IT_OUTPUT TABLE WITH THE REQUIRED DATA

  REFRESH IT_OUTPUT.
  SELECT COUNT(*) INTO V_SNO FROM ZIDOC WHERE SNO > 0.

  LOOP AT IT_COUNT.


      IF IT_COUNT-COUNT > 20.
        CLEAR V_FLAG1.
        LOOP AT IT_DATE.
            V_FLAG1 = V_FLAG1 + 1.

            SELECT MESTYP COUNT( * )
                     FROM EDIDC
                     INTO (IT_OUTPUT-MESSAGE, NO_OF_ERR)
                     WHERE STATUS = IT_COUNT-STATUS
                     AND CREDAT BETWEEN IT_DATE-LOW AND IT_DATE-HIGH
                     GROUP BY MESTYP.

              IT_OUTPUT-BASEWEEK = IT_DATE-HIGH + 1.

              IT_OUTPUT-ERROR = IT_COUNT-STATUS.

*This subroutine find out the previous erros for the perticular week
*       PERFORM PREVIOUS_WEEK USING IT_OUTPUT-BASEWEEK IT_OUTPUT-MESSAGE
*                                                             IT_OUTPUT-ERROR.
*
              CASE V_FLAG1.

                 WHEN 1.
                    IT_OUTPUT-WK1 = NO_OF_ERR.
                   MOVE IT_OUTPUT-WK1 TO ZIDOC-NO_OF_ERR.
                   MOVE 'WK1' TO ZIDOC-WEEK.
                    IT_OUTPUT-WK2 = ''.
                    IT_OUTPUT-WK3 = ''.
                    IT_OUTPUT-WK4 = ''.
                    IT_OUTPUT-WK5 = ''.


                 WHEN 2.
                    IT_OUTPUT-WK2 = NO_OF_ERR.
                   MOVE IT_OUTPUT-WK2 TO ZIDOC-NO_OF_ERR.
                   MOVE 'WK2' TO ZIDOC-WEEK.

                    IT_OUTPUT-WK1 = ''.
                    IT_OUTPUT-WK3 = ''.
                    IT_OUTPUT-WK4 = ''.
                    IT_OUTPUT-WK5 = ''.

                 WHEN 3.
                    IT_OUTPUT-WK3 = NO_OF_ERR.
                   MOVE IT_OUTPUT-WK3 TO ZIDOC-NO_OF_ERR.

                   MOVE 'WK3' TO ZIDOC-WEEK.
                    IT_OUTPUT-WK2 = ''.
                    IT_OUTPUT-WK1 = ''.
                    IT_OUTPUT-WK4 = ''.
                    IT_OUTPUT-WK5 = ''.

                 WHEN 4.

                    IT_OUTPUT-WK4 = NO_OF_ERR.
                   MOVE IT_OUTPUT-WK4 TO ZIDOC-NO_OF_ERR.
                   MOVE 'WK4' TO ZIDOC-WEEK.
                    IT_OUTPUT-WK2 = ''.
                    IT_OUTPUT-WK3 = ''.
                    IT_OUTPUT-WK1 = ''.
                    IT_OUTPUT-WK5 = ''.


                 WHEN 5.
                    IT_OUTPUT-WK5 = NO_OF_ERR.
                   MOVE IT_OUTPUT-WK5 TO ZIDOC-NO_OF_ERR.
                   MOVE 'WK5' TO ZIDOC-WEEK.
                    IT_OUTPUT-WK2 = ''.

                    IT_OUTPUT-WK3 = ''.
                    IT_OUTPUT-WK4 = ''.
                    IT_OUTPUT-WK1 = ''.
              ENDCASE.

              IF NO_OF_ERR > 20.
                 APPEND IT_OUTPUT.
                 CLEAR IT_OUTPUT.

              ENDIF.
            ENDSELECT.

        ENDLOOP.
        CLEAR NO_OF_ERR.
        CLEAR V_FLAG1.
    ENDIF.

  ENDLOOP.

  SORT IT_OUTPUT BY BASEWEEK.
  PERFORM UPDATE_DATABASE_TABLES.

ENDFORM.                                 " GET_DATA

*&---------------------------------------------------------------------*


*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text: This subroutine displays the data in screen
*----------------------------------------------------------------------*
*  -->  p1        text

*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_DATA.

*Build fieldcatalog internal table
  PERFORM BUILD_DATA_TABLE_CATALOG.
*Displays the Alv Grid
  PERFORM DISPLAY_ALV_OUTPUT.

ENDFORM.                                 " DISPLAY_DATA

*&---------------------------------------------------------------------*
*&      Form  BUILD_DATA_TABLE_CATALOG
*&---------------------------------------------------------------------*
*       text: This forms builds the fieldcatalog

*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM BUILD_DATA_TABLE_CATALOG.
  DATA: L_POS(2) TYPE N VALUE 1.
  REFRESH IT_FIELDCAT_DATA.
  CLEAR IT_FIELDCAT_DATA.


  IT_FIELDCAT_DATA-FIELDNAME         = 'BASEWEEK'.
  IT_FIELDCAT_DATA-TABNAME                            = 'IT_OUTPUT'.
  IT_FIELDCAT_DATA-COL_POS           = L_POS.
  IT_FIELDCAT_DATA-SELTEXT_M                        = 'BASE WEEK'(001).

  IT_FIELDCAT_DATA-DDICTXT          = 'M'.
  IT_FIELDCAT_DATA-OUTPUTLEN         = 10.
  IT_FIELDCAT_DATA-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_DATA-EMPHASIZE                          = 'C700'.
* IT_FIELDCAT_DATA-HOTSPOT           = 'X'.
  IT_FIELDCAT_DATA-NO_ZERO           = 'X'.
  APPEND IT_FIELDCAT_DATA.
  CLEAR  IT_FIELDCAT_DATA.

  L_POS                                               = L_POS + 1.

  IT_FIELDCAT_DATA-FIELDNAME         = 'MESSAGE'.
  IT_FIELDCAT_DATA-TABNAME                            = 'IT_OUTPUT'.
  IT_FIELDCAT_DATA-COL_POS           = L_POS.
  IT_FIELDCAT_DATA-SELTEXT_M         = 'MESSAGE'(002).
  IT_FIELDCAT_DATA-DDICTXT          = 'M'.

  IT_FIELDCAT_DATA-OUTPUTLEN         = 10.
  IT_FIELDCAT_DATA-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_DATA-EMPHASIZE                          = 'C700'.
  IT_FIELDCAT_DATA-NO_ZERO           = 'X'.
  APPEND IT_FIELDCAT_DATA.
  CLEAR  IT_FIELDCAT_DATA.
  L_POS                                               = L_POS + 1.


  IT_FIELDCAT_DATA-FIELDNAME         = 'ERROR'.
  IT_FIELDCAT_DATA-TABNAME                            = 'IT_OUTPUT'.
  IT_FIELDCAT_DATA-COL_POS           = L_POS.
  IT_FIELDCAT_DATA-SELTEXT_M                        = 'ERROR'(003).

  IT_FIELDCAT_DATA-DDICTXT          = 'M'.
  IT_FIELDCAT_DATA-OUTPUTLEN         = 10.
  IT_FIELDCAT_DATA-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_DATA-EMPHASIZE                          = 'C700'.
  IT_FIELDCAT_DATA-NO_ZERO           = 'X'.
  APPEND IT_FIELDCAT_DATA.
  CLEAR  IT_FIELDCAT_DATA.
  L_POS                                               = L_POS + 1.

  IT_FIELDCAT_DATA-FIELDNAME         = 'WK1'.
  IT_FIELDCAT_DATA-TABNAME                            = 'IT_OUTPUT'.
  IT_FIELDCAT_DATA-COL_POS           = L_POS.
  IT_FIELDCAT_DATA-SELTEXT_M                       = 'WEEK1 ERROS'(004).
  IT_FIELDCAT_DATA-DDICTXT          = 'M'.
  IT_FIELDCAT_DATA-OUTPUTLEN         = 10.

  IT_FIELDCAT_DATA-EMPHASIZE                          = 'C600'.
  IT_FIELDCAT_DATA-DATATYPE                            = 'INT4'.
  IT_FIELDCAT_DATA-INTTYPE                             = 'I'.
  IT_FIELDCAT_DATA-INTLEN                              = '8'.
  IT_FIELDCAT_DATA-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_DATA-NO_ZERO           = 'X'.
  IT_FIELDCAT_DATA-DO_SUM            = 'X'.
  APPEND IT_FIELDCAT_DATA.


  CLEAR  IT_FIELDCAT_DATA.
  L_POS                                               = L_POS + 1.

  IT_FIELDCAT_DATA-FIELDNAME           = 'WK2'.
  IT_FIELDCAT_DATA-TABNAME                            = 'IT_OUTPUT'.

  IT_FIELDCAT_DATA-COL_POS           = L_POS.
  IT_FIELDCAT_DATA-SELTEXT_M                       = 'WEEK2 ERROS'(004).
  IT_FIELDCAT_DATA-DDICTXT          = 'M'.
  IT_FIELDCAT_DATA-OUTPUTLEN         = 10.
  IT_FIELDCAT_DATA-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_DATA-EMPHASIZE                          = 'C600'.
  IT_FIELDCAT_DATA-DATATYPE                            = 'INT4'.
  IT_FIELDCAT_DATA-INTTYPE                             = 'I'.

  IT_FIELDCAT_DATA-INTLEN                              = '8'.
  IT_FIELDCAT_DATA-NO_ZERO           = 'X'.
  IT_FIELDCAT_DATA-DO_SUM                                  = 'X'.
  APPEND IT_FIELDCAT_DATA.
  CLEAR  IT_FIELDCAT_DATA.
  L_POS                                               = L_POS + 1.

  IT_FIELDCAT_DATA-FIELDNAME         = 'WK3'.
  IT_FIELDCAT_DATA-TABNAME                            = 'IT_OUTPUT'.
  IT_FIELDCAT_DATA-COL_POS           = L_POS.
  IT_FIELDCAT_DATA-SELTEXT_M                       = 'WEEK3 ERROS'(005).
  IT_FIELDCAT_DATA-DDICTXT          = 'M'.
  IT_FIELDCAT_DATA-OUTPUTLEN         = 10.
  IT_FIELDCAT_DATA-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_DATA-EMPHASIZE                          = 'C600'.


  IT_FIELDCAT_DATA-DATATYPE                            = 'INT4'.
  IT_FIELDCAT_DATA-INTTYPE                             = 'I'.
  IT_FIELDCAT_DATA-INTLEN                              = '8'.
  IT_FIELDCAT_DATA-NO_ZERO           = 'X'.
  IT_FIELDCAT_DATA-DO_SUM                                  = 'X'.

  APPEND IT_FIELDCAT_DATA.
  CLEAR  IT_FIELDCAT_DATA.
  L_POS                                               = L_POS + 1.

  IT_FIELDCAT_DATA-FIELDNAME         = 'WK4'.
  IT_FIELDCAT_DATA-TABNAME                            = 'IT_OUTPUT'.
  IT_FIELDCAT_DATA-COL_POS           = L_POS.
  IT_FIELDCAT_DATA-SELTEXT_M                          = 'WEEK4 ERRORS'(006).

  IT_FIELDCAT_DATA-DDICTXT          = 'M'.
  IT_FIELDCAT_DATA-OUTPUTLEN         = 10.
  IT_FIELDCAT_DATA-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_DATA-EMPHASIZE                          = 'C600'.
  IT_FIELDCAT_DATA-DATATYPE                            = 'INT4'.
  IT_FIELDCAT_DATA-INTTYPE                             = 'I'.
  IT_FIELDCAT_DATA-INTLEN                              = '8'.

  IT_FIELDCAT_DATA-NO_ZERO           = 'X'.
  IT_FIELDCAT_DATA-DO_SUM                                  = 'X'.
  APPEND IT_FIELDCAT_DATA.
  CLEAR  IT_FIELDCAT_DATA.
  L_POS                                               = L_POS + 1.

  IT_FIELDCAT_DATA-FIELDNAME         = 'WK5'.
  IT_FIELDCAT_DATA-TABNAME                            = 'IT_OUTPUT'.


  IT_FIELDCAT_DATA-COL_POS           = L_POS.
  IT_FIELDCAT_DATA-SELTEXT_M                       = 'WEEK5 ERROS'(005).
  IT_FIELDCAT_DATA-DDICTXT          = 'M'.
  IT_FIELDCAT_DATA-OUTPUTLEN         = 10.
  IT_FIELDCAT_DATA-FIX_COLUMN        = 'X'.

  IT_FIELDCAT_DATA-EMPHASIZE                          = 'C600'.
  IT_FIELDCAT_DATA-DATATYPE                            = 'INT4'.
  IT_FIELDCAT_DATA-INTTYPE                             = 'I'.
  IT_FIELDCAT_DATA-INTLEN                              = '8'.
  IT_FIELDCAT_DATA-NO_ZERO           = 'X'.
  IT_FIELDCAT_DATA-DO_SUM            = 'X'.
  APPEND IT_FIELDCAT_DATA.
  CLEAR  IT_FIELDCAT_DATA.

  L_POS                                               = L_POS + 1.

ENDFORM.                                 " BUILD_DATA_TABLE_CATALOG

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_OUTPUT
*&---------------------------------------------------------------------*

*       text This form displays the ALV grid
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY_ALV_OUTPUT.

  DATA: L_USER_FORMNAME   TYPE SLIS_FORMNAME VALUE 'USER_COMMAND',


          L_PF_STAT_FORNAME TYPE SLIS_FORMNAME VALUE 'PF_STATUS_SET'.

* SET LAYOUT VARIABLE, EVENTS AND SORT FIELDS
  X_LAYOUT_DATA-ZEBRA        = 'X'.                               " Zebra Layout
  X_LAYOUT_DATA-GET_SELINFOS = 'X'.

  IT_EVENTS_DATA-NAME = 'TOP_OF_LIST'.
  IT_EVENTS_DATA-FORM = 'TOP-OF-LIST'.

  APPEND IT_EVENTS_DATA.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
         EXPORTING

                 I_CALLBACK_PROGRAM       =V_REPID
                 I_CALLBACK_PF_STATUS_SET = L_PF_STAT_FORNAME
                 I_CALLBACK_USER_COMMAND  = L_USER_FORMNAME
*                    IT_EXCLUDING                          =
.

  X_LAYOUT_DATA-BOX_FIELDNAME = 'CHK'.

  X_LAYOUT_DATA-BOX_TABNAME   = 'IT_OUTPUT'.
*  X_LAYOUT_DATA-SUBTOTALS_TEXT = '*'.
  X_LAYOUT_DATA-TOTALS_TEXT    = 'Totals#'.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
         EXPORTING
                 IS_LAYOUT                               = X_LAYOUT_DATA


                 I_TABNAME                              = 'IT_OUTPUT'

*               I_TEXT                                 = ' '
         TABLES

                 T_OUTTAB                               = IT_OUTPUT
    EXCEPTIONS
             PROGRAM_ERROR                           = 1
             MAXIMUM_OF_APPENDS_REACHED =2
             OTHERS                                 = 3
                 .
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
*    EXPORTING
*             I_INTERFACE_CHECK       = ' '
*             IS_PRINT                            =

*             I_SCREEN_START_COLUMN   = 0
*             I_SCREEN_START_LINE     = 0
*             I_SCREEN_END_COLUMN     = 0
*             I_SCREEN_END_LINE       = 0
*    IMPORTING
*             E_EXIT_CAUSED_BY_CALLER =
*             ES_EXIT_CAUSED_BY_USER  =
    EXCEPTIONS


             PROGRAM_ERROR                       = 1
             OTHERS                              = 2
                 .
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

ENDFORM.                                 " DISPLAY_ALV_OUTPUT

*&---------------------------------------------------------------------*
*&      Form  IT_POPUP_DISPLAY
*&---------------------------------------------------------------------*

*       text: Displays popup screen
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM POPUP_DISPLAY.

*variables
  DATA : L_POS(1) TYPE N VALUE 1. " Field pos

* Fieldcatalog for popup
  DATA : IT_FIELDCAT_POP TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.

  CLEAR IT_FIELDCAT_POP.
  REFRESH IT_FIELDCAT_POP.


  SORT IT_IDOCMESS2.

* Base Week  #
  IT_FIELDCAT_POP-FIELDNAME        = 'BASEWEEK'.

  IT_FIELDCAT_POP-TABNAME                        = 'IT_IDOCMESS2'.
  IT_FIELDCAT_POP-COL_POS                            = L_POS.
  IT_FIELDCAT_POP-SELTEXT_M         = 'Base Week# '(030).
  IT_FIELDCAT_POP-OUTPUTLEN         = 10.
*  IT_FIELDCAT_POP-DDICTXT                             = 'M'.
*  IT_FIELDCAT_POP-OUTPUTLEN         = 50.
*  IT_FIELDCAT_POP-NO_ZERO          = 'X'.
  APPEND IT_FIELDCAT_POP.

  CLEAR  IT_FIELDCAT_POP.
  L_POS                                               = L_POS + 1.

* Message  #
  IT_FIELDCAT_POP-FIELDNAME        = 'MESSAGE'.
  IT_FIELDCAT_POP-TABNAME                        = 'IT_IDOCMESS2'.

  IT_FIELDCAT_POP-COL_POS                            = L_POS.
  IT_FIELDCAT_POP-SELTEXT_M         = 'Message# '(030).
  IT_FIELDCAT_POP-OUTPUTLEN         = 10.
*  IT_FIELDCAT_POP-DDICTXT                             = 'M'.
*  IT_FIELDCAT_POP-OUTPUTLEN         = 50.
*  IT_FIELDCAT_POP-NO_ZERO          = 'X'.
  APPEND IT_FIELDCAT_POP.
  CLEAR  IT_FIELDCAT_POP.


  L_POS                                               = L_POS + 1.

* Errors #
  IT_FIELDCAT_POP-FIELDNAME        = 'ERROR'.

  IT_FIELDCAT_POP-TABNAME                        = 'IT_IDOCMESS2'.
  IT_FIELDCAT_POP-COL_POS                            = L_POS.
  IT_FIELDCAT_POP-SELTEXT_M         = 'Errors# '(030).
  IT_FIELDCAT_POP-OUTPUTLEN         = 7.
*  IT_FIELDCAT_POP-DDICTXT                             = 'M'.
*  IT_FIELDCAT_POP-OUTPUTLEN         = 50.
*  IT_FIELDCAT_POP-NO_ZERO          = 'X'.
  APPEND IT_FIELDCAT_POP.

  CLEAR  IT_FIELDCAT_POP.
  L_POS                                               = L_POS + 1.

* Text  #
  IT_FIELDCAT_POP-FIELDNAME        = 'TEXT'.

  IT_FIELDCAT_POP-TABNAME                        = 'IT_IDOCMESS2'.
  IT_FIELDCAT_POP-COL_POS                            = L_POS.
  IT_FIELDCAT_POP-SELTEXT_M        = 'Text Display# '(030).
  IT_FIELDCAT_POP-OUTPUTLEN         = 50.
*  IT_FIELDCAT_POP-DDICTXT                             = 'M'.
*  IT_FIELDCAT_POP-OUTPUTLEN         = 50.
*  IT_FIELDCAT_POP-NO_ZERO          = 'X'.
  APPEND IT_FIELDCAT_POP.


  CLEAR  IT_FIELDCAT_POP.
  L_POS                                               = L_POS + 1.

*The code is added from here

* Number of Erros #

*  IT_FIELDCAT_POP-FIELDNAME        = 'WK1'.
*  IT_FIELDCAT_POP-TABNAME                        = 'IT_IDOCMESS2'.
*  IT_FIELDCAT_POP-COL_POS                             = L_POS.
*  IT_FIELDCAT_POP-SELTEXT_M         = 'Number Of Errors#'(032).
*  IT_FIELDCAT_POP-DDICTXT                             = 'M'.

*  IT_FIELDCAT_POP-OUTPUTLEN         = 20.
** IT_FIELDCAT_POP-FIX_COLUMN        = 'X'.
*  IT_FIELDCAT_POP-EMPHASIZE                          = 'C600'.
*  IT_FIELDCAT_POP-DATATYPE                           = 'INT4'.
*  IT_FIELDCAT_POP-INTTYPE                             = 'I'.
*  IT_FIELDCAT_POP-INTLEN                             = '8'.
*  IT_FIELDCAT_POP-NO_ZERO          = 'X'.

*  IT_FIELDCAT_POP-DO_SUM                              = 'X'.
*  APPEND IT_FIELDCAT_POP.
*  CLEAR  IT_FIELDCAT_POP.
*  L_POS                                                = L_POS + 1.

  IT_FIELDCAT_POP-FIELDNAME        = 'WK1'.
  IT_FIELDCAT_POP-TABNAME                        = 'IT_IDOCMESS2'.
  IT_FIELDCAT_POP-COL_POS                            = L_POS.


  IT_FIELDCAT_POP-SELTEXT_M                       = 'Wk1'(004).
  IT_FIELDCAT_POP-DDICTXT                             = 'M'.
  IT_FIELDCAT_POP-OUTPUTLEN         = 8.
  IT_FIELDCAT_POP-EMPHASIZE                         = 'C600'.
  IT_FIELDCAT_POP-DATATYPE                           = 'INT4'.

  IT_FIELDCAT_POP-INTTYPE                             = 'I'.
  IT_FIELDCAT_POP-INTLEN                             = '8'.
  IT_FIELDCAT_POP-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_POP-NO_ZERO          = 'X'.
  IT_FIELDCAT_POP-DO_SUM                              = 'X'.
  APPEND IT_FIELDCAT_POP.
  CLEAR  IT_FIELDCAT_POP.
  L_POS                                               = L_POS + 1.

  IT_FIELDCAT_POP-FIELDNAME                         = 'WK2'.
  IT_FIELDCAT_POP-TABNAME                        = 'IT_IDOCMESS2'.
  IT_FIELDCAT_POP-COL_POS                            = L_POS.
  IT_FIELDCAT_POP-SELTEXT_M                       = 'Wk2'(004).
  IT_FIELDCAT_POP-DDICTXT                             = 'M'.
  IT_FIELDCAT_POP-OUTPUTLEN         = 8.

  IT_FIELDCAT_POP-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_POP-EMPHASIZE                         = 'C600'.
  IT_FIELDCAT_POP-DATATYPE                           = 'INT4'.
  IT_FIELDCAT_POP-INTTYPE                             = 'I'.
  IT_FIELDCAT_POP-INTLEN                             = '8'.
  IT_FIELDCAT_POP-NO_ZERO          = 'X'.
  IT_FIELDCAT_POP-DO_SUM                                 = 'X'.
  APPEND IT_FIELDCAT_POP.


  CLEAR  IT_FIELDCAT_POP.
  L_POS                                               = L_POS + 1.

  IT_FIELDCAT_POP-FIELDNAME        = 'WK3'.
  IT_FIELDCAT_POP-TABNAME                        = 'IT_IDOCMESS2'.

  IT_FIELDCAT_POP-COL_POS                            = L_POS.
  IT_FIELDCAT_POP-SELTEXT_M                       = 'Wk3'(005).
  IT_FIELDCAT_POP-DDICTXT                             = 'M'.
  IT_FIELDCAT_POP-OUTPUTLEN         = 8.
  IT_FIELDCAT_POP-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_POP-EMPHASIZE                         = 'C600'.
  IT_FIELDCAT_POP-DATATYPE                           = 'INT4'.
  IT_FIELDCAT_POP-INTTYPE                             = 'I'.

  IT_FIELDCAT_POP-INTLEN                             = '8'.
  IT_FIELDCAT_POP-NO_ZERO          = 'X'.
  IT_FIELDCAT_POP-DO_SUM                                 = 'X'.
  APPEND IT_FIELDCAT_POP.
  CLEAR  IT_FIELDCAT_POP.
  L_POS                                               = L_POS + 1.

  IT_FIELDCAT_POP-FIELDNAME        = 'WK4'.
  IT_FIELDCAT_POP-TABNAME                        = 'IT_IDOCMESS2'.
  IT_FIELDCAT_POP-COL_POS                            = L_POS.
  IT_FIELDCAT_POP-SELTEXT_M                       = 'Wk4'(006).
  IT_FIELDCAT_POP-DDICTXT                             = 'M'.
  IT_FIELDCAT_POP-OUTPUTLEN         = 8.
  IT_FIELDCAT_POP-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_POP-EMPHASIZE                         = 'C600'.


  IT_FIELDCAT_POP-DATATYPE                           = 'INT4'.
  IT_FIELDCAT_POP-INTTYPE                             = 'I'.
  IT_FIELDCAT_POP-INTLEN                             = '8'.
  IT_FIELDCAT_POP-NO_ZERO          = 'X'.
  IT_FIELDCAT_POP-DO_SUM                                 = 'X'.

  APPEND IT_FIELDCAT_POP.
  CLEAR  IT_FIELDCAT_POP.
  L_POS                                               = L_POS + 1.

  IT_FIELDCAT_POP-FIELDNAME        = 'WK5'.
  IT_FIELDCAT_POP-TABNAME                        = 'IT_IDOCMESS2'.
  IT_FIELDCAT_POP-COL_POS                            = L_POS.
  IT_FIELDCAT_POP-SELTEXT_M                       = 'Wk5'(005).

  IT_FIELDCAT_POP-DDICTXT                             = 'M'.
  IT_FIELDCAT_POP-OUTPUTLEN         = 8.
  IT_FIELDCAT_POP-FIX_COLUMN        = 'X'.
  IT_FIELDCAT_POP-EMPHASIZE                         = 'C600'.
  IT_FIELDCAT_POP-DATATYPE                           = 'INT4'.
  IT_FIELDCAT_POP-INTTYPE                             = 'I'.
  IT_FIELDCAT_POP-INTLEN                             = '8'.

  IT_FIELDCAT_POP-NO_ZERO          = 'X'.
  IT_FIELDCAT_POP-DO_SUM                              = 'X'.
  APPEND IT_FIELDCAT_POP.
  CLEAR  IT_FIELDCAT_POP.
  L_POS                                               = L_POS + 1.


  CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
         EXPORTING
                  I_TITLE      = 'Errors For the Perticular Message'(050)
*             I_SELECTION                         = 'X'
*             I_ZEBRA                             = ' '

                 I_SCREEN_START_COLUMN   = 1
                 I_SCREEN_START_LINE     = 1
                 I_SCREEN_END_COLUMN     = 100
                 I_SCREEN_END_LINE       = 70
*             I_CHECKBOX_FIELDNAME    =
*             I_LINEMARK_FIELDNAME    =
*                  I_SCROLL_TO_SEL_LINE    = 'X'
                 I_TABNAME                         = 'IT_IDOCMESS2'

*             I_STRUCTURE_NAME        =

*             IT_EXCLUDING                       =
*             I_CALLBACK_PROGRAM      =
*             I_CALLBACK_USER_COMMAND =
*             IS_PRIVATE                         =
*    IMPORTING

*             ES_SELFIELD            =
*             E_EXIT                              =
         TABLES
                 T_OUTTAB                          =  IT_IDOCMESS2
        EXCEPTIONS
               PROGRAM_ERROR                        = 1
               OTHERS                              = 2
                 .


  IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  REFRESH IT_FIELDCAT_POP.

  CLEAR IT_FIELDCAT_POP.

  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
ENDFORM.                                 " IT_POPUP_DISPLAY

*&---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*       Processing User command
*----------------------------------------------------------------------*
*      -->P_UCOMM     Screens, function code triggered by PAI
*      -->P_SELFIELD  information cursor position ALV

*----------------------------------------------------------------------*
FORM USER_COMMAND USING                  P_UCOMM    LIKE SY-UCOMM
                                       P_SELFIELD TYPE SLIS_SELFIELD.
  CASE P_UCOMM.

    WHEN 'DISPLAY'.
*      P_SELFIELD-REFRESH = 'X'.
        PERFORM ERROR_LIST1.


        PERFORM POPUP_DISPLAY.
  ENDCASE.
ENDFORM.                                 " USER_COMMAND

*&---------------------------------------------------------------------*

*&      Form  ERROR_LIST
*&---------------------------------------------------------------------*
*       text: This subroutine displayes the errors of baseweek
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ERROR_LIST.

  DATA: BEGIN OF IT_IDOC_STATUS OCCURS 0.
              INCLUDE STRUCTURE EDIDS.
  DATA: END OF IT_IDOC_STATUS.

  DATA: IT_IDOCMESS_TEMP LIKE IT_IDOCMESS OCCURS 0 WITH HEADER LINE,
             V_DATE   LIKE SY-DATUM.

  DATA: ERROR_COUNT TYPE I.
  CLEAR: V_MESSAGE, V_ERROR.

  LOOP AT IT_OUTPUT WHERE CHK = 'X'.

    CLEAR IT_IDOCMESS.
    REFRESH IT_IDOCMESS.


      IT_DATE-LOW =IT_OUTPUT-BASEWEEK - 7.
      IT_DATE-HIGH = IT_OUTPUT-BASEWEEK - 1.

    SELECT STATUS MESTYP DOCNUM
                  FROM EDIDC

                  INTO TABLE IT_DOCNUM
                  WHERE MESTYP = IT_OUTPUT-MESSAGE AND
                           STATUS = IT_OUTPUT-ERROR AND
                  CREDAT BETWEEN IT_DATE-LOW AND IT_DATE-HIGH.

    ERROR_COUNT = 1.
    LOOP AT IT_DOCNUM.

*REFRESH IT_IDOC_STATUS.
        CLEAR IT_IDOC_STATUS.
        SELECT * FROM EDIDS INTO TABLE IT_IDOC_STATUS
                      WHERE DOCNUM = IT_DOCNUM-DOCNUM AND
                                STATUS = IT_DOCNUM-STATUS.

* Get most recent status record

        SORT IT_IDOC_STATUS DESCENDING BY LOGDAT LOGTIM COUNTR.
        READ TABLE IT_IDOC_STATUS INDEX 2.
        IF SY-SUBRC <> 0 OR IT_IDOC_STATUS-STATXT = ''.
          READ TABLE IT_IDOC_STATUS INDEX 1.
        ENDIF.

        READ TABLE IT_IDOCMESS WITH KEY TEXT =IT_IDOC_STATUS-STATXT.


        IF SY-SUBRC EQ 0.
            IT_IDOCMESS1-ERROR = IT_IDOCMESS-ERROR + 1.
          MODIFY IT_IDOCMESS1 TRANSPORTING ERROR
                                         WHERE TEXT = IT_IDOC_STATUS-STATXT.
          CONTINUE.

        ELSE.

            IT_IDOCMESS1-TEXT = IT_IDOC_STATUS-STATXT.
            IT_IDOCMESS1-ERROR = 1.

            APPEND IT_IDOCMESS1.
          CLEAR IT_IDOCMESS1.
          CLEAR IT_DOCNUM.

        ENDIF.
    ENDLOOP.

    SORT IT_IDOCMESS1 BY TEXT.

    LOOP AT IT_IDOCMESS1 WHERE TEXT EQ SPACE.
        SELECT SINGLE DESCRP FROM TEDS2 INTO TEDS2-DESCRP

                                       WHERE STATUS = V_ERROR AND
                                               LANGUA = 'EN'.
        IT_IDOCMESS1-TEXT = TEDS2-DESCRP.
        MODIFY IT_IDOCMESS1 INDEX SY-TABIX.
    ENDLOOP.

    LOOP AT IT_IDOCMESS1.
        WRITE:/5 IT_IDOCMESS1-TEXT, 80 IT_IDOCMESS1-ERROR.


    ENDLOOP.
*
  ENDLOOP.

ENDFORM.                                 " ERROR_LIST

*&---------------------------------------------------------------------*
*&      Form  UPDATE_DATABASE_TABLES
*&---------------------------------------------------------------------*
*       text : This perform commits the database inserts
*----------------------------------------------------------------------*
*  -->  p1        text

*  <--  p2        text
*----------------------------------------------------------------------*
FORM UPDATE_DATABASE_TABLES.

***********************************************************************
* Declaration of LOCAL Variables
***********************************************************************

  DATA: L_REPID LIKE SY-REPID, " Program Name.
          L_TIME LIKE SY-UZEIT,  " Program Execution Time
          L_DATE LIKE SY-DATUM,  " Program Execution Date.
          L_PRGID LIKE FRUN-PRGID."ABAP program name

*_ assigning the report name, executed date and executed time to local
*variables, which are used to insert in frun table
  L_REPID =SY-REPID.


  L_DATE =SY-DATUM.
  L_TIME = SY-UZEIT.

* Insert or Update FRUN record that was populated earlier
  MODIFY FRUN.

* The insertion takes place only once for a day.
*  SELECT PRGID
*             INTO L_PRGID
*             FROM FRUN
*             WHERE PRGID = L_REPID AND LDATU = L_DATE.
*
*    IF SY-SUBRC <> 0.
*  DELETE FROM ZIDOC WHERE SNO > 0.

CLEAR V_SNO.
SELECT COUNT( * ) FROM ZIDOC INTO V_SNO.
  LOOP AT IT_OUTPUT.

      IF IT_OUTPUT-WK1 <> 0.
        V_SNO = V_SNO + 1.
        MOVE IT_OUTPUT-BASEWEEK TO ZIDOC-BASEWEEK.

        MOVE IT_OUTPUT-ERROR TO ZIDOC-ERROR.
        MOVE IT_OUTPUT-MESSAGE TO ZIDOC-MESSAGE.
        MOVE V_SNO TO ZIDOC-SNO.
        MOVE IT_OUTPUT-WK1  TO ZIDOC-NO_OF_ERR.
        MOVE 'WK1' TO ZIDOC-WEEK.
        INSERT INTO ZIDOC VALUES ZIDOC.
        CLEAR ZIDOC.


    ENDIF.

      IF IT_OUTPUT-WK2 <> 0.
        MOVE IT_OUTPUT-BASEWEEK TO ZIDOC-BASEWEEK.
        MOVE IT_OUTPUT-ERROR TO ZIDOC-ERROR.

        MOVE IT_OUTPUT-MESSAGE TO ZIDOC-MESSAGE.
        V_SNO = V_SNO + 1.
        MOVE V_SNO TO ZIDOC-SNO.

        MOVE IT_OUTPUT-WK2  TO ZIDOC-NO_OF_ERR.
        MOVE 'WK2' TO ZIDOC-WEEK.
        INSERT INTO ZIDOC VALUES ZIDOC.
        CLEAR ZIDOC.

    ENDIF.

      IF IT_OUTPUT-WK3 <> 0.

        MOVE IT_OUTPUT-BASEWEEK TO ZIDOC-BASEWEEK.

        MOVE IT_OUTPUT-ERROR TO ZIDOC-ERROR.
        MOVE IT_OUTPUT-MESSAGE TO ZIDOC-MESSAGE.
        V_SNO = V_SNO + 1.
        MOVE V_SNO TO ZIDOC-SNO.
        MOVE IT_OUTPUT-WK3  TO ZIDOC-NO_OF_ERR.
        MOVE 'WK3' TO ZIDOC-WEEK.
        INSERT INTO ZIDOC VALUES ZIDOC.
        CLEAR ZIDOC.


    ENDIF.

      IF IT_OUTPUT-WK4 <> 0.

        MOVE IT_OUTPUT-BASEWEEK TO ZIDOC-BASEWEEK.
        MOVE IT_OUTPUT-ERROR TO ZIDOC-ERROR.
        MOVE IT_OUTPUT-MESSAGE TO ZIDOC-MESSAGE.
        V_SNO = V_SNO + 1.
        MOVE V_SNO TO ZIDOC-SNO.
        MOVE IT_OUTPUT-WK4  TO ZIDOC-NO_OF_ERR.
        MOVE 'WK4' TO ZIDOC-WEEK.
        INSERT INTO ZIDOC VALUES ZIDOC.

        CLEAR ZIDOC.

    ENDIF.

      IF IT_OUTPUT-WK5 <> 0.
        MOVE IT_OUTPUT-BASEWEEK TO ZIDOC-BASEWEEK.
        MOVE IT_OUTPUT-ERROR TO ZIDOC-ERROR.

        MOVE IT_OUTPUT-MESSAGE TO ZIDOC-MESSAGE.
        V_SNO = V_SNO + 1.
        MOVE V_SNO TO ZIDOC-SNO.
        MOVE IT_OUTPUT-WK5  TO ZIDOC-NO_OF_ERR.
        MOVE 'WK5' TO ZIDOC-WEEK.
        INSERT INTO ZIDOC VALUES ZIDOC.
        CLEAR ZIDOC.


    ENDIF.

*     INSERT INTO ZIDOC VALUES ZIDOC.

  ENDLOOP.

*    ELSE.
* MESSAGE S001 WITH 'Extraction Program is already excuted for this day'
*            .
*    ENDIF.
* ENDSELECT.
ENDFORM.                                 " UPDATE_DATABASE_TABLES

*---------------------------------------------------------------------*
*       FORM UPDATE_LAST_RUN_TIME                                                                       *
*---------------------------------------------------------------------*
*       Update last run date and time for the report                                                    *
*---------------------------------------------------------------------*

FORM UPDATE_LAST_RUN_TIME.
***********************************************************************
* Declaration of LOCAL Variables
***********************************************************************
  DATA: L_REPID LIKE SY-REPID, " Program Name.
          L_TIME LIKE SY-UZEIT,  " Program Execution Time
          L_DATE LIKE SY-DATUM,  " Program Execution Date.
          L_PRGID LIKE FRUN-PRGID."ABAP program name


*_ assigning the report name, executed date and executed time to local
*variables, which are used to insert in frun table
  L_REPID =SY-REPID.
  L_DATE =SY-DATUM.

  L_TIME = SY-UZEIT.

  SELECT SINGLE
             PRGID
             INTO L_PRGID
             FROM FRUN
             WHERE PRGID = L_REPID.

  MOVE:L_REPID TO FRUN-PRGID,
         L_DATE TO FRUN-LDATU,
         L_TIME TO FRUN-LZEIT.
* FRUN is updated during commit work later in the program
ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  PREVIOUS_WEEK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_BASEWEEK  text
*----------------------------------------------------------------------*
FORM PREVIOUS_WEEK.
* USING    P_BASEWEEK P_MESSAGE P_ERROR.


  DATA: V_LINES TYPE I.
  CLEAR V_LINES.
  SELECT  * INTO TABLE IT_ZIDOC
                      FROM ZIDOC.
*                       WHERE

*                       BASEWEEK = P_BASEWEEK.
*                       AND
*                       MESSAGE = P_MESSAGE AND
*                       ERROR = P_ERROR.
  IF SY-SUBRC = 0.
    CLEAR V_TABIX.
    LOOP AT IT_OUTPUT.
        V_TABIX= SY-TABIX.

        READ TABLE IT_ZIDOC WITH KEY BASEWEEK = IT_OUTPUT-BASEWEEK.
        IF SY-SUBRC =0.

          LOOP AT IT_ZIDOC WHERE BASEWEEK = IT_OUTPUT-BASEWEEK AND
                                                       MESSAGE = IT_OUTPUT-MESSAGE AND
                                                      ERROR = IT_OUTPUT-ERROR.

              CASE IT_ZIDOC-WEEK.
                 WHEN 'WK1'.
                    IT_OUTPUT-WK1 = IT_ZIDOC-NO_OF_ERR.
                   MODIFY IT_OUTPUT INDEX V_TABIX TRANSPORTING WK1.
                 WHEN 'WK2'.
                    IT_OUTPUT-WK2 = IT_ZIDOC-NO_OF_ERR.
                   MODIFY IT_OUTPUT INDEX V_TABIX TRANSPORTING WK2.
                 WHEN 'WK3'.


                    IT_OUTPUT-WK3 = IT_ZIDOC-NO_OF_ERR.
                   MODIFY IT_OUTPUT INDEX V_TABIX TRANSPORTING WK3.
                 WHEN 'WK4'.
                    IT_OUTPUT-WK4 = IT_ZIDOC-NO_OF_ERR.
                   MODIFY IT_OUTPUT INDEX V_TABIX TRANSPORTING WK4.

                 WHEN 'WK5'.
                    IT_OUTPUT-WK5 = IT_ZIDOC-NO_OF_ERR.
                   MODIFY IT_OUTPUT INDEX V_TABIX TRANSPORTING WK5.
              ENDCASE.
            ENDLOOP.

        ELSE.
            IT_OUTPUT-MESSAGE = IT_ZIDOC-MESSAGE.

            IT_OUTPUT-ERROR = IT_ZIDOC-ERROR.
            IT_OUTPUT-BASEWEEK = IT_ZIDOC-BASEWEEK.
          CASE IT_ZIDOC-WEEK.
              WHEN 'WK1'.
                 IT_OUTPUT-WK1 = IT_ZIDOC-NO_OF_ERR.

              WHEN 'WK2'.

                 IT_OUTPUT-WK2 = IT_ZIDOC-NO_OF_ERR.

              WHEN 'WK3'.
                 IT_OUTPUT-WK3 = IT_ZIDOC-NO_OF_ERR.

              WHEN 'WK4'.
                 IT_OUTPUT-WK4 = IT_ZIDOC-NO_OF_ERR.


              WHEN 'WK5'.
                 IT_OUTPUT-WK5 = IT_ZIDOC-NO_OF_ERR.

            ENDCASE.

            APPEND IT_OUTPUT.
          CLEAR IT_OUTPUT.
        ENDIF.

*     MODIFY IT_OUTPUT INDEX V_TABIX TRANSPORTING WK1 WK2 WK3 WK4 WK5.
        CLEAR V_TABIX.
    ENDLOOP.
*    ELSE.

*      APPEND IT_OUTPUT.
*      CLEAR IT_OUTPUT.
  ENDIF.
ENDFORM.                                 " PREVIOUS_WEEK

*&---------------------------------------------------------------------*
*&      Form  GET_DATA_DETAIL_LIST

*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_DATA_DETAIL_LIST.


  DATA: BEGIN OF IT_IDOC_STATUS OCCURS 0.
              INCLUDE STRUCTURE EDIDS.
  DATA: END OF IT_IDOC_STATUS.

  DATA: IT_IDOCMESS_TEMP LIKE IT_IDOCMESS OCCURS 0 WITH HEADER LINE,
             V_DATE   LIKE SY-DATUM.
  DATA: ERROR_COUNT TYPE I.
  CLEAR: V_MESSAGE, V_ERROR.
  DATA: V_SNO TYPE I, V_VAR1(3) TYPE C.
  CLEAR V_SNO.
  LOOP AT IT_OUTPUT.

    CLEAR IT_IDOCMESS.
*    REFRESH IT_IDOCMESS.
*
      IT_DATE-LOW =IT_OUTPUT-BASEWEEK - 7.
      IT_DATE-HIGH = IT_OUTPUT-BASEWEEK - 1.

    SELECT STATUS MESTYP DOCNUM

                  FROM EDIDC
                  INTO TABLE IT_DOCNUM
                  WHERE MESTYP = IT_OUTPUT-MESSAGE AND
                           STATUS = IT_OUTPUT-ERROR AND
                  CREDAT BETWEEN IT_DATE-LOW AND IT_DATE-HIGH.

    ERROR_COUNT = 1.


    LOOP AT IT_DOCNUM.
*REFRESH IT_IDOC_STATUS.
        CLEAR IT_IDOC_STATUS.
        SELECT * FROM EDIDS INTO TABLE IT_IDOC_STATUS
                      WHERE DOCNUM = IT_DOCNUM-DOCNUM AND

                                STATUS = IT_DOCNUM-STATUS.

* Get most recent status record
        SORT IT_IDOC_STATUS DESCENDING BY LOGDAT LOGTIM COUNTR.
        READ TABLE IT_IDOC_STATUS INDEX 2.
        IF SY-SUBRC <> 0 OR IT_IDOC_STATUS-STATXT = ''.
          READ TABLE IT_IDOC_STATUS INDEX 1.
        ENDIF.

        IF IT_OUTPUT-WK5 <> 0.
            V_VAR1 = 'WK5'.
        ENDIF.
        IF IT_OUTPUT-WK4 <> 0.
            V_VAR1 = 'WK4'.
        ENDIF.
        IF IT_OUTPUT-WK3 <> 0.

            V_VAR1 = 'WK3'.
        ENDIF.
        IF IT_OUTPUT-WK2 <> 0.
            V_VAR1 = 'WK2'.
        ENDIF.
        IF IT_OUTPUT-WK1 <> 0.
            V_VAR1 = 'WK1'.
        ENDIF.


        READ TABLE IT_IDOCMESS WITH KEY TEXT =IT_IDOC_STATUS-STATXT
                                                       BASEWEEK = IT_OUTPUT-BASEWEEK
                                                       MESSAGE = IT_OUTPUT-MESSAGE

                                                       ERROR = IT_OUTPUT-ERROR.

        IF SY-SUBRC EQ 0.
            IT_IDOCMESS-NO_OF_ERR = IT_IDOCMESS-NO_OF_ERR + 1.
          MODIFY IT_IDOCMESS TRANSPORTING NO_OF_ERR
                                              WHERE TEXT = IT_IDOC_STATUS-STATXT AND
                                                       BASEWEEK = IT_OUTPUT-BASEWEEK AND
                                                       MESSAGE = IT_OUTPUT-MESSAGE AND

                                                               ERROR = IT_OUTPUT-ERROR.
          CONTINUE.
        ELSE.
            IT_IDOCMESS-BASEWEEK = IT_OUTPUT-BASEWEEK.
            IT_IDOCMESS-MESSAGE = IT_OUTPUT-MESSAGE.
            IT_IDOCMESS-ERROR = IT_OUTPUT-ERROR.
            IT_IDOCMESS-TEXT = IT_IDOC_STATUS-STATXT.

            IT_IDOCMESS-NO_OF_ERR = 1.
            IT_IDOCMESS-WEEK = V_VAR1.
            IT_IDOCMESS-SNO = V_SNO +1.
            V_SNO = V_SNO + 1.
            APPEND IT_IDOCMESS.
          CLEAR IT_IDOCMESS.
          CLEAR IT_DOCNUM.
        ENDIF.


    ENDLOOP.

*    LOOP AT IT_IDOCMESS.
*      WRITE:/5 IT_IDOCMESS-TEXT, 80 IT_IDOCMESS-ERROR.
*    ENDLOOP.

  ENDLOOP.

  SORT IT_IDOCMESS BY TEXT.

  LOOP AT IT_IDOCMESS WHERE TEXT EQ SPACE OR
                                             TEXT EQ '&'.

    SELECT SINGLE DESCRP FROM TEDS2 INTO TEDS2-DESCRP
                                   WHERE STATUS = V_ERROR AND
                                             LANGUA = 'EN'.
      IT_IDOCMESS-TEXT = TEDS2-DESCRP.
    MODIFY IT_IDOCMESS INDEX SY-TABIX.
  ENDLOOP.

  PERFORM UPDATE_ZIPOPUP.

ENDFORM.                                 " GET_DATA_DETAIL_LIST

*&---------------------------------------------------------------------*
*&      Form  UPDATE_ZIPOPUP
*&---------------------------------------------------------------------*


*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*

FORM UPDATE_ZIPOPUP.
  DATA: IT_ZIPOPUP LIKE ZIPOPUP OCCURS 0 WITH HEADER LINE.
  CLEAR V_SNO.
  SORT IT_IDOCMESS BY BASEWEEK.

  SELECT COUNT(*) FROM ZIPOPUP INTO V_SNO.

  LOOP AT IT_IDOCMESS.

    V_SNO = V_SNO + 1.
    MOVE V_SNO TO IT_ZIPOPUP-SNO.
    MOVE IT_IDOCMESS-BASEWEEK TO IT_ZIPOPUP-BASEWEEK.
    MOVE IT_IDOCMESS-MESSAGE TO IT_ZIPOPUP-MESSAGE.
    MOVE IT_IDOCMESS-ERROR TO IT_ZIPOPUP-ERROR.
    MOVE IT_IDOCMESS-TEXT TO IT_ZIPOPUP-TEXT.
    MOVE IT_IDOCMESS-NO_OF_ERR TO IT_ZIPOPUP-NO_OF_ERR.

    MOVE IT_IDOCMESS-WEEK TO IT_ZIPOPUP-WEEK.

    APPEND IT_ZIPOPUP.
    CLEAR IT_ZIPOPUP.
  ENDLOOP.

  INSERT ZIPOPUP FROM TABLE IT_ZIPOPUP.


ENDFORM.                                 " UPDATE_ZIPOPUP

*&---------------------------------------------------------------------*
*&      Form  ERROR_LIST
*&---------------------------------------------------------------------*
*       text: This subroutine displayes the errors of baseweek
*----------------------------------------------------------------------*
*  -->  p1        text

*  <--  p2        text
*----------------------------------------------------------------------*
FORM ERROR_LIST1.

  DATA: BEGIN OF IT_IDOC_STATUS OCCURS 0.
              INCLUDE STRUCTURE EDIDS.
  DATA: END OF IT_IDOC_STATUS.

  DATA: IT_IDOCMESS_TEMP LIKE IT_IDOCMESS OCCURS 0 WITH HEADER LINE,
             V_DATE   LIKE SY-DATUM.
  DATA: ERROR_COUNT TYPE I.
  CLEAR: V_MESSAGE, V_ERROR.
  REFRESH IT_IDOCMESS1.

  READ TABLE IT_OUTPUT WITH KEY CHK = 'X'.


  IF SY-SUBRC <> 0.
       MESSAGE W003.

  ENDIF.

  LOOP AT IT_OUTPUT WHERE CHK = 'X'.

    SELECT SNO
               BASEWEEK
               MESSAGE
               ERROR
               TEXT

               NO_OF_ERR
               WEEK
               APPENDING TABLE IT_IDOCMESS1
               FROM ZIPOPUP
               WHERE BASEWEEK = IT_OUTPUT-BASEWEEK AND
                       MESSAGE = IT_OUTPUT-MESSAGE AND
                       ERROR = IT_OUTPUT-ERROR.

    SORT IT_IDOCMESS1 BY BASEWEEK MESSAGE ERROR.

   LOOP AT IT_IDOCMESS1 WHERE TEXT EQ SPACE.
        SELECT SINGLE DESCRP FROM TEDS2 INTO TEDS2-DESCRP
                                       WHERE STATUS = V_ERROR AND
                                               LANGUA = 'EN'.
        IT_IDOCMESS1-TEXT = TEDS2-DESCRP.


        MODIFY IT_IDOCMESS1 INDEX SY-TABIX.
    ENDLOOP.

    LOOP AT IT_IDOCMESS.
        WRITE:/5 IT_IDOCMESS-TEXT, 80 IT_IDOCMESS-ERROR.

    ENDLOOP.

  ENDLOOP.

*// Here the code
  CLEAR IT_IDOCMESS2.
  REFRESH IT_IDOCMESS2.

  LOOP AT IT_IDOCMESS1.
  CLEAR V_TABIX.
  V_TABIX =SY-TABIX.
    MOVE: IT_IDOCMESS1-BASEWEEK TO IT_IDOCMESS2-BASEWEEK,
              IT_IDOCMESS1-MESSAGE  TO IT_IDOCMESS2-MESSAGE,
              IT_IDOCMESS1-ERROR TO IT_IDOCMESS2-ERROR,
              IT_IDOCMESS1-TEXT TO IT_IDOCMESS2-TEXT.

    READ TABLE IT_IDOCMESS2 WITH KEY BASEWEEK = IT_IDOCMESS1-BASEWEEK
                                               MESSAGE = IT_IDOCMESS1-MESSAGE
                                               ERROR = IT_IDOCMESS1-ERROR
                                               TEXT= IT_IDOCMESS1-TEXT.

      IF SY-SUBRC = 0.


    CASE IT_IDOCMESS1-WEEK.
        WHEN 'WK1'.
            IT_IDOCMESS2-WK1 = IT_IDOCMESS1-NO_OF_ERR.
          MODIFY IT_IDOCMESS2 TRANSPORTING WK1

                       WHERE BASEWEEK= IT_IDOCMESS1-BASEWEEK AND
                                               MESSAGE = IT_IDOCMESS1-MESSAGE AND
                                               ERROR = IT_IDOCMESS1-ERROR AND
                                               TEXT= IT_IDOCMESS1-TEXT.

        WHEN 'WK2'.
            IT_IDOCMESS2-WK2 = IT_IDOCMESS1-NO_OF_ERR.

          MODIFY IT_IDOCMESS2 TRANSPORTING WK2
                       WHERE BASEWEEK= IT_IDOCMESS1-BASEWEEK AND
                                               MESSAGE = IT_IDOCMESS1-MESSAGE AND
                                               ERROR = IT_IDOCMESS1-ERROR AND
                                               TEXT= IT_IDOCMESS1-TEXT.

        WHEN 'WK3'.

            IT_IDOCMESS2-WK3 = IT_IDOCMESS1-NO_OF_ERR.
          MODIFY IT_IDOCMESS2 TRANSPORTING WK3
                       WHERE BASEWEEK= IT_IDOCMESS1-BASEWEEK AND
                                               MESSAGE = IT_IDOCMESS1-MESSAGE AND
                                               ERROR = IT_IDOCMESS1-ERROR AND
                                               TEXT= IT_IDOCMESS1-TEXT.

        WHEN 'WK4'.


            IT_IDOCMESS2-WK4 = IT_IDOCMESS1-NO_OF_ERR.
          MODIFY IT_IDOCMESS2 TRANSPORTING WK4
                       WHERE BASEWEEK = IT_IDOCMESS1-BASEWEEK AND
                                               MESSAGE = IT_IDOCMESS1-MESSAGE AND
                                               ERROR = IT_IDOCMESS1-ERROR AND

                                               TEXT= IT_IDOCMESS1-TEXT.

        WHEN 'WK5'.
            IT_IDOCMESS2-WK5 = IT_IDOCMESS1-NO_OF_ERR.
          MODIFY IT_IDOCMESS2 TRANSPORTING WK5
                       WHERE BASEWEEK = IT_IDOCMESS1-BASEWEEK AND
                                               MESSAGE = IT_IDOCMESS1-MESSAGE AND
                                               ERROR = IT_IDOCMESS1-ERROR AND

                                               TEXT= IT_IDOCMESS1-TEXT.

   ENDCASE.

   ELSE.
   CASE IT_IDOCMESS1-WEEK.

        WHEN 'WK1'.
            IT_IDOCMESS2-WK1 = IT_IDOCMESS1-NO_OF_ERR.

        WHEN 'WK2'.
            IT_IDOCMESS2-WK2 = IT_IDOCMESS1-NO_OF_ERR.

        WHEN 'WK3'.
            IT_IDOCMESS2-WK3 = IT_IDOCMESS1-NO_OF_ERR.


        WHEN 'WK4'.
            IT_IDOCMESS2-WK4 = IT_IDOCMESS1-NO_OF_ERR.

        WHEN 'WK5'.

            IT_IDOCMESS2-WK5 = IT_IDOCMESS1-NO_OF_ERR.

    ENDCASE.

    APPEND IT_IDOCMESS2.
    CLEAR IT_IDOCMESS2.
    ENDIF.

  ENDLOOP.

CLEAR V_TABIX.

SORT IT_IDOCMESS2 BY BASEWEEK
                               MESSAGE

                               ERROR.
LOOP AT IT_IDOCMESS2.

V_TABIX = SY-TABIX.
V_TABIX = V_TABIX + 1.

READ TABLE IT_IDOCMESS2 INTO IT_IDOCMESS2_TEMP INDEX V_TABIX.


IF IT_IDOCMESS2-BASEWEEK =IT_IDOCMESS2_TEMP-BASEWEEK.

IT_IDOCMESS-BASEWEEK = ''.
CLEAR IT_IDOCMESS2-BASEWEEK.
MODIFY IT_IDOCMESS2 INDEX V_TABIX TRANSPORTING BASEWEEK.

ENDIF.

ENDLOOP.

ENDFORM.                                 " ERROR_LIST
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | Интерфейсы All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.