MPS报表

TYPE-POOLS: SLIS.
TABLES: MARA,MAKT,AFKO,MARC.
DATA:BEGIN OF ALV_LINE.
       INCLUDE STRUCTURE ZPP_MPS_SID.
DATA: END OF ALV_LINE.
DATA: ALV_TAB LIKE TABLE OF ALV_LINE WITH NON-UNIQUE KEY WERKS MATNR.
DATA: BEGIN OF TAB OCCURS 0,
       WERKS LIKE MARC-WERKS,
       GSTRP LIKE AFKO-GSTRP,
       MATNR LIKE MARA-MATNR,
       QTY LIKE AFKO-GAMNG,
      END OF TAB.
DATA: IS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

DATA: BEGIN OF ITAB OCCURS 0,
         WERKS LIKE MARC-WERKS,
         AUFNR LIKE AFKO-AUFNR,
         PLNBEZ LIKE AFKO-PLNBEZ,
         GSTRP LIKE AFKO-GSTRP,   "Basic start date
         GAMNG LIKE AFKO-GAMNG,
      END OF ITAB.
DATA: WA_ITAB LIKE LINE OF ITAB.



DATA: NUM_STRING(10) TYPE C.
DATA: OR_STATUS LIKE MAKT-MAKTX.
DATA: OR_NO LIKE JEST-OBJNR.
DATA: CUR_DATE LIKE SY-DATUM,
      LAST_DATE LIKE SY-DATUM.
DATA: RESULT_DAY(10) TYPE C.

*-SELECTION-SCREEN
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME.
SELECT-OPTIONS: T_WERKS FOR MARC-WERKS NO INTERVALS OBLIGATORY.
SELECT-OPTIONS: T_MATNR FOR MARA-MATNR.

SKIP 1.
PARAMETERS: T_DATE LIKE SY-DATUM.
PARAMETERS: T_DAY(2) TYPE N DEFAULT '10'.
SELECTION-SCREEN END OF BLOCK BLK1.

SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME.
 SELECTION-SCREEN BEGIN OF LINE.
 PARAMETERS: R1 RADIOBUTTON GROUP RGP DEFAULT 'X'.
 SELECTION-SCREEN COMMENT 5(20) COMM1.
 SELECTION-SCREEN END OF LINE.

 SELECTION-SCREEN BEGIN OF LINE.
 PARAMETERS: R2 RADIOBUTTON GROUP RGP.
 SELECTION-SCREEN COMMENT 5(20) COMM2.
 SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK BLK2.

* END SELECTION-SCREEN

INITIALIZATION.
  T_DATE = SY-DATUM + 1.
  COMM1 = 'MACM MPS List'.
  COMM2 = 'MSPT MPS List'.

START-OF-SELECTION.

  CUR_DATE = T_DATE.
  LAST_DATE = CUR_DATE + T_DAY.

 PERFORM. GET_DATA_FORM.          "Production order
 PERFORM. TRIEVE_DATA_FORM.
 PERFORM. FILL_DATA_FORM.
 PERFORM. DISPLAY_ALV_FORM.

*&------------------------------------------------------*
*&      Form  GET_DATA_FORM
*&------------------------------------------------------*
FORM. GET_DATA_FORM. .
  CLEAR: ITAB,ALV_TAB.
  REFRESH: ITAB,ALV_TAB.
   IF R1 = 'X'.
   SELECT AUFK~WERKS  AFKO~AUFNR AFKO~PLNBEZ AFKO~GSTRP AFKO~GAMNG
           INTO (ITAB-WERKS, ITAB-AUFNR,ITAB-PLNBEZ, ITAB-GSTRP,
                  ITAB-GAMNG)
          FROM AFKO
          JOIN AUFK ON AFKO~AUFNR = AUFK~AUFNR
          WHERE AUFK~WERKS IN T_WERKS
          AND   AFKO~PLNBEZ IN T_MATNR
          AND AFKO~GSTRP GE CUR_DATE .


          CONCATENATE 'OR' ITAB-AUFNR INTO OR_NO.

          CALL FUNCTION 'STATUS_TEXT_EDIT'
             EXPORTING
                  OBJNR       = OR_NO
                 ONLY_ACTIVE = 'X'
                 SPRAS       = 'E'
                  BYPASS_BUFFER = '1'
          IMPORTING
                 LINE = OR_STATUS.

             IF NOT  ( OR_STATUS CS 'TECO'
                  OR OR_STATUS CS 'CNF'
                   OR OR_STATUS CS 'DLFL'
                  OR OR_STATUS CS 'LKD'
               OR OR_STATUS CS 'PCNF'
               OR OR_STATUS CS 'MSPT' ).
               APPEND ITAB.
               CLEAR ITAB.
             ENDIF.
    ENDSELECT.
