• 历史库存查询(6月滚动)(动态列表的使用)(含日期F4的选择帮助)


    *&---------------------------------------------------------------------*
    *& Report ZPMRP031
    *&---------------------------------------------------------------------*
    *&历史库存查询6个月--Creat by Bruce King20191203
    *&---------------------------------------------------------------------*
    REPORT ZPMRP031.
    TABLES:MATDOC,S031.
    TYPES:BEGIN OF TY_DATA,
            BUKRS            TYPE MATDOC-BUKRS,        "公司
            WERKS            TYPE MATDOC-WERKS,        "工厂
            LGORT_SID        TYPE  MATDOC-LGORT_SID, "库位
            MATBF            TYPE MATDOC-MATBF,        "物料编码
            MAKTX            TYPE MAKT-MAKTX,          "物料描述
    *        CHARG_SID        TYPE MATDOC-CHARG_SID, "批次
            EISBE            LIKE MARC-EISBE, "基于工厂的安全库存  add by King 20191209
            MEINS            TYPE MATDOC-MEINS,        "基本单位
            YEARMONTH_BUDAT1 TYPE MATDOC-YEARMONTH_BUDAT, "年月
            MENGE1           TYPE  MATDOC-MENGE,       "月末结存数量
          END   OF TY_DATA.
    TYPES:BEGIN OF TY_DATA1,
            YEARMONTH_BUDAT1 TYPE MATDOC-YEARMONTH_BUDAT,
          END OF TY_DATA1.
    
    DATA:IT_TEMP TYPE STANDARD TABLE OF TY_DATA1,
         WA_TEMP TYPE TY_DATA1.
    DATA IT_DATA TYPE TABLE OF TY_DATA.
    DATA IT_DATA1 TYPE TABLE OF TY_DATA.
    DATA WA_DATA TYPE TY_DATA.
    DATA WA_DATA1 TYPE TY_DATA.
    "FIELD SYMBOLS
    FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,
                   <DYN_WA>,
                   <DYN_FIELD>.
    
    DATA:N TYPE I.
    DATA: IT_TABLE     TYPE REF TO DATA,
          IT_STRUCTURE TYPE LVC_T_FCAT,
          WA_STRUCTURE TYPE LVC_S_FCAT.
    DATA: WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
          IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
          POS         TYPE I,
          WA_LAYOUT   TYPE SLIS_LAYOUT_ALV,
          G_LAYOUT    TYPE LVC_S_LAYO.
    DATA: G_TITLE    TYPE LVC_TITLE.
    DATA:TEMP_DATE(8) TYPE N.
    DATA:L_ON_DATE_E TYPE P0001-BEGDA.
    DATA:D_MONTH TYPE P0001-BEGDA.
    DEFINE ADD_COL.
      CLEAR WA_FIELDCAT.
      ADD 1 TO POS.
      WA_FIELDCAT-COL_POS = POS.
      WA_FIELDCAT-FIELDNAME = &1.
      WA_FIELDCAT-REF_FIELDNAME = &2.
      WA_FIELDCAT-REF_TABNAME = &3.
      WA_FIELDCAT-SELTEXT_M = &4.
      WA_FIELDCAT-TABNAME = &5.
      WA_FIELDCAT-DO_SUM = &6.
      WA_FIELDCAT-INPUT = &7.
      WA_FIELDCAT-NO_ZERO = &8.
      WA_FIELDCAT-DECIMALS_OUT = &9.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
    END-OF-DEFINITION.
    
    DEFINE CHANGE_DATE. "用来转换日期 change by king 20200302
      CLEAR:TEMP_DATE,D_MONTH.
      D_MONTH = |{ &1 }01|.
      CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
      EXPORTING
        DATE      = D_MONTH "输入日期
        DAYS      = 0 "天数加N或者减N  不加也不减 写0
        MONTHS    = 1  "月份加N或者减N 不加也不减 写0
        SIGNUM    = '-' "可以是+或者-
        YEARS     = 0 "年份加N或者减N 不加也不减 写0
      IMPORTING
        CALC_DATE = L_ON_DATE_E. "得到加减之后的日期
      S_MONTH1 = L_ON_DATE_E(6) + 0. "取月份
    END-OF-DEFINITION.
    "选择屏幕定义
    SELECTION-SCREEN: BEGIN OF BLOCK A1 WITH FRAME TITLE TEXT-010.
    SELECT-OPTIONS:
      S_WERKS FOR MATDOC-WERKS OBLIGATORY,"工厂
      S_LGORT FOR MATDOC-LGORT_SID OBLIGATORY,"库存地
      S_MATNR FOR MATDOC-MATBF."物料编码
    PARAMETERS  S_MONTH1 TYPE S031-SPMON OBLIGATORY.     "月份
    SELECTION-SCREEN: END OF BLOCK A1.
    
    INITIALIZATION.
    
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_MONTH1.
      PERFORM MONAT_F4.
    
    START-OF-SELECTION.
      D_MONTH = |{ S_MONTH1 }01|.
      PERFORM FRM_GET_DATA1.
      CHANGE_DATE S_MONTH1.
      DATA(S_MONTH2) = S_MONTH1 .
      PERFORM FRM_GET_DATA2.
      CHANGE_DATE S_MONTH1.
      DATA(S_MONTH3) = S_MONTH1 .
      PERFORM FRM_GET_DATA3.
      CHANGE_DATE S_MONTH1.
      DATA(S_MONTH4) = S_MONTH1 .
      PERFORM FRM_GET_DATA4.
      CHANGE_DATE S_MONTH1.
      DATA(S_MONTH5) = S_MONTH1 .
      PERFORM FRM_GET_DATA5.
      CHANGE_DATE S_MONTH1.
      DATA(S_MONTH6) = S_MONTH1 .
      PERFORM FRM_GET_DATA6.
      PERFORM FRM_AUTHRITY_CHECK.
      PERFORM CREAT_STRUCTURE."创建内表结构
      PERFORM CREAT_TABLE."按照结构定义内表
      PERFORM DATA_TO_TABLE."写数据进内表
      PERFORM FRM_INIT_LAYOUT.
      PERFORM FRM_SHOW_ALV."内表数据展示
    
    FORM FRM_GET_DATA1.
      SELECT BUKRS,          "公司
             WERKS,          "工厂
             LGORT_SID,      "库位
             MATBF,          "物料编码
             MEINS,          "基本计量单位
             MENGE,          "月末结存数量
             YEARMONTH_BUDAT,"年月
             BSTTYP_SG,      "库存类别
    *         UMSOK_CID,       "特殊库存标识
    *         CHARG_SID,      "批次
             SHKZG           "借贷标识
        FROM MATDOC
        INTO TABLE @DATA(IT_MATDOC1)
        WHERE WERKS     IN @S_WERKS
          AND LGORT_SID IN @S_LGORT
          AND MATBF     IN @S_MATNR
      AND YEARMONTH_BUDAT <= @S_MONTH1.
    
      "降序排列
      REFRESH IT_DATA.
      SORT IT_MATDOC1 BY YEARMONTH_BUDAT ASCENDING.
      LOOP AT IT_MATDOC1 INTO DATA(WA) GROUP BY ( KEY1 = WA-BUKRS
          KEY2 = WA-WERKS    KEY3 = WA-LGORT_SID    KEY4 = WA-MATBF ) INTO DATA(KEY).
        WA_DATA-BUKRS           = KEY-KEY1.
        WA_DATA-WERKS           = KEY-KEY2.
        WA_DATA-LGORT_SID       = KEY-KEY3.
        WA_DATA-MATBF           = KEY-KEY4.
    *     WA_DATA-CHARG_SID       = KEY-KEY5.
        WA_DATA-YEARMONTH_BUDAT1 = S_MONTH1.
        LOOP AT GROUP KEY INTO DATA(WA_MATDOC1).
          IF WA_MATDOC1-SHKZG = 'H'.
            WA_MATDOC1-MENGE = 0 - WA_MATDOC1-MENGE.
          ENDIF.
          WA_DATA-MENGE1 = WA_DATA-MENGE1 + WA_MATDOC1-MENGE.
          WA_DATA-MEINS = WA_MATDOC1-MEINS.
        ENDLOOP.
        "获取物料描述
        SELECT SINGLE MAKTX
          FROM MAKT
          INTO WA_DATA-MAKTX
          WHERE MATNR = WA_DATA-MATBF
            AND SPRAS = SY-LANGU.
        SELECT SINGLE EISBE FROM MARC INTO WA_DATA-EISBE WHERE MATNR = WA_DATA-MATBF AND WERKS = WA_DATA-WERKS.
        WA_DATA-MATBF = |{ WA_DATA-MATBF ALPHA = OUT }|.
        APPEND WA_DATA TO IT_DATA.
        CLEAR  WA_DATA.
      ENDLOOP.
    ENDFORM.
    
    FORM FRM_GET_DATA2.
      SELECT BUKRS,          "公司
             WERKS,          "工厂
             MATBF,          "物料编码
             LGORT_SID,      "库位
             MEINS,          "基本计量单位
             MENGE,          "月末结存数量
             YEARMONTH_BUDAT,"年月
             BSTTYP_SG,      "库存类别
    *         UMSOK_CID,       "特殊库存标识
    *         CHARG_SID,      "批次
             SHKZG           "借贷标识
        FROM MATDOC
        INTO TABLE @DATA(IT_MATDOC2)
        WHERE WERKS     IN @S_WERKS
          AND LGORT_SID IN @S_LGORT
          AND MATBF     IN @S_MATNR
      AND YEARMONTH_BUDAT <= @S_MONTH2.
    
      "降序排列
      SORT IT_MATDOC2 BY YEARMONTH_BUDAT ASCENDING.
      LOOP AT IT_MATDOC2 INTO DATA(WA) GROUP BY ( KEY1 = WA-BUKRS
          KEY2 = WA-WERKS    KEY3 = WA-LGORT_SID    KEY4 = WA-MATBF ) INTO DATA(KEY).
        WA_DATA-BUKRS           = KEY-KEY1.
        WA_DATA-WERKS           = KEY-KEY2.
        WA_DATA-LGORT_SID       = KEY-KEY3.
        WA_DATA-MATBF           = KEY-KEY4.
    *     WA_DATA-CHARG_SID       = KEY-KEY5.
        WA_DATA-YEARMONTH_BUDAT1 = S_MONTH2.
        LOOP AT GROUP KEY INTO DATA(WA_MATDOC2).
          IF WA_MATDOC2-SHKZG = 'H'.
            WA_MATDOC2-MENGE = 0 - WA_MATDOC2-MENGE.
          ENDIF.
          WA_DATA-MENGE1 = WA_DATA-MENGE1 + WA_MATDOC2-MENGE.
          WA_DATA-MEINS = WA_MATDOC2-MEINS.
        ENDLOOP.
        "获取物料描述
        SELECT SINGLE MAKTX
          FROM MAKT
          INTO WA_DATA-MAKTX
          WHERE MATNR = WA_DATA-MATBF
            AND SPRAS = SY-LANGU.
        SELECT SINGLE EISBE FROM MARC INTO WA_DATA-EISBE WHERE MATNR = WA_DATA-MATBF AND WERKS = WA_DATA-WERKS.
        WA_DATA-MATBF = |{ WA_DATA-MATBF ALPHA = OUT }|.
        APPEND WA_DATA TO IT_DATA.
        CLEAR  WA_DATA.
      ENDLOOP.
    ENDFORM.
    FORM FRM_GET_DATA3.
      SELECT BUKRS,          "公司
             WERKS,          "工厂
             MATBF,          "物料编码
             LGORT_SID,      "库位
             MEINS,          "基本计量单位
             MENGE,          "月末结存数量
             YEARMONTH_BUDAT,"年月
             BSTTYP_SG,      "库存类别
    *         UMSOK_CID,       "特殊库存标识
    *         CHARG_SID,      "批次
             SHKZG           "借贷标识
        FROM MATDOC
        INTO TABLE @DATA(IT_MATDOC3)
        WHERE WERKS     IN @S_WERKS
          AND LGORT_SID IN @S_LGORT
          AND MATBF     IN @S_MATNR
      AND YEARMONTH_BUDAT <= @S_MONTH3.
    
      "降序排列
      SORT IT_MATDOC3 BY YEARMONTH_BUDAT ASCENDING.
      LOOP AT IT_MATDOC3 INTO DATA(WA) GROUP BY ( KEY1 = WA-BUKRS
          KEY2 = WA-WERKS    KEY3 = WA-LGORT_SID    KEY4 = WA-MATBF ) INTO DATA(KEY).
        WA_DATA-BUKRS           = KEY-KEY1.
        WA_DATA-WERKS           = KEY-KEY2.
        WA_DATA-LGORT_SID       = KEY-KEY3.
        WA_DATA-MATBF           = KEY-KEY4.
    *     WA_DATA-CHARG_SID       = KEY-KEY5.
        WA_DATA-YEARMONTH_BUDAT1 = S_MONTH3.
        LOOP AT GROUP KEY INTO DATA(WA_MATDOC3).
          IF WA_MATDOC3-SHKZG = 'H'.
            WA_MATDOC3-MENGE = 0 - WA_MATDOC3-MENGE.
          ENDIF.
          WA_DATA-MENGE1 = WA_DATA-MENGE1 + WA_MATDOC3-MENGE.
          WA_DATA-MEINS = WA_MATDOC3-MEINS.
        ENDLOOP.
        "获取物料描述
        SELECT SINGLE MAKTX
          FROM MAKT
          INTO WA_DATA-MAKTX
          WHERE MATNR = WA_DATA-MATBF
            AND SPRAS = SY-LANGU.
        SELECT SINGLE EISBE FROM MARC INTO WA_DATA-EISBE WHERE MATNR = WA_DATA-MATBF AND WERKS = WA_DATA-WERKS.
        WA_DATA-MATBF = |{ WA_DATA-MATBF ALPHA = OUT }|.
        APPEND WA_DATA TO IT_DATA.
        CLEAR  WA_DATA.
      ENDLOOP.
    ENDFORM.
    FORM FRM_GET_DATA4.
      SELECT BUKRS,          "公司
             WERKS,          "工厂
             MATBF,          "物料编码
             LGORT_SID,      "库位
             MEINS,          "基本计量单位
             MENGE,          "月末结存数量
             YEARMONTH_BUDAT,"年月
             BSTTYP_SG,      "库存类别
    *         UMSOK_CID,       "特殊库存标识
    *         CHARG_SID,      "批次
             SHKZG           "借贷标识
        FROM MATDOC
        INTO TABLE @DATA(IT_MATDOC4)
        WHERE WERKS     IN @S_WERKS
          AND LGORT_SID IN @S_LGORT
          AND MATBF     IN @S_MATNR
      AND YEARMONTH_BUDAT <= @S_MONTH4.
    
      "降序排列
      SORT IT_MATDOC4 BY YEARMONTH_BUDAT ASCENDING.
      LOOP AT IT_MATDOC4 INTO DATA(WA) GROUP BY ( KEY1 = WA-BUKRS
          KEY2 = WA-WERKS    KEY3 = WA-LGORT_SID    KEY4 = WA-MATBF ) INTO DATA(KEY).
        WA_DATA-BUKRS           = KEY-KEY1.
        WA_DATA-WERKS           = KEY-KEY2.
        WA_DATA-LGORT_SID       = KEY-KEY3.
        WA_DATA-MATBF           = KEY-KEY4.
    *     WA_DATA-CHARG_SID       = KEY-KEY5.
        WA_DATA-YEARMONTH_BUDAT1 = S_MONTH4.
        LOOP AT GROUP KEY INTO DATA(WA_MATDOC4).
          IF WA_MATDOC4-SHKZG = 'H'.
            WA_MATDOC4-MENGE = 0 - WA_MATDOC4-MENGE.
          ENDIF.
          WA_DATA-MENGE1 = WA_DATA-MENGE1 + WA_MATDOC4-MENGE.
          WA_DATA-MEINS = WA_MATDOC4-MEINS.
        ENDLOOP.
        "获取物料描述
        SELECT SINGLE MAKTX
          FROM MAKT
          INTO WA_DATA-MAKTX
          WHERE MATNR = WA_DATA-MATBF
            AND SPRAS = SY-LANGU.
        SELECT SINGLE EISBE FROM MARC INTO WA_DATA-EISBE WHERE MATNR = WA_DATA-MATBF AND WERKS = WA_DATA-WERKS.
        WA_DATA-MATBF = |{ WA_DATA-MATBF ALPHA = OUT }|.
        APPEND WA_DATA TO IT_DATA.
        CLEAR  WA_DATA.
      ENDLOOP.
    ENDFORM.
    FORM FRM_GET_DATA5.
      SELECT BUKRS,          "公司
             WERKS,          "工厂
             MATBF,          "物料编码
             LGORT_SID,      "库位
             MEINS,          "基本计量单位
             MENGE,          "月末结存数量
             YEARMONTH_BUDAT,"年月
             BSTTYP_SG,      "库存类别
    *         UMSOK_CID,       "特殊库存标识
    *         CHARG_SID,      "批次
             SHKZG           "借贷标识
        FROM MATDOC
        INTO TABLE @DATA(IT_MATDOC5)
        WHERE WERKS     IN @S_WERKS
          AND LGORT_SID IN @S_LGORT
          AND MATBF     IN @S_MATNR
      AND YEARMONTH_BUDAT <= @S_MONTH5.
    
      "降序排列
      SORT IT_MATDOC5 BY YEARMONTH_BUDAT ASCENDING.
      LOOP AT IT_MATDOC5 INTO DATA(WA) GROUP BY ( KEY1 = WA-BUKRS
          KEY2 = WA-WERKS    KEY3 = WA-LGORT_SID    KEY4 = WA-MATBF ) INTO DATA(KEY).
        WA_DATA-BUKRS           = KEY-KEY1.
        WA_DATA-WERKS           = KEY-KEY2.
        WA_DATA-LGORT_SID       = KEY-KEY3.
        WA_DATA-MATBF           = KEY-KEY4.
    *     WA_DATA-CHARG_SID       = KEY-KEY5.
        WA_DATA-YEARMONTH_BUDAT1 = S_MONTH5.
        LOOP AT GROUP KEY INTO DATA(WA_MATDOC5).
          IF WA_MATDOC5-SHKZG = 'H'.
            WA_MATDOC5-MENGE = 0 - WA_MATDOC5-MENGE.
          ENDIF.
          WA_DATA-MENGE1 = WA_DATA-MENGE1 + WA_MATDOC5-MENGE.
          WA_DATA-MEINS = WA_MATDOC5-MEINS.
        ENDLOOP.
        "获取物料描述
        SELECT SINGLE MAKTX
          FROM MAKT
          INTO WA_DATA-MAKTX
          WHERE MATNR = WA_DATA-MATBF
            AND SPRAS = SY-LANGU.
        SELECT SINGLE EISBE FROM MARC INTO WA_DATA-EISBE WHERE MATNR = WA_DATA-MATBF AND WERKS = WA_DATA-WERKS.
        WA_DATA-MATBF = |{ WA_DATA-MATBF ALPHA = OUT }|.
        APPEND WA_DATA TO IT_DATA.
        CLEAR  WA_DATA.
      ENDLOOP.
    ENDFORM.
    FORM FRM_GET_DATA6.
      SELECT BUKRS,          "公司
             WERKS,          "工厂
             MATBF,          "物料编码
             LGORT_SID,      "库位
             MEINS,          "基本计量单位
             MENGE,          "月末结存数量
             YEARMONTH_BUDAT,"年月
             BSTTYP_SG,      "库存类别
    *         UMSOK_CID,       "特殊库存标识
    *         CHARG_SID,      "批次
             SHKZG           "借贷标识
        FROM MATDOC
        INTO TABLE @DATA(IT_MATDOC6)
        WHERE WERKS     IN @S_WERKS
          AND LGORT_SID IN @S_LGORT
          AND MATBF     IN @S_MATNR
      AND YEARMONTH_BUDAT <= @S_MONTH6.
    
      "降序排列
      SORT IT_MATDOC6 BY YEARMONTH_BUDAT ASCENDING.
      LOOP AT IT_MATDOC6 INTO DATA(WA) GROUP BY ( KEY1 = WA-BUKRS
          KEY2 = WA-WERKS    KEY3 = WA-LGORT_SID    KEY4 = WA-MATBF ) INTO DATA(KEY).
        WA_DATA-BUKRS           = KEY-KEY1.
        WA_DATA-WERKS           = KEY-KEY2.
        WA_DATA-LGORT_SID       = KEY-KEY3.
        WA_DATA-MATBF           = KEY-KEY4.
    *     WA_DATA-CHARG_SID       = KEY-KEY5.
        WA_DATA-YEARMONTH_BUDAT1 = S_MONTH6.
        LOOP AT GROUP KEY INTO DATA(WA_MATDOC6).
          IF WA_MATDOC6-SHKZG = 'H'.
            WA_MATDOC6-MENGE = 0 - WA_MATDOC6-MENGE.
          ENDIF.
          WA_DATA-MENGE1 = WA_DATA-MENGE1 + WA_MATDOC6-MENGE.
          WA_DATA-MEINS = WA_MATDOC6-MEINS.
        ENDLOOP.
        "获取物料描述
        SELECT SINGLE MAKTX
          FROM MAKT
          INTO WA_DATA-MAKTX
          WHERE MATNR = WA_DATA-MATBF
            AND SPRAS = SY-LANGU.
        SELECT SINGLE EISBE FROM MARC INTO WA_DATA-EISBE WHERE MATNR = WA_DATA-MATBF AND WERKS = WA_DATA-WERKS.
        WA_DATA-MATBF = |{ WA_DATA-MATBF ALPHA = OUT }|.
        APPEND WA_DATA TO IT_DATA.
        CLEAR  WA_DATA.
      ENDLOOP.
    ENDFORM.
    
    FORM FRM_AUTHRITY_CHECK .
      LOOP AT IT_DATA INTO DATA(WA1).
        "排除没有权限的数据
        AUTHORITY-CHECK OBJECT 'EDO_BUK'
                 ID 'BUKRS' FIELD WA1-BUKRS.
        IF SY-SUBRC <> 0.
          DELETE IT_DATA.
        ENDIF.
        CLEAR WA1.
      ENDLOOP.
    ENDFORM.
    
    FORM L_STATUS100 USING EXTAB TYPE SLIS_T_EXTAB.
      SET  PF-STATUS  'STANDARD'.
    ENDFORM.
    
    FORM FRM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM RS_SELFIELD TYPE SLIS_SELFIELD.
      DATA: REF TYPE REF TO CL_GUI_ALV_GRID.
      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
        IMPORTING
          E_GRID = REF.
      CALL METHOD REF->CHECK_CHANGED_DATA.
      RS_SELFIELD-REFRESH = 'X'.
    ENDFORM.
    
    FORM MONAT_F4 .
      DATA: BEGIN OF MF_DYNPFIELDS OCCURS 1.
          INCLUDE STRUCTURE DYNPREAD.
      DATA: END   OF MF_DYNPFIELDS.
      DATA: MF_RETURNCODE LIKE SY-SUBRC,
            MF_MONAT      LIKE ISELLIST-MONTH,
            MF_HLP_REPID  LIKE SY-REPID.
      FIELD-SYMBOLS: <MF_FELD>.
    
      GET CURSOR FIELD MF_DYNPFIELDS-FIELDNAME.
      APPEND MF_DYNPFIELDS.
      MF_HLP_REPID = SY-REPID.
      DO 2 TIMES.
        CALL FUNCTION 'DYNP_VALUES_READ'
          EXPORTING
            DYNAME               = MF_HLP_REPID
            DYNUMB               = SY-DYNNR
          TABLES
            DYNPFIELDS           = MF_DYNPFIELDS
          EXCEPTIONS
            INVALID_ABAPWORKAREA = 01
            INVALID_DYNPROFIELD  = 02
            INVALID_DYNPRONAME   = 03
            INVALID_DYNPRONUMMER = 04
            INVALID_REQUEST      = 05
            NO_FIELDDESCRIPTION  = 06
            UNDEFIND_ERROR       = 07.
        IF SY-SUBRC = 3.
          MF_HLP_REPID = 'SAPLALDB'.
        ELSE.
          READ TABLE MF_DYNPFIELDS INDEX 1.
          TRANSLATE MF_DYNPFIELDS-FIELDVALUE USING '_ '.
          EXIT.
        ENDIF.
      ENDDO.
      IF SY-SUBRC = 0.
        CALL FUNCTION 'CONVERSION_EXIT_PERI_INPUT'
          EXPORTING
            INPUT         = MF_DYNPFIELDS-FIELDVALUE
          IMPORTING
            OUTPUT        = MF_MONAT
          EXCEPTIONS
            ERROR_MESSAGE = 1.
        IF MF_MONAT IS INITIAL.
          MF_MONAT = SY-DATLO(6).
        ENDIF.
        CALL FUNCTION 'POPUP_TO_SELECT_MONTH'
          EXPORTING
            ACTUAL_MONTH               = MF_MONAT
          IMPORTING
            SELECTED_MONTH             = MF_MONAT
            RETURN_CODE                = MF_RETURNCODE
          EXCEPTIONS
            FACTORY_CALENDAR_NOT_FOUND = 01
            HOLIDAY_CALENDAR_NOT_FOUND = 02
            MONTH_NOT_FOUND            = 03.
        IF SY-SUBRC = 0 AND MF_RETURNCODE = 0.
          CALL FUNCTION 'CONVERSION_EXIT_PERI_OUTPUT'
            EXPORTING
              INPUT  = MF_MONAT
            IMPORTING
              OUTPUT = MF_DYNPFIELDS-FIELDVALUE.
          COLLECT MF_DYNPFIELDS.
          CALL FUNCTION 'DYNP_VALUES_UPDATE'
            EXPORTING
              DYNAME               = MF_HLP_REPID
              DYNUMB               = SY-DYNNR
            TABLES
              DYNPFIELDS           = MF_DYNPFIELDS
            EXCEPTIONS
              INVALID_ABAPWORKAREA = 01
              INVALID_DYNPROFIELD  = 02
              INVALID_DYNPRONAME   = 03
              INVALID_DYNPRONUMMER = 04
              INVALID_REQUEST      = 05
              NO_FIELDDESCRIPTION  = 06
              UNDEFIND_ERROR       = 07.
        ENDIF.
      ENDIF.
    ENDFORM.
    
    FORM CREAT_STRUCTURE.
      DATA: L_LINES TYPE I.
      LOOP AT IT_DATA INTO WA_DATA.
        MOVE-CORRESPONDING WA_DATA TO WA_TEMP.
        APPEND WA_TEMP TO IT_TEMP.
      ENDLOOP.
      SORT IT_TEMP BY YEARMONTH_BUDAT1 ASCENDING.
      DELETE ADJACENT DUPLICATES FROM IT_TEMP COMPARING YEARMONTH_BUDAT1.
      SORT IT_TEMP BY YEARMONTH_BUDAT1 .
      DESCRIBE TABLE IT_TEMP LINES N.
      L_LINES = 8.
    * 创建静态结构部分
      PERFORM FRM_ALV_FCAT_SET USING:
        1   'BUKRS' TEXT-007 'BUKRS'  'MSEG'  SPACE   SPACE,
        2   'WERKS' TEXT-007 'WERKS'  'MSEG'  SPACE   SPACE,
        3   'LGORT_SID' TEXT-008 'LGORT'  'MSEG'  SPACE   SPACE,
        4   'MATBF' TEXT-008 'MATNR'  'MAKT'  SPACE   SPACE,
        5   'MAKTX' TEXT-008 'MAKTX'  'MAKT'  SPACE   SPACE,
        6   'EISBE' TEXT-008 'EISBE'  'MARC'  SPACE   SPACE,
        7   'MEINS' TEXT-008 'MEINS'  'MARA'  SPACE   SPACE.
      LOOP AT IT_TEMP INTO WA_TEMP.
    *    DO N TIMES.
        CLEAR WA_STRUCTURE.
    *字段名称
        WA_STRUCTURE-FIELDNAME = WA_TEMP-YEARMONTH_BUDAT1.
    *列名称
    *    CONCATENATE '移动类型' WA_DATA2-BWART INTO WA_STRUCTURE-SCRTEXT_L.
        WA_STRUCTURE-SCRTEXT_L = WA_TEMP-YEARMONTH_BUDAT1.
        WA_STRUCTURE-SCRTEXT_M = WA_STRUCTURE-SCRTEXT_L.
        WA_STRUCTURE-SCRTEXT_S = WA_STRUCTURE-SCRTEXT_L.
        WA_STRUCTURE-COLTEXT   = WA_STRUCTURE-SCRTEXT_L.
        WA_STRUCTURE-NO_ZERO   = 'X'.
        WA_STRUCTURE-DO_SUM    = ''.
        WA_STRUCTURE-REF_FIELD = 'MENGE'.
        WA_STRUCTURE-REF_TABLE = 'EKPO'.
        WA_STRUCTURE-COL_POS    = L_LINES.
        APPEND WA_STRUCTURE TO IT_STRUCTURE.
        L_LINES = L_LINES + 1.
      ENDLOOP.
    ENDFORM.
    FORM CREAT_TABLE.
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG = IT_STRUCTURE
        IMPORTING
          EP_TABLE        = IT_TABLE.
      ASSIGN IT_TABLE->* TO <DYN_TABLE>.
    ENDFORM.
    FORM DATA_TO_TABLE.
      DATA:WA_NEW_LINE TYPE REF TO DATA.
      CREATE DATA WA_NEW_LINE LIKE LINE OF <DYN_TABLE>.
      ASSIGN WA_NEW_LINE->* TO <DYN_WA>.
      DATA:L_FIELDNAME TYPE LVC_S_FCAT-FIELDNAME.
      DATA:LW_ERFMG TYPE TY_DATA.
      SORT IT_DATA BY BUKRS WERKS LGORT_SID MATBF.
      LOOP AT IT_DATA INTO WA_DATA.
        CLEAR:L_FIELDNAME.
        L_FIELDNAME = WA_DATA-YEARMONTH_BUDAT1.
        ASSIGN COMPONENT L_FIELDNAME OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
        <DYN_FIELD> = WA_DATA-MENGE1.
        LW_ERFMG = WA_DATA.
        AT END OF MATBF.  "会将of后面的字段及其左边的字段变化时运行下面的代码块
          ASSIGN COMPONENT 'BUKRS' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>. "将固定的字段一一列出
          <DYN_FIELD> = LW_ERFMG-BUKRS.
          ASSIGN COMPONENT 'WERKS' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
          <DYN_FIELD> = LW_ERFMG-WERKS.
          ASSIGN COMPONENT 'LGORT_SID' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
          <DYN_FIELD> = LW_ERFMG-LGORT_SID.
          ASSIGN COMPONENT 'MATBF' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
          <DYN_FIELD> = LW_ERFMG-MATBF.
          ASSIGN COMPONENT 'MAKTX' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
          <DYN_FIELD> = LW_ERFMG-MAKTX.
          ASSIGN COMPONENT 'EISBE' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
          <DYN_FIELD> = LW_ERFMG-EISBE.
          ASSIGN COMPONENT 'MEINS' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
          <DYN_FIELD> = LW_ERFMG-MEINS.
          APPEND <DYN_WA> TO <DYN_TABLE>.
          CLEAR: <DYN_WA>.
        ENDAT.
        CLEAR: LW_ERFMG, WA_DATA1.
      ENDLOOP.
    *  DELETE <DYN_TABLE> WHERE MATNR IS INITIAL.
    ENDFORM.
    *设置layout属性
    FORM FRM_INIT_LAYOUT .
      G_TITLE = TEXT-006.
      CLEAR WA_LAYOUT.
      G_LAYOUT-CWIDTH_OPT = 'X'.
    ENDFORM.                    " FRM_INIT_LAYOUT
    
    FORM FRM_SHOW_ALV.
    *  * ALV显示函数
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          I_CALLBACK_PROGRAM = SY-REPID
          IS_LAYOUT_LVC      = G_LAYOUT
          IT_FIELDCAT_LVC    = IT_STRUCTURE
          I_GRID_TITLE       = G_TITLE
    *     i_callback_pf_status_set = 'PF_STATUS_SET'
    *     IT_EXCLUDING       =       "系统自带STATUS图标控制内表
          I_SAVE             = 'A'
    *     i_callback_pf_status_set = 'PF_STATUS_SET'
    *     i_callback_user_command  = 'FRM_USER_COMMAND'
        TABLES
          T_OUTTAB           = <DYN_TABLE>
        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.
    FORM FRM_ALV_FCAT_SET USING PU_POS    TYPE I
                                PU_FNAME  TYPE C
                                PU_FTEXT  TYPE C
                                PU_RFIELD TYPE C
                                PU_RTABLE TYPE C
                                PU_QNAME  TYPE C
                                PU_EDIT   TYPE C.
      CLEAR WA_STRUCTURE.
      WA_STRUCTURE-COL_POS    = PU_POS.
      WA_STRUCTURE-FIELDNAME  = PU_FNAME.
      WA_STRUCTURE-SCRTEXT_L  = PU_FTEXT.
      WA_STRUCTURE-SCRTEXT_M  = PU_FTEXT.
      WA_STRUCTURE-SCRTEXT_S  = PU_FTEXT.
      WA_STRUCTURE-REF_FIELD  = PU_RFIELD.
      WA_STRUCTURE-REF_TABLE  = PU_RTABLE.
      WA_STRUCTURE-QFIELDNAME = PU_QNAME.
      WA_STRUCTURE-EDIT       = PU_EDIT.
      WA_STRUCTURE-KEY = 'X'.
      APPEND WA_STRUCTURE TO IT_STRUCTURE.
    ENDFORM.                    " FRM_ALV_FCAT_S

  • 相关阅读:
    SharePoint 2019
    SharePoint 2019 图文安装教程
    SharePoint 2016 服务器部署(七)SharePoint 和OOS 集成
    如何将域中的AD数据导入SharePoint
    SharePoint 2016 图文安装教程 后面有激活序列号、密钥分享
    Github上优秀的.NET Core项目
    SQL Server删除/创建复制订阅失败,报15517错误问题的处理
    vue-devtools 开发工具的安装
    laravel 查询数据toArray内层无法转换的问题
    KindEditor 增加html标签
  • 原文地址:https://www.cnblogs.com/BruceKing/p/11988145.html
Copyright © 2020-2023  润新知