ENDIF.

 IF R2 = 'X'.
   SELECT AUFK~WERKS  AFKO~AUFNR AFKO~PLNBEZ AFKO~GSTRP AFKO~GAMNG
           INTO (ITAB-WERKS,
                 ITAB-AUFNR,
                 ITAB-PLNBEZ,
                 ITAB-GSTRP,
                 ITAB-GAMNG)
          FROM AFKO
          JOIN AUFK ON AFKO~AUFNR = AUFK~AUFNR
          WHERE AUFK~WERKS IN T_WERKS
          AND   AFKO~PLNBEZ IN T_MATNR
          AND AFKO~GSTRP GE CUR_DATE .


          CONCATENATE 'OR' ITAB-AUFNR INTO OR_NO.

          CALL FUNCTION 'STATUS_TEXT_EDIT'
             EXPORTING
             OBJNR       = OR_NO
             ONLY_ACTIVE = 'X'
             SPRAS       = 'E'
             BYPASS_BUFFER = '1'
          IMPORTING
             LINE = OR_STATUS.

             IF NOT  ( OR_STATUS CS 'TECO'
               OR OR_STATUS CS 'CNF'
               OR OR_STATUS CS 'DLFL'
               OR OR_STATUS CS 'LKD'
               OR OR_STATUS CS 'PCNF'
               OR OR_STATUS CS 'MACM' ).
               APPEND ITAB.
               CLEAR ITAB.
             ENDIF.
    ENDSELECT.
ENDIF.


    SORT ITAB BY GSTRP PLNBEZ WERKS.
    LOOP AT ITAB .
        TAB-MATNR = ITAB-PLNBEZ.
        TAB-GSTRP = ITAB-GSTRP.
        TAB-QTY = ITAB-GAMNG.
        COLLECT TAB.
    ENDLOOP.

ENDFORM.

*&----------------------------------------------------*
*&      Form  TRIEVE_DATA_FORM
*&----------------------------------------------------*

FORM. TRIEVE_DATA_FORM.
 DATA: L_DAY(2) TYPE N,
       I_TIMES(2) TYPE N,
       L_FIELD(10) TYPE C,
       L_TITLE TYPE D.
       L_DAY = 1.


 CLEAR IS_FIELDCAT.
 IS_FIELDCAT-FIELDNAME = 'WERKS'.
 IS_FIELDCAT-TABNAME = 'ZPP_MPS_SID'.
 IS_FIELDCAT-REPTEXT_DDIC = 'WO & SO'.
 IS_FIELDCAT-OUTPUTLEN = '10'.
 IS_FIELDCAT-COL_POS = 1.
 IS_FIELDCAT-JUST = 'C'.
 APPEND IS_FIELDCAT TO IT_FIELDCAT.

 CLEAR IS_FIELDCAT.
 IS_FIELDCAT-FIELDNAME = 'MATNR'.
 IS_FIELDCAT-TABNAME = 'ZPP_MPS_SID'.
 IS_FIELDCAT-REPTEXT_DDIC = 'Mat.No'.
 IS_FIELDCAT-OUTPUTLEN = '18'.
 IS_FIELDCAT-COL_POS = 2.
 IS_FIELDCAT-JUST = 'C'.
 APPEND IS_FIELDCAT TO IT_FIELDCAT.



I_TIMES = T_DAY.

 DO I_TIMES TIMES.
  IF L_DAY > 14.
    EXIT.
  ELSE.
   CONCATENATE 'DAY' L_DAY INTO L_FIELD.
   L_TITLE = T_DATE + L_DAY - 1.
   IS_FIELDCAT-FIELDNAME = L_FIELD.
   IS_FIELDCAT-TABNAME = 'ZPP_MPS_SID'.
   IS_FIELDCAT-REPTEXT_DDIC = L_TITLE.
   IS_FIELDCAT-OUTPUTLEN = '10'.
   IS_FIELDCAT-COL_POS = SY-TABIX.
   APPEND IS_FIELDCAT TO IT_FIELDCAT.

   L_DAY = L_DAY + 1.
 ENDIF.

 ENDDO.

ENDFORM.

*&---------------------------------------------------*
*&      Form  FILL_DATA_FORM
*&---------------------------------------------------*
FORM. FILL_DATA_FORM.
DATA: L_PLANT LIKE MARC-WERKS.
    SORT ITAB BY WERKS PLNBEZ GSTRP.
    LOOP AT ITAB INTO WA_ITAB.
       READ TABLE ALV_TAB INTO ALV_LINE WITH KEY MATNR = WA_ITAB-PLNBEZ.


       IF SY-SUBRC <> 0.
           CLEAR ALV_LINE.
          IF WA_ITAB-WERKS = '1000‘.
            ALV_LINE-WERKS = 'A客户'.
          ENDIF.

          IF WA_ITAB-WERKS = '2000'.
            ALV_LINE-WERKS = 'B客户'.
          ENDIF.


            ALV_LINE-MATNR = WA_ITAB-PLNBEZ.

            READ TABLE TAB WITH KEY MATNR = WA_ITAB-PLNBEZ
                                    GSTRP = WA_ITAB-GSTRP.

            IF SY-SUBRC = 0.
               WA_ITAB-GAMNG = TAB-QTY.
            ENDIF.
            PERFORM. FILL_DB_DATA USING WA_ITAB-GSTRP WA_ITAB-GAMNG.
              APPEND ALV_LINE TO ALV_TAB.

       ELSEIF SY-SUBRC = 0.
           CLEAR ALV_LINE.
             IF WA_ITAB-WERKS = '1000‘.
                ALV_LINE-WERKS = 'A客户'.
            ENDIF.

          IF WA_ITAB-WERKS = '2000'.
               ALV_LINE-WERKS = 'B客户'.
          ENDIF.

            ALV_LINE-MATNR = WA_ITAB-PLNBEZ.

            READ TABLE TAB WITH KEY MATNR = WA_ITAB-PLNBEZ
                                    GSTRP = WA_ITAB-GSTRP.

            IF SY-SUBRC = 0.
               WA_ITAB-GAMNG = TAB-QTY.
            ENDIF.

            PERFORM. MODIFY_DB_DATA USING WA_ITAB-GSTRP WA_ITAB-GAMNG.
       ENDIF.
    ENDLOOP.

  SORT ALV_TAB BY WERKS MATNR.
   DELETE ADJACENT DUPLICATES FROM  ALV_TAB COMPARING ALL FIELDS.
ENDFORM.

*&------------------------------------------------------*
*&      Form  FILL_DB_DATA
*&------------------------------------------------------*
FORM. FILL_DB_DATA USING    P_GSTRP
                           P_GAMNG.
DATA: I_A(2) TYPE N.

   CLEAR: RESULT_DAY.
   I_A = P_GSTRP - T_DATE + 1.
   CONCATENATE 'DAY' I_A INTO RESULT_DAY.
   NUM_STRING = P_GAMNG.
    IF P_GAMNG = 0.   NUM_STRING = ''. ENDIF.
    CASE RESULT_DAY.
      WHEN 'DAY01'.  ALV_LINE-DAY01 = NUM_STRING.
      WHEN 'DAY02'.  ALV_LINE-DAY02 = NUM_STRING.
      WHEN 'DAY03'.  ALV_LINE-DAY03 = NUM_STRING.
      WHEN 'DAY04'.  ALV_LINE-DAY04 = NUM_STRING.
      WHEN 'DAY05'.  ALV_LINE-DAY05 = NUM_STRING.
      WHEN 'DAY06'.  ALV_LINE-DAY06 = NUM_STRING.
      WHEN 'DAY07'.  ALV_LINE-DAY07 = NUM_STRING.
      WHEN 'DAY08'.  ALV_LINE-DAY08 = NUM_STRING.
      WHEN 'DAY09'.  ALV_LINE-DAY09 = NUM_STRING.
      WHEN 'DAY10'.  ALV_LINE-DAY10 = NUM_STRING.
      WHEN 'DAY11'.  ALV_LINE-DAY11 = NUM_STRING.
      WHEN 'DAY12'.  ALV_LINE-DAY12 = NUM_STRING.
      WHEN 'DAY13'.  ALV_LINE-DAY13 = NUM_STRING.
      WHEN 'DAY14'.  ALV_LINE-DAY14 = NUM_STRING.

ENDCASE.

ENDFORM.
*&----------------------------------------------------*
*&      Form  MODIFY_DB_DATA
*&----------------------------------------------------*

FORM. MODIFY_DB_DATA USING    PP_GSTRP
                             PP_GAMNG.

  DATA: I_B(2) TYPE N.
  CLEAR: RESULT_DAY.
  I_B = PP_GSTRP - T_DATE + 1.
   CONCATENATE 'DAY' I_B INTO RESULT_DAY.
   NUM_STRING = PP_GAMNG.
   CASE RESULT_DAY.
    WHEN 'DAY01'.
       ALV_LINE-DAY01 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY01.
    WHEN 'DAY02'.
      ALV_LINE-DAY02 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY02.
    WHEN 'DAY03'.
       ALV_LINE-DAY03 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY03.

    WHEN 'DAY04'.
      ALV_LINE-DAY04 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY04.
    WHEN 'DAY05'.
      ALV_LINE-DAY05 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY05.
    WHEN 'DAY06'.
      ALV_LINE-DAY06 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY06.

    WHEN 'DAY07'.
      ALV_LINE-DAY07 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY07.
    WHEN 'DAY08'.
      ALV_LINE-DAY08 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY08.

    WHEN 'DAY09'.
      ALV_LINE-DAY09 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY09.
    WHEN 'DAY10'.
      ALV_LINE-DAY10 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY10.
    WHEN 'DAY11'.
      ALV_LINE-DAY11 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY11.

    WHEN 'DAY12'.
      ALV_LINE-DAY12 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY12.

    WHEN 'DAY13'.
      ALV_LINE-DAY13 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY13.

    WHEN 'DAY14'.
      ALV_LINE-DAY14 = NUM_STRING.
      MODIFY TABLE ALV_TAB FROM ALV_LINE TRANSPORTING DAY14.
  ENDCASE.

ENDFORM.


*&----------------------------------------------------*
*&      Form  DISPLAY_ALV_FORM
*&----------------------------------------------------*

FORM. DISPLAY_ALV_FORM.

  data: L_REPID LIKE SY-REPID.
  L_REPID = SY-REPID.
  SORT ALV_TAB BY  WERKS MATNR.
  call function 'REUSE_ALV_GRID_DISPLAY'
  exporting
    i_interface_check                 = ''
    i_callback_program                = L_REPID
    it_fieldcat                       = IT_FIELDCAT
    i_default                         = 'X'
    i_save                            = 'A'

   tables
     t_outtab                          = ALV_TAB
  exceptions
    program_error                     = 1
    others                            = 2 .
ENDFORM.
*--------------------------------------------------------------------------*
定义ZPP_MPS_SID的结构如下:
MANDT    MANDT    CLNT    3    0    Client
WERKS    WERKS_D    CHAR    4    0    Plant
MATNR    MATNR    CHAR    18    0    Material number
DAY01        CHAR    10    0    Reference Day01
DAY02        CHAR    10    0    Reference Day02
DAY03        CHAR    10    0    Reference Day03
DAY04        CHAR    10    0    Reference Day04
DAY05        CHAR    10    0    Reference Day05
DAY06        CHAR    10    0    Reference Day06
DAY07        CHAR    10    0    Reference Day07
DAY08        CHAR    10    0    Reference Day08
DAY09        CHAR    10    0    Reference Day09
DAY10        CHAR    10    0    Reference Day10
DAY11        CHAR    10    0    Reference Day11
DAY12        CHAR    10    0    Reference Day12
DAY13        CHAR    10    0    Reference Day13
DAY14        CHAR    10    0    Reference Day14



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15117617/viewspace-551898/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15117617/viewspace-551898/

你可能感兴趣的:(MPS报表)