开发笔记-销售预测分析报表

*&---------------------------------------------------------------------*
*& Report ZSDR036
*&---------------------------------------------------------------------*
*& Author              :  NathanSun
*& Create Date         :  2020-02-21
*& Program Type        :  Report
*& Description         :  销售预测分析报表(20210608)
*&---------------------------------------------------------------------*
REPORT ZSDR036C.

*&---------------------------------------------------------------------*
*& 包含               YN_TEST02_TOP
*&---------------------------------------------------------------------*
TABLES:PBIM,KNA1,MARA,MARC,VBAP,MATDOC,ZTMM03,STPO.

TYPE-POOLS:SLIS.

"定义ALV输出所需变量
DATA: S_LAYOUT    TYPE SLIS_LAYOUT_ALV,
      GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: IW_CELLCOLOR TYPE LVC_T_SCOL WITH HEADER LINE.

DATA: BEGIN OF ITAB OCCURS 0 ,
        ZENNR LIKE ZTMM04-ZENNR,
        UNAME LIKE ZTMM04-UNAME,
      END OF ITAB.
DATA: RETURN_TAB TYPE DDSHRETVAL OCCURS 0 .

TYPES: BEGIN OF GTS_TEXT,
         TEXT1   TYPE DD03P-SCRTEXT_L,
         TEXT2   TYPE DD03P-SCRTEXT_L,
         TEXT3   TYPE DD03P-SCRTEXT_L,
         TEXT4   TYPE DD03P-SCRTEXT_L,
         TEXT5   TYPE DD03P-SCRTEXT_L,
         TEXT6   TYPE DD03P-SCRTEXT_L,
         TEXT7   TYPE DD03P-SCRTEXT_L,
         TEXT8   TYPE DD03P-SCRTEXT_L,
         TEXT9   TYPE DD03P-SCRTEXT_L,
         TEXT10  TYPE DD03P-SCRTEXT_L,
         TEXT11  TYPE DD03P-SCRTEXT_L,
         TEXT12  TYPE DD03P-SCRTEXT_L,

         CTEXT1  TYPE DD03P-SCRTEXT_L,
         CTEXT2  TYPE DD03P-SCRTEXT_L,
         CTEXT3  TYPE DD03P-SCRTEXT_L,
         CTEXT4  TYPE DD03P-SCRTEXT_L,
         CTEXT5  TYPE DD03P-SCRTEXT_L,
         CTEXT6  TYPE DD03P-SCRTEXT_L,
         CTEXT7  TYPE DD03P-SCRTEXT_L,
         CTEXT8  TYPE DD03P-SCRTEXT_L,
         CTEXT9  TYPE DD03P-SCRTEXT_L,
         CTEXT10 TYPE DD03P-SCRTEXT_L,
         CTEXT11 TYPE DD03P-SCRTEXT_L,
         CTEXT12 TYPE DD03P-SCRTEXT_L,

         TEXTA1  TYPE DD03P-SCRTEXT_L,
         TEXTA2  TYPE DD03P-SCRTEXT_L,
         TEXTA3  TYPE DD03P-SCRTEXT_L,
         TEXTA4  TYPE DD03P-SCRTEXT_L,
         TEXTA5  TYPE DD03P-SCRTEXT_L,
         TEXTA6  TYPE DD03P-SCRTEXT_L,

         CTEXTA1 TYPE DD03P-SCRTEXT_L,
         CTEXTA2 TYPE DD03P-SCRTEXT_L,
         CTEXTA3 TYPE DD03P-SCRTEXT_L,
         CTEXTA4 TYPE DD03P-SCRTEXT_L,
         CTEXTA5 TYPE DD03P-SCRTEXT_L,
         CTEXTA6 TYPE DD03P-SCRTEXT_L,

         ZCYJE1  TYPE DD03P-SCRTEXT_L,
         ZCYJE2  TYPE DD03P-SCRTEXT_L,
         ZCYJE3  TYPE DD03P-SCRTEXT_L,
         ZCYJE4  TYPE DD03P-SCRTEXT_L,
         ZCYJE5  TYPE DD03P-SCRTEXT_L,
         ZCYJE6  TYPE DD03P-SCRTEXT_L,

         ZCYBL1  TYPE DD03P-SCRTEXT_L,
         ZCYBL2  TYPE DD03P-SCRTEXT_L,
         ZCYBL3  TYPE DD03P-SCRTEXT_L,
         ZCYBL4  TYPE DD03P-SCRTEXT_L,
         ZCYBL5  TYPE DD03P-SCRTEXT_L,
         ZCYBL6  TYPE DD03P-SCRTEXT_L,

         PERXX1  TYPE PBED-PERXX,
         PERXX2  TYPE PBED-PERXX,
         PERXX3  TYPE PBED-PERXX,
         PERXX4  TYPE PBED-PERXX,
         PERXX5  TYPE PBED-PERXX,
         PERXX6  TYPE PBED-PERXX,
         PERXX7  TYPE PBED-PERXX,
         PERXX8  TYPE PBED-PERXX,
         PERXX9  TYPE PBED-PERXX,
         PERXX10 TYPE PBED-PERXX,
         PERXX11 TYPE PBED-PERXX,
         PERXX12 TYPE PBED-PERXX,

       END OF GTS_TEXT.
DATA: LV_TEXT TYPE GTS_TEXT.
DATA: LV_FIELDNAME TYPE CHAR20.
DATA: LV_FIELDNAME1 TYPE CHAR10.
DATA: LV_FIELDNAME2 TYPE CHAR10.
DATA: LV_FIELDNAME3 TYPE CHAR10.
DATA: LV_FIELDNAME4 TYPE CHAR10.
DATA: LV_FIELDNAME5 TYPE CHAR10.
DATA: LV_FIELDNAME6 TYPE CHAR10.
DATA: LV_ZTMM09 TYPE ZTMM09.

TYPES: BEGIN OF GTS_DATA,
         FLAGE     TYPE I,                  "   排序

         PBDNR_YC  TYPE CHAR30,             "   销售预测版本
         PBDNR     TYPE PBIM-PBDNR,         "   需求计划版本
         KUNNR     TYPE KNA1-KUNNR,         "   客户编码
         KATR1     TYPE KNA1-KATR1,         "   属性1
         NAME1     TYPE KNA1-NAME1,         "   客户名称
         NAME2     TYPE KNA1-NAME2,         "   客户名称
         NAME      TYPE CHAR100,            "   客户名称
         KDGRP     TYPE KNVV-KDGRP,         "   客户组
         KTEXT     TYPE T151T-KTEXT,        "   客户组
         BZIRK     TYPE KNVV-BZIRK,         "   销售区域
         BZTXT     TYPE T171T-BZTXT,        "   销售区域
         OEMODM    TYPE ZTPIRIMPLOG-OEMODM, "   ODM/OEM/NEW
         EXTWG     TYPE MARA-EXTWG,         "   系列
         MATNR     TYPE MARA-MATNR,         "   物料编码
         MAKTX     TYPE MAKT-MAKTX,         "   物料名称
         KDMAT     TYPE KNMT-KDMAT,         "   客户物料编码
         WERKS     TYPE ZTPIRIMPLOG-WERKS,  "   销售工厂
         ERSDA     TYPE ZTPIRIMPLOG-ERSDA,  "   创建日期
         WERKS_SC  TYPE MARC-WERKS,         "   生产工厂
         BUKRS_SC  TYPE T001K-BUKRS,        "   生产公司
         KBETR     TYPE ZWSDJ,              "   销售单价
         KONWA     TYPE KONP-KONWA,         "   币别
         KMEIN     TYPE KONP-KMEIN,         "   单位
         KBETR_CN  TYPE ZWSDJ,              "   CNY销售单价
         L_RATE    TYPE P DECIMALS 4,       "   兑换RMB汇率

         PLNMG1    TYPE ZTPIRIMPLOG-PLNMG,  "   数量1
         PLNMG2    TYPE ZTPIRIMPLOG-PLNMG,  "   数量2
         PLNMG3    TYPE ZTPIRIMPLOG-PLNMG,  "   数量3
         PLNMG4    TYPE ZTPIRIMPLOG-PLNMG,  "   数量4
         PLNMG5    TYPE ZTPIRIMPLOG-PLNMG,  "   数量5
         PLNMG6    TYPE ZTPIRIMPLOG-PLNMG,  "   数量6
         PLNMG7    TYPE ZTPIRIMPLOG-PLNMG,  "   数量7
         PLNMG8    TYPE ZTPIRIMPLOG-PLNMG,  "   数量8
         PLNMG9    TYPE ZTPIRIMPLOG-PLNMG,  "   数量9
         PLNMG10   TYPE ZTPIRIMPLOG-PLNMG,  "   数量10
         PLNMG11   TYPE ZTPIRIMPLOG-PLNMG,  "   数量11
         PLNMG12   TYPE ZTPIRIMPLOG-PLNMG,  "   数量12

         KBETR1    TYPE ZCURR3,             "   金额1
         KBETR2    TYPE ZCURR3,             "   金额2
         KBETR3    TYPE ZCURR3,             "   金额3
         KBETR4    TYPE ZCURR3,             "   金额4
         KBETR5    TYPE ZCURR3,             "   金额5
         KBETR6    TYPE ZCURR3,             "   金额6
         KBETR7    TYPE ZCURR3,             "   金额7
         KBETR8    TYPE ZCURR3,             "   金额8
         KBETR9    TYPE ZCURR3,             "   金额9
         KBETR10   TYPE ZCURR3,             "   金额10
         KBETR11   TYPE ZCURR3,             "   金额11
         KBETR12   TYPE ZCURR3,             "   金额12

         PLNMGA1   TYPE ZTPIRIMPLOG-PLNMG,  "   数量1
         PLNMGA2   TYPE ZTPIRIMPLOG-PLNMG,  "   数量2
         PLNMGA3   TYPE ZTPIRIMPLOG-PLNMG,  "   数量3
         PLNMGA4   TYPE ZTPIRIMPLOG-PLNMG,  "   数量4
         PLNMGA5   TYPE ZTPIRIMPLOG-PLNMG,  "   数量5
         PLNMGA6   TYPE ZTPIRIMPLOG-PLNMG,  "   数量6

         KBETRA1   TYPE ZCURR3,             "   金额1
         KBETRA2   TYPE ZCURR3,             "   金额2
         KBETRA3   TYPE ZCURR3,             "   金额3
         KBETRA4   TYPE ZCURR3,             "   金额4
         KBETRA5   TYPE ZCURR3,             "   金额5
         KBETRA6   TYPE ZCURR3,             "   金额6

         ZCYJE1    TYPE ZCURR3  ,           "   差异金额1
         ZCYJE2    TYPE ZCURR3  ,           "   差异金额2
         ZCYJE3    TYPE ZCURR3  ,           "   差异金额3
         ZCYJE4    TYPE ZCURR3  ,           "   差异金额4
         ZCYJE5    TYPE ZCURR3  ,           "   差异金额5
         ZCYJE6    TYPE ZCURR3  ,           "   差异金额6

         ZCYBL1    TYPE CHAR20  ,           "   差异比例1
         ZCYBL2    TYPE CHAR20  ,           "   差异比例2
         ZCYBL3    TYPE CHAR20  ,           "   差异比例3
         ZCYBL4    TYPE CHAR20  ,           "   差异比例4
         ZCYBL5    TYPE CHAR20  ,           "   差异比例5
         ZCYBL6    TYPE CHAR20  ,           "   差异比例6

         CELLCOLOR TYPE  LVC_T_SCOL,        "   单元格颜色
       END OF GTS_DATA.

DATA: LV_DATUMH TYPE DATUM .
DATA: LV_DATUML TYPE DATUM .
DATA: LV_DATUMU TYPE DATUM .
DATA: LV_DATUMD TYPE DATUM .
DATA: LV_DATUMN TYPE DATUM .

DATA: LV_PERXXL TYPE PBED-PERXX .
DATA: LV_PERXXH TYPE PBED-PERXX .
DATA: LV_PERXX  TYPE PBED-PERXX .

DATA: LV_YEARL TYPE NUMC4 .
DATA: LV_YEARN TYPE NUMC4 .
DATA: LV_POPEL TYPE POPER .
DATA: LV_POPEN TYPE POPER .
DATA: LV_DYTS  TYPE CHAR3 .

DATA: GT_DATA   TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_A TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_B TYPE TABLE OF GTS_DATA WITH HEADER LINE.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS P_RD1 RADIOBUTTON GROUP GP1 DEFAULT 'X' USER-COMMAND MXX."用来显示 p_AUFNR
PARAMETERS P_RD2 RADIOBUTTON GROUP GP1 ."用来隐藏 p_AUFNR
*-------------------------------------------------------------------------------------------------C1
SELECT-OPTIONS: S_PBDNR  FOR  PBIM-PBDNR  MODIF ID C1.                                   "  需求计划版本
SELECT-OPTIONS: S_KUNNR  FOR  KNA1-KUNNR  MODIF ID C1.                                   "  客户编码
SELECT-OPTIONS: S_EXTWG  FOR  MARA-EXTWG  MODIF ID C1.                                   "  系列
SELECT-OPTIONS: S_MATNR  FOR  MARA-MATNR  MODIF ID C1.                                   "  物料编码
SELECT-OPTIONS: S_WERKS  FOR  MARC-WERKS  MODIF ID C1.                                   "  工厂
*-------------------------------------------------------------------------------------------------C1

*-------------------------------------------------------------------------------------------------C2
SELECT-OPTIONS: S_PBDNR1 FOR  PBIM-PBDNR MODIF ID C2  .                                 "  需求计划版本1
SELECT-OPTIONS: S_PBDNR2 FOR  PBIM-PBDNR MODIF ID C2  .                                 "  需求计划版本2
SELECT-OPTIONS: S_PBDNR3 FOR  PBIM-PBDNR MODIF ID C3  .                                 "  需求计划版本3

PARAMETERS:     P_PERXX  TYPE PBED-PERXX  DEFAULT SY-DATUM(6) OBLIGATORY .               "  起始期间

SELECTION-SCREEN BEGIN OF LINE.

PARAMETERS:
      R1 RADIOBUTTON GROUP RAD2 MODIF ID C2 USER-COMMAND MXY.
SELECTION-SCREEN COMMENT 03(20) TEXT-001 MODIF ID C2.
PARAMETERS:
      R2 RADIOBUTTON GROUP RAD2 MODIF ID C2.
SELECTION-SCREEN COMMENT 26(23) TEXT-002 MODIF ID C2.
PARAMETERS:
      R3 RADIOBUTTON GROUP RAD2 MODIF ID C2.
SELECTION-SCREEN COMMENT 52(30) TEXT-003 MODIF ID C2.

SELECTION-SCREEN END OF LINE.
*-------------------------------------------------------------------------------------------------C2
SELECTION-SCREEN END OF BLOCK B1.

*&---------------------------------------------------------------------*
*& Form SCREEN_OUTPUT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM SCREEN_OUTPUT .
  LOOP AT SCREEN  .
    IF P_RD1 = 'X' .
      IF SCREEN-GROUP1 = 'C1'.
        SCREEN-ACTIVE = '1'.
        IF SCREEN-NAME = 'S_PBDNR-LOW'
          OR SCREEN-NAME = 'S_PBDNR1-LOW'
          OR SCREEN-NAME = 'S_PBDNR2-LOW'
          .
          SCREEN-REQUIRED = '2'.
        ENDIF.
        MODIFY SCREEN.
      ELSEIF SCREEN-GROUP1 = 'C2' OR SCREEN-GROUP1 = 'C3'.
        SCREEN-ACTIVE = '0'.
        MODIFY SCREEN.
      ENDIF.
    ELSEIF P_RD2 = 'X' .
      IF SCREEN-GROUP1 = 'C2' OR SCREEN-GROUP1 = 'C3'.
        SCREEN-ACTIVE = '1'.
        IF SCREEN-NAME = 'S_PBDNR-LOW'
          OR SCREEN-NAME = 'S_PBDNR1-LOW'
          OR SCREEN-NAME = 'S_PBDNR2-LOW'
          .
          SCREEN-REQUIRED = '2'.
        ENDIF.
        MODIFY SCREEN.
      ELSEIF SCREEN-GROUP1 = 'C1' .
        SCREEN-ACTIVE = '0'.
        MODIFY SCREEN.
      ENDIF.
    ENDIF.

    IF R2 = 'X' OR R3 = 'X'.
      IF SCREEN-GROUP1 = 'C3'.
        SCREEN-ACTIVE = '0'.
        MODIFY SCREEN.
      ENDIF.
    ELSE.
      IF SCREEN-GROUP1 = 'C3'.
        SCREEN-ACTIVE = '1'.
        MODIFY SCREEN.
      ENDIF.
    ENDIF.
  ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SCREEN_SETTING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM SCREEN_SETTING .
  DATA: GT_ZTPIRIMPLOG   TYPE TABLE OF ZTPIRIMPLOG WITH HEADER LINE.
  DATA: LV_PBDNR1 TYPE PBDNR.
  DATA: LV_PBDNR2 TYPE PBDNR.
  FIELD-SYMBOLS: <F0> , <F1> , <F2> , <F3> , <F4>, <F5> , <F6>.
  CLEAR LV_TEXT .
  LV_PERXXL = P_PERXX .
  LV_DATUML = P_PERXX && '01'.
  LV_DATUMD(6) = P_PERXX .

  IF P_RD2 IS NOT INITIAL AND ( R2 IS NOT INITIAL OR R3 IS NOT INITIAL ).
    CLEAR: GT_ZTPIRIMPLOG[] .
    SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_ZTPIRIMPLOG[] FROM ZTPIRIMPLOG
      WHERE PBDNR IN S_PBDNR1
      .
    SORT GT_ZTPIRIMPLOG[] BY ERSDA DESCENDING .
    READ TABLE GT_ZTPIRIMPLOG INDEX 1 .
    LV_PBDNR1 = GT_ZTPIRIMPLOG-ERSDA .

    CLEAR: GT_ZTPIRIMPLOG[] .
    SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_ZTPIRIMPLOG[] FROM ZTPIRIMPLOG
      WHERE PBDNR IN S_PBDNR2
      .
    SORT GT_ZTPIRIMPLOG[] BY ERSDA DESCENDING .
    READ TABLE GT_ZTPIRIMPLOG INDEX 1 .
    LV_PBDNR2 = GT_ZTPIRIMPLOG-ERSDA .
  ENDIF.

  DO 12 TIMES.

    CLEAR LV_FIELDNAME.
    LV_FIELDNAME = 'PERXX' && SY-INDEX .
    ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE LV_TEXT TO <F0> .
    <F0> = LV_DATUMD(6).

    IF P_RD2 IS INITIAL OR ( R2 IS INITIAL AND R3 IS INITIAL )..
      CLEAR LV_FIELDNAME1.
      LV_FIELDNAME1 = 'TEXT' && SY-INDEX .
      ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE LV_TEXT TO <F1> .
      <F1> = LV_DATUMD(4) && '年' && LV_DATUMD+4(2) && '月预测数量'.

      CLEAR LV_FIELDNAME2.
      LV_FIELDNAME2 = 'CTEXT' && SY-INDEX .
      ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE LV_TEXT TO <F2> .
      <F2> = LV_DATUMD(4) && '年' && LV_DATUMD+4(2) && '月预测金额'.
    ELSE.

      CLEAR LV_FIELDNAME1.
      LV_FIELDNAME1 = 'TEXT' && SY-INDEX .
      ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE LV_TEXT TO <F1> .
      <F1> = LV_PBDNR1 && ':' && LV_DATUMD(4) && '年' && LV_DATUMD+4(2) && '月数量'.

      CLEAR LV_FIELDNAME2.
      LV_FIELDNAME2 = 'CTEXT' && SY-INDEX .
      ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE LV_TEXT TO <F2> .
      <F2> = LV_PBDNR1 && ':' && LV_DATUMD(4) && '年' && LV_DATUMD+4(2) && '月金额'.

      CLEAR LV_FIELDNAME3.
      LV_FIELDNAME3 = 'TEXTA' && SY-INDEX .
      ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE LV_TEXT TO <F3> .
      IF SY-SUBRC = 0.
        <F3> = LV_PBDNR2 && ':' && LV_DATUMD(4) && '年' && LV_DATUMD+4(2) && '月数量'.
      ENDIF.

      CLEAR LV_FIELDNAME4.
      LV_FIELDNAME4 = 'CTEXTA' && SY-INDEX .
      ASSIGN COMPONENT LV_FIELDNAME4 OF STRUCTURE LV_TEXT TO <F4> .
      IF SY-SUBRC = 0.
        <F4> = LV_PBDNR2 && ':' && LV_DATUMD(4) && '年' && LV_DATUMD+4(2) && '月金额'.
      ENDIF.

      CLEAR LV_FIELDNAME5.
      LV_FIELDNAME5 = 'ZCYJE' && SY-INDEX .
      ASSIGN COMPONENT LV_FIELDNAME5 OF STRUCTURE LV_TEXT TO <F5> .
      IF SY-SUBRC = 0.
        <F5> = LV_DATUMD(4) && '年' && LV_DATUMD+4(2) && '月差异金额'.
      ENDIF.

      CLEAR LV_FIELDNAME6.
      LV_FIELDNAME6 = 'ZCYBL' && SY-INDEX .
      ASSIGN COMPONENT LV_FIELDNAME6 OF STRUCTURE LV_TEXT TO <F6> .
      IF SY-SUBRC = 0.
        <F6> = LV_DATUMD(4) && '年' && LV_DATUMD+4(2) && '月差异比例'.
      ENDIF.

    ENDIF.

    LV_DATUMD = LV_DATUMD(6) && '27'.
    LV_DATUMD = LV_DATUMD + 6.

  ENDDO.

*  LV_TEXT-TEXT15 = LV_DATUMD(4) && '年' && LV_DATUMD+4(2) && '月预测数'.
*  LV_TEXT-PERXX15 = LV_DATUMD(6).
  LV_PERXXH = LV_TEXT-PERXX12(6) .
  LV_DATUMH = LV_TEXT-PERXX12(6) && '27'.
  LV_DATUMH = LV_DATUMH + 6.
  LV_DATUMH = LV_DATUMH(6) && '01'.
  LV_DATUMH = LV_DATUMH - 1.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FOM_GETDATA .
  DATA: GT_ZTPIRIMPLOG TYPE TABLE OF ZTPIRIMPLOG WITH HEADER LINE.
  DATA: GS_MARC  TYPE MARC .
  DATA: GS_T460A TYPE T460A .
  DATA: LV_KONP  TYPE KONP .
  DATA: LV_MBEW  TYPE MBEW .
  DATA: S_WAERK TYPE WAERK VALUE 'CNY'.
  DATA: CW_RATE LIKE BAPI1093_0.
  DATA: S_C_FACTOR TYPE P DECIMALS 3.
  DATA: T_C_FACTOR TYPE P DECIMALS 3.
  DATA: L_RATE  TYPE P DECIMALS 4.
  DATA: LV_PDATU  TYPE PDATU.
  DATA: LV_WEEK  TYPE SCAL-WEEK.
  DATA: LV_PBDNR TYPE PBDNR.
  DATA: LIKE_CHAR TYPE CHAR10.
  DATA: LV_DATUM TYPE CHAR10.
  DATA: NUM TYPE I.
  DATA: NUM1 TYPE I.
  DATA: LV_N TYPE I.
  DATA: FACTOR  TYPE  ISOC_FACTOR.
  FIELD-SYMBOLS: <FA1>, <FA2>, <FA3>, <FA4>, <FA5>, <FA6>.
  FIELD-SYMBOLS: <FTL> TYPE ANY TABLE .
  DATA: LV_DATA  TYPE GTS_DATA.
  DATA: LV_DATA1 TYPE GTS_DATA.
  DATA: LV_DATA2 TYPE GTS_DATA.
  DATA: LV_DATA3 TYPE GTS_DATA.

  TYPES BEGIN OF GTS_MATDOC.
  INCLUDE TYPE MATDOC.
  TYPES AUART LIKE ZTWEEKA-AUART.
  TYPES END OF GTS_MATDOC.
  DATA: GT_MATDOC TYPE TABLE OF GTS_MATDOC WITH HEADER LINE.

  IF P_RD1 IS NOT INITIAL.
    NUM = 1 .
    NUM1 = 12 .
  ELSE.

    IF R1 IS NOT INITIAL.
      NUM = 3 .
    ELSE.
      NUM = 2 .
    ENDIF.

    NUM1 = 6 .
    CLEAR S_KUNNR[].
    CLEAR S_MATNR[].
    CLEAR S_WERKS[].
    CLEAR S_EXTWG[].
  ENDIF.

  IF R2 IS NOT INITIAL OR R3 IS NOT INITIAL.
    CLEAR S_PBDNR3[].
    CLEAR S_PBDNR3.
  ENDIF.

  CLEAR GT_DATA_A[] .
  DO NUM TIMES.
    CLEAR LV_N .
    LV_N = SY-INDEX .

    IF P_RD1 IS INITIAL .
      CLEAR S_PBDNR[] .
      LV_FIELDNAME = 'S_PBDNR' && SY-INDEX && '[]'.
      ASSIGN (LV_FIELDNAME) TO <FTL> .
      S_PBDNR[] = <FTL> .
      IF S_PBDNR[] IS INITIAL.
        EXIT.
      ENDIF.
    ENDIF.

    CLEAR GT_DATA[].
    SELECT
    ZTPIRIMPLOG~PBDNR
    ZTPIRIMPLOG~KUNNR
    ZTPIRIMPLOG~OEMODM
    ZTPIRIMPLOG~MATNR
    ZTPIRIMPLOG~WERKS
    ZTPIRIMPLOG~ERSDA
    MARA~EXTWG
    INTO CORRESPONDING FIELDS OF TABLE GT_DATA[]
    FROM ZTPIRIMPLOG
    INNER JOIN MARA ON ZTPIRIMPLOG~MATNR = MARA~MATNR
    WHERE ZTPIRIMPLOG~PBDNR IN S_PBDNR
      AND ZTPIRIMPLOG~KUNNR IN S_KUNNR
      AND ZTPIRIMPLOG~MATNR IN S_MATNR
      AND ZTPIRIMPLOG~WERKS IN S_WERKS
*    AND ZTPIRIMPLOG~PERXX >= LV_PERXXL
*    AND ZTPIRIMPLOG~PERXX <= LV_PERXXH
      AND MARA~EXTWG        IN S_EXTWG
      .
    SORT GT_DATA[] BY ERSDA DESCENDING .
    READ TABLE GT_DATA INDEX 1 .
    LV_PBDNR = GT_DATA-ERSDA .

    SORT GT_DATA[] .
    DELETE ADJACENT DUPLICATES FROM GT_DATA[] COMPARING ALL FIELDS.

    IF GT_DATA[] IS NOT INITIAL.
      CLEAR GT_ZTPIRIMPLOG[].
      SELECT * INTO TABLE GT_ZTPIRIMPLOG[] FROM ZTPIRIMPLOG
        FOR ALL ENTRIES IN GT_DATA[]
        WHERE PBDNR  = GT_DATA-PBDNR
          AND KUNNR  = GT_DATA-KUNNR
*          AND OEMODM = GT_DATA-OEMODM
          AND MATNR  = GT_DATA-MATNR
          AND WERKS  = GT_DATA-WERKS
          .
      LOOP AT GT_ZTPIRIMPLOG .

        IF GT_ZTPIRIMPLOG-ENTLU = 'W'.
          CLEAR LV_PDATU .
          LV_WEEK = GT_ZTPIRIMPLOG-PERXX.
          CALL FUNCTION 'WEEK_GET_FIRST_DAY'
            EXPORTING
              WEEK         = LV_WEEK
            IMPORTING
              DATE         = LV_PDATU
            EXCEPTIONS
              WEEK_INVALID = 1
              OTHERS       = 2.

          GT_ZTPIRIMPLOG-PERXX = LV_PDATU(6) .
        ENDIF.

        IF GT_ZTPIRIMPLOG-PERXX < LV_PERXXL OR GT_ZTPIRIMPLOG-PERXX > LV_PERXXH.
          DELETE GT_ZTPIRIMPLOG.
          CLEAR GT_ZTPIRIMPLOG.
          CONTINUE .
        ENDIF.

        MODIFY GT_ZTPIRIMPLOG TRANSPORTING PERXX.
        CLEAR GT_ZTPIRIMPLOG .
      ENDLOOP.
    ENDIF.

    LOOP AT GT_DATA.

      IF GT_DATA-PBDNR(3) = 'NEW'.
        GT_DATA-OEMODM = 'NEW'.
      ENDIF.

      GT_DATA-PBDNR_YC = LV_PBDNR .

      SELECT SINGLE MAKTX INTO GT_DATA-MAKTX FROM MAKT
        WHERE MATNR = GT_DATA-MATNR
          AND SPRAS = SY-LANGU
          .

      SELECT SINGLE NAME1 NAME2 KATR1 INTO CORRESPONDING FIELDS OF GT_DATA FROM KNA1
        WHERE KUNNR = GT_DATA-KUNNR
        .
      GT_DATA-NAME = GT_DATA-NAME1 && GT_DATA-NAME2 .

      SELECT SINGLE KDGRP BZIRK INTO CORRESPONDING FIELDS OF GT_DATA FROM KNVV
        WHERE KUNNR = GT_DATA-KUNNR
        .
      IF SY-SUBRC = 0.
        SELECT SINGLE KTEXT INTO GT_DATA-KTEXT FROM T151T
          WHERE KDGRP = GT_DATA-KDGRP
            AND SPRAS = SY-LANGU
            .
        SELECT SINGLE BZTXT INTO GT_DATA-BZTXT FROM T171T
          WHERE BZIRK = GT_DATA-BZIRK
            AND SPRAS = SY-LANGU
            .
      ENDIF.

      SELECT SINGLE KDMAT INTO GT_DATA-KDMAT FROM KNMT
        WHERE MATNR = GT_DATA-MATNR
          AND KUNNR = GT_DATA-KUNNR
          .

*生产工厂
      CLEAR GS_MARC.
      SELECT SINGLE * INTO CORRESPONDING FIELDS OF GS_MARC FROM MARC
        WHERE WERKS  = GT_DATA-WERKS
          AND MATNR  = GT_DATA-MATNR
          .

      IF GS_MARC-SOBSL = '31'.
        GT_DATA-WERKS_SC = '1202' .
      ELSEIF GS_MARC-SOBSL IS INITIAL.
        GT_DATA-WERKS_SC = GT_DATA-WERKS .
      ELSE.
        CLEAR GS_T460A.
        SELECT SINGLE * INTO CORRESPONDING FIELDS OF GS_T460A FROM T460A
          WHERE WERKS  = GT_DATA-WERKS
            AND SOBSL  = GS_MARC-SOBSL
            .
        IF GS_T460A-WRK02 IS NOT INITIAL .
          GT_DATA-WERKS_SC = GS_T460A-WRK02 .
        ELSEIF GS_T460A-REWRK IS NOT INITIAL.
          GT_DATA-WERKS_SC = GS_T460A-REWRK .
        ELSE.
          GT_DATA-WERKS_SC = GT_DATA-WERKS .
        ENDIF.
      ENDIF.

*生产公司
      SELECT SINGLE BUKRS INTO GT_DATA-BUKRS_SC FROM T001K
        WHERE BWKEY = GT_DATA-WERKS_SC
        .



* a.根据客户编码+物料编码 关联表A305、KONP取得生效日期A305-DATAB<=当天且截止日期A305-DATBI>=当天、
* 条件类型A305-KSCHL为ZP00,删除指示符KONP-LOEVM_KOW为空的第一套数据行
* 净价KONP-KBETR/价格单位KONP-KPEIN即为净价,KONP-KONWA为币别,KONP-KMEIN为单位

      CLEAR LV_KONP.
      SELECT SINGLE
        KONP~KBETR
        KONP~KPEIN
        KONP~KONWA
        KONP~KMEIN
        INTO CORRESPONDING FIELDS OF LV_KONP
        FROM KONP
        INNER JOIN A305 ON KONP~KNUMH = A305~KNUMH
      WHERE A305~MATNR  = GT_DATA-MATNR
        AND A305~KUNNR  = GT_DATA-KUNNR
        AND A305~KSCHL  = 'ZP00'
        AND A305~DATAB <= SY-DATUM
        AND A305~DATBI >= SY-DATUM
        AND KONP~LOEVM_KO = ''
        .

      IF SY-SUBRC = 0.
        GT_DATA-KBETR = LV_KONP-KBETR / LV_KONP-KPEIN .
        GT_DATA-KONWA = LV_KONP-KONWA .
        GT_DATA-KMEIN = LV_KONP-KMEIN .
      ELSE.

*b如果未找到价格,根据物料编码+销售工厂到MBEW,如价格控制 VPRSV ='S' ,
*则取出标准价 STPRS /价格单位 PEINH 即是净价;如果如价格控制VPRSV ='V',
*则取出移动平均价 VERPR /价格单位 PEINH 即是净价。
*根据工厂关联表 T001K-BWKEY 找到所属公司 BUKRS ,
*到表 T001 找到公司使用的币别WAERS, MARA- MEINS 为单位

        CLEAR LV_MBEW.
        SELECT SINGLE * INTO CORRESPONDING FIELDS OF LV_MBEW FROM MBEW
          WHERE MATNR  = GT_DATA-MATNR
            AND BWKEY  = GT_DATA-WERKS
            .
        IF LV_MBEW-VPRSV = 'S'.
          GT_DATA-KBETR = LV_MBEW-STPRS / LV_MBEW-PEINH .
        ELSEIF LV_MBEW-VPRSV = 'V'.
          GT_DATA-KBETR = LV_MBEW-VERPR / LV_MBEW-PEINH .
        ENDIF.

        SELECT SINGLE
          T001~WAERS
          INTO GT_DATA-KONWA
          FROM T001
          INNER JOIN T001K ON T001~BUKRS = T001K~BUKRS
          WHERE T001K~BWKEY = GT_DATA-WERKS
          .

        SELECT SINGLE MEINS INTO GT_DATA-KMEIN FROM MARA
          WHERE MATNR = GT_DATA-MATNR
          .
      ENDIF.

      CLEAR FACTOR .
      CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
        EXPORTING
          CURRENCY          = GT_DATA-KONWA
        IMPORTING
          FACTOR            = FACTOR
        EXCEPTIONS
          TOO_MANY_DECIMALS = 1
          OTHERS            = 2.
      IF SY-SUBRC = 0.
        GT_DATA-KBETR = GT_DATA-KBETR * FACTOR .
      ENDIF.

      IF S_WAERK <> GT_DATA-KONWA.

        CLEAR CW_RATE.
        CLEAR S_C_FACTOR.
        CLEAR T_C_FACTOR.
        CLEAR L_RATE.
        IF GT_DATA-KONWA <> 'EUR'.

*1. 获取汇率信息
          CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'
            EXPORTING
              RATE_TYPE  = 'M'
              FROM_CURR  = GT_DATA-KONWA
              TO_CURRNCY = S_WAERK
              DATE       = SY-DATUM
            IMPORTING
              EXCH_RATE  = CW_RATE.

*2. 获取转换因子
          CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
            EXPORTING
              CURRENCY = GT_DATA-KONWA
            IMPORTING
              FACTOR   = S_C_FACTOR.

          CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
            EXPORTING
              CURRENCY = S_WAERK
            IMPORTING
              FACTOR   = T_C_FACTOR.

          L_RATE = CW_RATE-EXCH_RATE * ( CW_RATE-TO_FACTOR / CW_RATE-FROM_FACTOR ).

        ELSE.

*1. 获取汇率信息
          CALL FUNCTION 'BAPI_EXCHANGERATE_GETDETAIL'
            EXPORTING
              RATE_TYPE  = 'EURX'
              FROM_CURR  = S_WAERK
              TO_CURRNCY = GT_DATA-KONWA
              DATE       = SY-DATUM
            IMPORTING
              EXCH_RATE  = CW_RATE.

*2. 获取转换因子
          CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
            EXPORTING
              CURRENCY = GT_DATA-KONWA
            IMPORTING
              FACTOR   = S_C_FACTOR.

          CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
            EXPORTING
              CURRENCY = S_WAERK
            IMPORTING
              FACTOR   = T_C_FACTOR.

          L_RATE = CW_RATE-EXCH_RATE * ( CW_RATE-FROM_FACTOR / CW_RATE-TO_FACTOR ).
          L_RATE = 1 / L_RATE .

        ENDIF.

      ELSE .
        L_RATE = 1 .
      ENDIF.

      GT_DATA-KBETR_CN = GT_DATA-KBETR * L_RATE .

      IF GT_DATA-KONWA IS NOT INITIAL.
        GT_DATA-L_RATE = L_RATE .
      ENDIF.

      LOOP AT GT_ZTPIRIMPLOG WHERE PBDNR  = GT_DATA-PBDNR
                               AND KUNNR  = GT_DATA-KUNNR
*                               AND OEMODM = GT_DATA-OEMODM
                               AND MATNR  = GT_DATA-MATNR
                               AND WERKS  = GT_DATA-WERKS
                               .

        DO NUM1 TIMES.
          CLEAR LV_FIELDNAME.
          LV_FIELDNAME = 'PERXX' && SY-INDEX .
          ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE LV_TEXT TO <FA1> .
          IF <FA1> = GT_ZTPIRIMPLOG-PERXX.
            CLEAR LV_FIELDNAME1.
            LV_FIELDNAME1 = 'PLNMG' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA TO <FA2> .
            <FA2> = <FA2> + GT_ZTPIRIMPLOG-PLNMG .
          ENDIF.
        ENDDO.
        CLEAR GT_ZTPIRIMPLOG .
      ENDLOOP.

      DO NUM1 TIMES.

        CLEAR LV_FIELDNAME.
        LV_FIELDNAME = 'PERXX' && SY-INDEX .
        ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE LV_TEXT TO <FA1> .

        CLEAR LV_FIELDNAME1.
        LV_FIELDNAME1 = 'PLNMG' && SY-INDEX .
        ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA TO <FA3> .

*        IF <FA1> = SY-DATUM(6) AND ( GT_DATA-KATR1 <> 'D' OR ( GT_DATA-KATR1 = 'D'  AND GT_DATA-OEMODM = 'ODM' ) ) .
        IF <FA1> = SY-DATUM(6) AND GT_DATA-KATR1 <> 'D' .
*          CLEAR LIKE_CHAR .
*          CONCATENATE SY-DATUM(6)'%' INTO LIKE_CHAR.
          LV_DATUM = SY-DATUM(6) && '01'.
          CLEAR GT_MATDOC[].
          SELECT * INTO CORRESPONDING FIELDS OF TABLE GT_MATDOC FROM MATDOC
            WHERE BWART IN ( '601','602','631','632' )
              AND BUDAT >= LV_DATUM
              AND BUDAT <= GT_DATA-ERSDA
              AND WERKS = GT_DATA-WERKS
              AND MATNR = GT_DATA-MATNR
              AND KUNNR = GT_DATA-KUNNR
              AND XAUTO = ''
              AND VBELN_IM <> ''
              AND ( ( MATDOC~CANCELLED =  '' AND MATDOC~SMBLN =  '') OR ( MATDOC~CANCELLED = '' AND MATDOC~SMBLN <> '' AND MATDOC~CANCELLATION_TYPE = '1' )  )
              .
          LOOP AT GT_MATDOC.
            IF GT_MATDOC-BWART = '602' OR GT_MATDOC-BWART = '632'.
              GT_MATDOC-ERFMG = GT_MATDOC-ERFMG * -1 .
            ENDIF.
            <FA3> = <FA3> + GT_MATDOC-ERFMG .
            CLEAR GT_MATDOC.
          ENDLOOP.
        ENDIF.

        CLEAR LV_FIELDNAME2.
        LV_FIELDNAME2 = 'KBETR' && SY-INDEX .
        ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE GT_DATA TO <FA4> .

        <FA4> = <FA3> * GT_DATA-KBETR_CN .
      ENDDO.
      GT_DATA-FLAGE = LV_N .
      MODIFY GT_DATA.
      CLEAR GT_DATA.
    ENDLOOP.

    IF P_RD2 IS NOT INITIAL .

      IF R1 IS NOT INITIAL .

        CLEAR GT_DATA_A.
        READ TABLE GT_DATA INTO GT_DATA_A INDEX 1 .

        DO NUM1 TIMES.
          CLEAR LV_FIELDNAME.
          LV_FIELDNAME = 'PLNMG' && SY-INDEX .
          ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA_A TO <FA1> .
          CLEAR <FA1> .

          CLEAR LV_FIELDNAME1.
          LV_FIELDNAME1 = 'KBETR' && SY-INDEX .
          ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA_A TO <FA2> .
          CLEAR <FA2> .
        ENDDO.

        LOOP AT GT_DATA WHERE PBDNR_YC = GT_DATA_A-PBDNR_YC.
          DO NUM1 TIMES.
            CLEAR LV_FIELDNAME.
            LV_FIELDNAME  = 'PLNMG' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA_A TO <FA1> .
            CLEAR LV_FIELDNAME1.
            LV_FIELDNAME1 = 'KBETR' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA_A TO <FA2> .
            CLEAR LV_FIELDNAME2.
            LV_FIELDNAME2 = 'PLNMG' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE GT_DATA TO <FA3> .
            CLEAR LV_FIELDNAME3.
            LV_FIELDNAME3 = 'KBETR' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE GT_DATA TO <FA4> .
            <FA1> = <FA1> + <FA3> .
            <FA2> = <FA2> + <FA4> .
          ENDDO.
          CLEAR GT_DATA .
        ENDLOOP.
        APPEND GT_DATA_A .

      ELSEIF R2 IS NOT INITIAL .

        GT_DATA_B[] = GT_DATA[] .
        SORT GT_DATA_B BY OEMODM EXTWG PBDNR_YC .
        DELETE ADJACENT DUPLICATES FROM GT_DATA_B[] COMPARING OEMODM EXTWG PBDNR_YC.
        APPEND LINES OF GT_DATA_B[] TO GT_DATA_A[].

        LOOP AT GT_DATA_A WHERE PBDNR_YC = LV_PBDNR.

          DO NUM1 TIMES.
            CLEAR LV_FIELDNAME.
            LV_FIELDNAME = 'PLNMG' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA_A TO <FA1> .
            CLEAR <FA1> .

            CLEAR LV_FIELDNAME1.
            LV_FIELDNAME1 = 'KBETR' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA_A TO <FA2> .
            CLEAR <FA2> .
          ENDDO.

          LOOP AT GT_DATA WHERE EXTWG = GT_DATA_A-EXTWG
                            AND OEMODM = GT_DATA_A-OEMODM
                            AND PBDNR_YC = GT_DATA_A-PBDNR_YC
                            .
            DO NUM1 TIMES.
              CLEAR LV_FIELDNAME.
              LV_FIELDNAME  = 'PLNMG' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA_A TO <FA1> .
              CLEAR LV_FIELDNAME1.
              LV_FIELDNAME1 = 'KBETR' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA_A TO <FA2> .
              CLEAR LV_FIELDNAME2.
              LV_FIELDNAME2 = 'PLNMG' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE GT_DATA TO <FA3> .
              CLEAR LV_FIELDNAME3.
              LV_FIELDNAME3 = 'KBETR' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE GT_DATA TO <FA4> .
              <FA1> = <FA1> + <FA3> .
              <FA2> = <FA2> + <FA4> .
            ENDDO.
            CLEAR GT_DATA .
          ENDLOOP.

          MODIFY GT_DATA_A.
          CLEAR GT_DATA_A.
        ENDLOOP.

      ELSEIF R3 IS NOT INITIAL..

        GT_DATA_B[] = GT_DATA[] .
        SORT GT_DATA_B BY OEMODM EXTWG BUKRS_SC PBDNR_YC .
        DELETE ADJACENT DUPLICATES FROM GT_DATA_B[] COMPARING OEMODM EXTWG BUKRS_SC PBDNR_YC.
        APPEND LINES OF GT_DATA_B[] TO GT_DATA_A[].

        LOOP AT GT_DATA_A WHERE PBDNR_YC = LV_PBDNR.

          DO NUM1 TIMES.
            CLEAR LV_FIELDNAME.
            LV_FIELDNAME = 'PLNMG' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA_A TO <FA1> .
            CLEAR <FA1> .

            CLEAR LV_FIELDNAME1.
            LV_FIELDNAME1 = 'KBETR' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA_A TO <FA2> .
            CLEAR <FA2> .
          ENDDO.

          LOOP AT GT_DATA WHERE EXTWG = GT_DATA_A-EXTWG
                            AND OEMODM = GT_DATA_A-OEMODM
                            AND BUKRS_SC = GT_DATA_A-BUKRS_SC
                            AND PBDNR_YC = GT_DATA_A-PBDNR_YC
                            .
            DO NUM1 TIMES.
              CLEAR LV_FIELDNAME.
              LV_FIELDNAME  = 'PLNMG' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA_A TO <FA1> .
              CLEAR LV_FIELDNAME1.
              LV_FIELDNAME1 = 'KBETR' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA_A TO <FA2> .
              CLEAR LV_FIELDNAME2.
              LV_FIELDNAME2 = 'PLNMG' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE GT_DATA TO <FA3> .
              CLEAR LV_FIELDNAME3.
              LV_FIELDNAME3 = 'KBETR' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE GT_DATA TO <FA4> .
              <FA1> = <FA1> + <FA3> .
              <FA2> = <FA2> + <FA4> .
            ENDDO.
            CLEAR GT_DATA .
          ENDLOOP.

          MODIFY GT_DATA_A.
          CLEAR GT_DATA_A.
        ENDLOOP.

      ENDIF.

    ENDIF.

  ENDDO.

  IF P_RD2 IS NOT INITIAL .

    IF R1 IS NOT INITIAL.

      CLEAR LV_DATA .
      CLEAR LV_DATA1 .
      CLEAR LV_DATA2 .
      CLEAR LV_DATA3 .
      READ TABLE GT_DATA_A INTO LV_DATA1 INDEX 1 .
      READ TABLE GT_DATA_A INTO LV_DATA2 INDEX 2 .
      READ TABLE GT_DATA_A INTO LV_DATA3 INDEX 3 .

      IF LV_DATA1 IS NOT INITIAL.
        IF LV_DATA2 IS NOT INITIAL.
          CLEAR LV_DATA .
          DO NUM1 TIMES.

            CLEAR LV_FIELDNAME.
            LV_FIELDNAME  = 'PLNMG' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE LV_DATA1 TO <FA1> .
            CLEAR LV_FIELDNAME1.
            LV_FIELDNAME1 = 'KBETR' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE LV_DATA1 TO <FA2> .
            CLEAR LV_FIELDNAME2.
            LV_FIELDNAME2 = 'PLNMG' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE LV_DATA2 TO <FA3> .
            CLEAR LV_FIELDNAME3.
            LV_FIELDNAME3 = 'KBETR' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE LV_DATA2 TO <FA4> .
            CLEAR LV_FIELDNAME4.
            LV_FIELDNAME4 = 'PLNMG' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME4 OF STRUCTURE LV_DATA TO <FA5> .
            CLEAR LV_FIELDNAME5.
            LV_FIELDNAME5 = 'KBETR' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME5 OF STRUCTURE LV_DATA TO <FA6> .

            IF <FA3> <> 0.
              <FA5> = ( <FA1> - <FA3> ) / <FA3> * 100.
              IF <FA5> < 0.
                CLEAR IW_CELLCOLOR .
                IW_CELLCOLOR-FNAME = LV_FIELDNAME4 .
                IW_CELLCOLOR-COLOR-COL = 6.
                IW_CELLCOLOR-COLOR-INT = 0.
                IW_CELLCOLOR-COLOR-INV = 0.
                APPEND IW_CELLCOLOR TO LV_DATA-CELLCOLOR.
              ENDIF.
            ENDIF.

            IF <FA4> <> 0.
              <FA6> = ( <FA2> - <FA4> ) / <FA4> * 100.
              IF <FA6> < 0.
                CLEAR IW_CELLCOLOR .
                IW_CELLCOLOR-FNAME = LV_FIELDNAME5 .
                IW_CELLCOLOR-COLOR-COL = 6.
                IW_CELLCOLOR-COLOR-INT = 0.
                IW_CELLCOLOR-COLOR-INV = 0.
                APPEND IW_CELLCOLOR TO LV_DATA-CELLCOLOR.
              ENDIF.
            ENDIF.

          ENDDO.

          LV_DATA-PBDNR_YC = LV_DATA1-PBDNR_YC && 'VS' && LV_DATA2-PBDNR_YC && '差异比率(%)'.

          INSERT LV_DATA INTO GT_DATA_A[] INDEX 3.
        ENDIF.

        IF LV_DATA3 IS NOT INITIAL.
          CLEAR LV_DATA .
          DO NUM1 TIMES.

            CLEAR LV_FIELDNAME.
            LV_FIELDNAME  = 'PLNMG' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE LV_DATA1 TO <FA1> .
            CLEAR LV_FIELDNAME1.
            LV_FIELDNAME1 = 'KBETR' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE LV_DATA1 TO <FA2> .
            CLEAR LV_FIELDNAME2.
            LV_FIELDNAME2 = 'PLNMG' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE LV_DATA3 TO <FA3> .
            CLEAR LV_FIELDNAME3.
            LV_FIELDNAME3 = 'KBETR' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE LV_DATA3 TO <FA4> .
            CLEAR LV_FIELDNAME4.
            LV_FIELDNAME4 = 'PLNMG' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME4 OF STRUCTURE LV_DATA TO <FA5> .
            CLEAR LV_FIELDNAME5.
            LV_FIELDNAME5 = 'KBETR' && SY-INDEX .
            ASSIGN COMPONENT LV_FIELDNAME5 OF STRUCTURE LV_DATA TO <FA6> .

            IF <FA3> <> 0.
              <FA5> = ( <FA1> - <FA3> ) / <FA3> * 100.
              IF <FA5> < 0.
                CLEAR IW_CELLCOLOR .
                IW_CELLCOLOR-FNAME = LV_FIELDNAME4 .
                IW_CELLCOLOR-COLOR-COL = 6.
                IW_CELLCOLOR-COLOR-INT = 0.
                IW_CELLCOLOR-COLOR-INV = 0.
                APPEND IW_CELLCOLOR TO LV_DATA-CELLCOLOR.
              ENDIF.
            ENDIF.

            IF <FA4> <> 0.
              <FA6> = ( <FA2> - <FA4> ) / <FA4> * 100.
              IF <FA6> < 0.
                CLEAR IW_CELLCOLOR .
                IW_CELLCOLOR-FNAME = LV_FIELDNAME5 .
                IW_CELLCOLOR-COLOR-COL = 6.
                IW_CELLCOLOR-COLOR-INT = 0.
                IW_CELLCOLOR-COLOR-INV = 0.
                APPEND IW_CELLCOLOR TO LV_DATA-CELLCOLOR.
              ENDIF.
            ENDIF.

          ENDDO.

          LV_DATA-PBDNR_YC = LV_DATA1-PBDNR_YC && 'VS' && LV_DATA3-PBDNR_YC && '差异比率(%)'.
          INSERT LV_DATA INTO GT_DATA_A[] INDEX 5.
        ENDIF.
      ENDIF.

      GT_DATA[] = GT_DATA_A[] .

    ELSEIF R2 IS NOT INITIAL.

      CLEAR GT_DATA[].
      LOOP AT GT_DATA_A.
        GT_DATA-EXTWG    = GT_DATA_A-EXTWG.
        GT_DATA-OEMODM   = GT_DATA_A-OEMODM.
        APPEND GT_DATA.
        CLEAR GT_DATA.
        CLEAR GT_DATA_A.
      ENDLOOP.

      SORT GT_DATA[] BY OEMODM EXTWG .
      DELETE ADJACENT DUPLICATES FROM GT_DATA[] COMPARING OEMODM EXTWG.
      LOOP AT GT_DATA.

        LOOP AT GT_DATA_A WHERE EXTWG = GT_DATA-EXTWG AND OEMODM = GT_DATA-OEMODM.
          IF GT_DATA_A-FLAGE = 1.

            DO NUM1 TIMES.

              CLEAR LV_FIELDNAME.
              LV_FIELDNAME  = 'PLNMG' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA TO <FA1> .
              CLEAR LV_FIELDNAME1.
              LV_FIELDNAME1 = 'KBETR' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA TO <FA2> .

              CLEAR LV_FIELDNAME2.
              LV_FIELDNAME2 = 'PLNMG' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE GT_DATA_A TO <FA3> .
              CLEAR LV_FIELDNAME3.
              LV_FIELDNAME3 = 'KBETR' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE GT_DATA_A TO <FA4> .

              <FA1> = <FA1> + <FA3> .
              <FA2> = <FA2> + <FA4> .

            ENDDO.

          ELSEIF GT_DATA_A-FLAGE = 2.

            DO NUM1 TIMES.

              CLEAR LV_FIELDNAME.
              LV_FIELDNAME  = 'PLNMGA' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA TO <FA1> .
              CLEAR LV_FIELDNAME1.
              LV_FIELDNAME1 = 'KBETRA' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA TO <FA2> .

              CLEAR LV_FIELDNAME2.
              LV_FIELDNAME2 = 'PLNMG' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE GT_DATA_A TO <FA3> .
              CLEAR LV_FIELDNAME3.
              LV_FIELDNAME3 = 'KBETR' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE GT_DATA_A TO <FA4> .

              <FA1> = <FA1> + <FA3> .
              <FA2> = <FA2> + <FA4> .

            ENDDO.

          ENDIF.

          CLEAR GT_DATA_A .
        ENDLOOP.

        DO NUM1 TIMES.

          CLEAR LV_FIELDNAME.
          LV_FIELDNAME  = 'ZCYJE' && SY-INDEX .
          ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA TO <FA1> .
          CLEAR LV_FIELDNAME1.
          LV_FIELDNAME1 = 'ZCYBL' && SY-INDEX .
          ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA TO <FA2> .

*        CLEAR LV_FIELDNAME2.
*        LV_FIELDNAME2 = 'PLNMG' && SY-INDEX .
*        ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE GT_DATA TO <FA3> .
          CLEAR LV_FIELDNAME3.
          LV_FIELDNAME3 = 'KBETR' && SY-INDEX .
          ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE GT_DATA TO <FA4> .

*        CLEAR LV_FIELDNAME4.
*        LV_FIELDNAME4 = 'PLNMGA' && SY-INDEX .
*        ASSIGN COMPONENT LV_FIELDNAME4 OF STRUCTURE GT_DATA TO <FA5> .
          CLEAR LV_FIELDNAME5.
          LV_FIELDNAME5 = 'KBETRA' && SY-INDEX .
          ASSIGN COMPONENT LV_FIELDNAME5 OF STRUCTURE GT_DATA TO <FA6> .

* 差异比例=(销售预测版本1金额-销售预测版本2金额)/销售预测版本2金额(保留三位小数)*100 & '%',如果需求版本2金额=0,则显示100%
          IF <FA6> <> 0.
            <FA1> = ( <FA4> - <FA6> ) / <FA6> * 100 .
          ENDIF.
          IF <FA1> < 0.
            CLEAR IW_CELLCOLOR .
            IW_CELLCOLOR-FNAME = LV_FIELDNAME1 .
            IW_CELLCOLOR-COLOR-COL = 6.
            IW_CELLCOLOR-COLOR-INT = 0.
            IW_CELLCOLOR-COLOR-INV = 0.
            APPEND IW_CELLCOLOR TO GT_DATA-CELLCOLOR.
          ENDIF.
          <FA2> = <FA1> && '%' .
* 差异金额=销售预测版本1金额-计划版本2,小于0单元格显示红色
          <FA1> = <FA4> - <FA6> .
          IF <FA1> < 0 .
            CLEAR IW_CELLCOLOR .
            IW_CELLCOLOR-FNAME = LV_FIELDNAME .
            IW_CELLCOLOR-COLOR-COL = 6.
            IW_CELLCOLOR-COLOR-INT = 0.
            IW_CELLCOLOR-COLOR-INV = 0.
            APPEND IW_CELLCOLOR TO GT_DATA-CELLCOLOR.
          ENDIF.
        ENDDO.

        MODIFY GT_DATA.
        CLEAR GT_DATA.
      ENDLOOP.

    ELSEIF R3 IS NOT INITIAL.

      CLEAR GT_DATA[].
      LOOP AT GT_DATA_A.
        GT_DATA-EXTWG    = GT_DATA_A-EXTWG.
        GT_DATA-BUKRS_SC = GT_DATA_A-BUKRS_SC.
        GT_DATA-OEMODM   = GT_DATA_A-OEMODM.
        APPEND GT_DATA.
        CLEAR GT_DATA.
        CLEAR GT_DATA_A.
      ENDLOOP.

      SORT GT_DATA[] BY OEMODM EXTWG BUKRS_SC .
      DELETE ADJACENT DUPLICATES FROM GT_DATA[] COMPARING OEMODM EXTWG BUKRS_SC.
      LOOP AT GT_DATA.

        LOOP AT GT_DATA_A WHERE EXTWG = GT_DATA-EXTWG
                            AND OEMODM = GT_DATA-OEMODM
                            AND BUKRS_SC = GT_DATA-BUKRS_SC
                            .
          IF GT_DATA_A-FLAGE = 1.

            DO NUM1 TIMES.

              CLEAR LV_FIELDNAME.
              LV_FIELDNAME  = 'PLNMG' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA TO <FA1> .
              CLEAR LV_FIELDNAME1.
              LV_FIELDNAME1 = 'KBETR' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA TO <FA2> .

              CLEAR LV_FIELDNAME2.
              LV_FIELDNAME2 = 'PLNMG' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE GT_DATA_A TO <FA3> .
              CLEAR LV_FIELDNAME3.
              LV_FIELDNAME3 = 'KBETR' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE GT_DATA_A TO <FA4> .

              <FA1> = <FA1> + <FA3> .
              <FA2> = <FA2> + <FA4> .

            ENDDO.

          ELSEIF GT_DATA_A-FLAGE = 2.

            DO NUM1 TIMES.

              CLEAR LV_FIELDNAME.
              LV_FIELDNAME  = 'PLNMGA' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA TO <FA1> .
              CLEAR LV_FIELDNAME1.
              LV_FIELDNAME1 = 'KBETRA' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA TO <FA2> .

              CLEAR LV_FIELDNAME2.
              LV_FIELDNAME2 = 'PLNMG' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE GT_DATA_A TO <FA3> .
              CLEAR LV_FIELDNAME3.
              LV_FIELDNAME3 = 'KBETR' && SY-INDEX .
              ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE GT_DATA_A TO <FA4> .

              <FA1> = <FA1> + <FA3> .
              <FA2> = <FA2> + <FA4> .

            ENDDO.

          ENDIF.

          CLEAR GT_DATA_A .
        ENDLOOP.

        DO NUM1 TIMES.

          CLEAR LV_FIELDNAME.
          LV_FIELDNAME  = 'ZCYJE' && SY-INDEX .
          ASSIGN COMPONENT LV_FIELDNAME OF STRUCTURE GT_DATA TO <FA1> .
          CLEAR LV_FIELDNAME1.
          LV_FIELDNAME1 = 'ZCYBL' && SY-INDEX .
          ASSIGN COMPONENT LV_FIELDNAME1 OF STRUCTURE GT_DATA TO <FA2> .

*        CLEAR LV_FIELDNAME2.
*        LV_FIELDNAME2 = 'PLNMG' && SY-INDEX .
*        ASSIGN COMPONENT LV_FIELDNAME2 OF STRUCTURE GT_DATA TO <FA3> .
          CLEAR LV_FIELDNAME3.
          LV_FIELDNAME3 = 'KBETR' && SY-INDEX .
          ASSIGN COMPONENT LV_FIELDNAME3 OF STRUCTURE GT_DATA TO <FA4> .

*        CLEAR LV_FIELDNAME4.
*        LV_FIELDNAME4 = 'PLNMGA' && SY-INDEX .
*        ASSIGN COMPONENT LV_FIELDNAME4 OF STRUCTURE GT_DATA TO <FA5> .
          CLEAR LV_FIELDNAME5.
          LV_FIELDNAME5 = 'KBETRA' && SY-INDEX .
          ASSIGN COMPONENT LV_FIELDNAME5 OF STRUCTURE GT_DATA TO <FA6> .

* 差异比例=(销售预测版本1金额-销售预测版本2金额)/销售预测版本2金额(保留三位小数)*100 & '%',如果需求版本2金额=0,则显示100%
          IF <FA6> <> 0.
            <FA1> = ( <FA4> - <FA6> ) / <FA6> * 100 .
          ENDIF.
          IF <FA1> < 0.
            CLEAR IW_CELLCOLOR .
            IW_CELLCOLOR-FNAME = LV_FIELDNAME1 .
            IW_CELLCOLOR-COLOR-COL = 6.
            IW_CELLCOLOR-COLOR-INT = 0.
            IW_CELLCOLOR-COLOR-INV = 0.
            APPEND IW_CELLCOLOR TO GT_DATA-CELLCOLOR.
          ENDIF.
          <FA2> = <FA1> && '%' .
* 差异金额=销售预测版本1金额-计划版本2,小于0单元格显示红色
          <FA1> = <FA4> - <FA6> .
          IF <FA1> < 0 .
            CLEAR IW_CELLCOLOR .
            IW_CELLCOLOR-FNAME = LV_FIELDNAME .
            IW_CELLCOLOR-COLOR-COL = 6.
            IW_CELLCOLOR-COLOR-INT = 0.
            IW_CELLCOLOR-COLOR-INV = 0.
            APPEND IW_CELLCOLOR TO GT_DATA-CELLCOLOR.
          ENDIF.
        ENDDO.

        MODIFY GT_DATA.
        CLEAR GT_DATA.
      ENDLOOP.

    ENDIF.
  ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_DISPLAY .
  CLEAR S_LAYOUT.
  S_LAYOUT-ZEBRA = 'X'.
  S_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
  S_LAYOUT-COLTAB_FIELDNAME = 'CELLCOLOR'. "单元格颜色内表字段
*  s_layout-box_fieldname    = 'BOX'.
  PERFORM FRM_FILL_FIELD .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_SAVE                   = 'A'
      IS_LAYOUT                = S_LAYOUT
      IT_FIELDCAT              = GT_FIELDCAT
      I_CALLBACK_PROGRAM       = SY-REPID
      I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'
*     i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
      I_CALLBACK_USER_COMMAND  = 'USER_COMMAND'
*     I_CALLBACK_HTML_TOP_OF_PAGE = 'F_HTML_TOP_OF_PAGE'
      I_HTML_HEIGHT_TOP        = 8                             "指定ALV表头宽度
    TABLES
      T_OUTTAB                 = GT_DATA[].
ENDFORM.

FORM FRM_FILL_FIELD .
  DATA:  WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
  DEFINE FILL_FIELD.
    WA_FIELDCAT-FIELDNAME = &1.
    WA_FIELDCAT-SELTEXT_L = &2.
*    IF WA_FIELDCAT-FIELDNAME =  'MSLJH' OR WA_FIELDCAT-FIELDNAME =  'WCBJH'.
*      WA_FIELDCAT-EMPHASIZE = 'C600'. "设置字段的颜色
*    ENDIF.

*    IF WA_FIELDCAT-FIELDNAME =  'MSLMB' OR WA_FIELDCAT-FIELDNAME =  'WCBMB'.
*      WA_FIELDCAT-EMPHASIZE = 'C710'. "设置字段的颜色
*    ENDIF.

    IF WA_FIELDCAT-FIELDNAME = 'PLNBEZ' OR WA_FIELDCAT-FIELDNAME = 'MATNR' .
      WA_FIELDCAT-REF_TABNAME = 'MARA'.
      WA_FIELDCAT-REF_FIELDNAME = 'MATNR'.
    ENDIF.

    IF WA_FIELDCAT-FIELDNAME = 'ARKTX' OR WA_FIELDCAT-FIELDNAME = 'WAKTX' .
      WA_FIELDCAT-REF_TABNAME = 'VBAP'.
      WA_FIELDCAT-REF_FIELDNAME = 'ARKTX'.
    ENDIF.

    IF WA_FIELDCAT-FIELDNAME = 'KUNNR' .
      WA_FIELDCAT-REF_TABNAME = 'KNA1'.
      WA_FIELDCAT-REF_FIELDNAME = 'KUNNR'.
    ENDIF.

    APPEND WA_FIELDCAT TO GT_FIELDCAT.
    CLEAR WA_FIELDCAT.
  END-OF-DEFINITION.
  IF P_RD1 IS NOT INITIAL.

    FILL_FIELD :
      'PBDNR_YC'  '销售预测版本',
      'PBDNR'  '需求计划版本',
      'KUNNR'  '客户编码',
      'NAME'   '客户名称',
      'KTEXT'  '客户组',
      'BZTXT'  '销售区域',
      'OEMODM' 'ODM/OEM/NEW',
      'EXTWG'  '系列',
      'MATNR'  '物料编码',
      'MAKTX'  '物料名称',
      'KDMAT'  '客户物料编码',
      'WERKS'  '销售工厂',
      'WERKS_SC' '生产工厂',
      'BUKRS_SC' '生产公司',
      'KBETR'  '销售单价'  ,
      'KONWA'  '币别',
      'KMEIN'  '单位',
      'KBETR_CN'  'CNY销售单价',
      'L_RATE'  '兑换RMB汇率',
      'PLNMG1'  LV_TEXT-TEXT1   ,
      'PLNMG2'  LV_TEXT-TEXT2   ,
      'PLNMG3'  LV_TEXT-TEXT3   ,
      'PLNMG4'  LV_TEXT-TEXT4   ,
      'PLNMG5'  LV_TEXT-TEXT5   ,
      'PLNMG6'  LV_TEXT-TEXT6   ,
      'PLNMG7'  LV_TEXT-TEXT7   ,
      'PLNMG8'  LV_TEXT-TEXT8   ,
      'PLNMG9'  LV_TEXT-TEXT9   ,
      'PLNMG10' LV_TEXT-TEXT10  ,
      'PLNMG11' LV_TEXT-TEXT11  ,
      'PLNMG12' LV_TEXT-TEXT12  ,
      'KBETR1'  LV_TEXT-CTEXT1  ,
      'KBETR2'  LV_TEXT-CTEXT2  ,
      'KBETR3'  LV_TEXT-CTEXT3  ,
      'KBETR4'  LV_TEXT-CTEXT4  ,
      'KBETR5'  LV_TEXT-CTEXT5  ,
      'KBETR6'  LV_TEXT-CTEXT6  ,
      'KBETR7'  LV_TEXT-CTEXT7  ,
      'KBETR8'  LV_TEXT-CTEXT8  ,
      'KBETR9'  LV_TEXT-CTEXT9  ,
      'KBETR10'	LV_TEXT-CTEXT10	,
      'KBETR11'	LV_TEXT-CTEXT11	,
      'KBETR12'	LV_TEXT-CTEXT12	.
  ELSEIF P_RD2 IS NOT INITIAL AND R1 IS NOT INITIAL.

    FILL_FIELD :
      'PBDNR_YC'  '销售预测版本' ,
      'PLNMG1'  LV_TEXT-TEXT1   ,
      'PLNMG2'  LV_TEXT-TEXT2   ,
      'PLNMG3'  LV_TEXT-TEXT3   ,
      'PLNMG4'  LV_TEXT-TEXT4   ,
      'PLNMG5'  LV_TEXT-TEXT5   ,
      'PLNMG6'  LV_TEXT-TEXT6   ,
      'KBETR1'  LV_TEXT-CTEXT1  ,
      'KBETR2'  LV_TEXT-CTEXT2  ,
      'KBETR3'  LV_TEXT-CTEXT3  ,
      'KBETR4'  LV_TEXT-CTEXT4  ,
      'KBETR5'  LV_TEXT-CTEXT5  ,
      'KBETR6'  LV_TEXT-CTEXT6  .

  ELSEIF P_RD2 IS NOT INITIAL AND R2 IS NOT INITIAL.

    FILL_FIELD :
      'OEMODM'  'ODM/OEM/NEW',
      'EXTWG'   '系列',
      'PLNMG1'  LV_TEXT-TEXT1   ,
      'PLNMG2'  LV_TEXT-TEXT2   ,
      'PLNMG3'  LV_TEXT-TEXT3   ,
      'PLNMG4'  LV_TEXT-TEXT4   ,
      'PLNMG5'  LV_TEXT-TEXT5   ,
      'PLNMG6'  LV_TEXT-TEXT6   ,
      'KBETR1'  LV_TEXT-CTEXT1  ,
      'KBETR2'  LV_TEXT-CTEXT2  ,
      'KBETR3'  LV_TEXT-CTEXT3  ,
      'KBETR4'  LV_TEXT-CTEXT4  ,
      'KBETR5'  LV_TEXT-CTEXT5  ,
      'KBETR6'  LV_TEXT-CTEXT6  ,
      'PLNMGA1' LV_TEXT-TEXTA1  ,
      'PLNMGA2' LV_TEXT-TEXTA2  ,
      'PLNMGA3' LV_TEXT-TEXTA3  ,
      'PLNMGA4' LV_TEXT-TEXTA4  ,
      'PLNMGA5' LV_TEXT-TEXTA5  ,
      'PLNMGA6' LV_TEXT-TEXTA6  ,
      'KBETRA1' LV_TEXT-CTEXTA1 ,
      'KBETRA2' LV_TEXT-CTEXTA2 ,
      'KBETRA3' LV_TEXT-CTEXTA3 ,
      'KBETRA4' LV_TEXT-CTEXTA4 ,
      'KBETRA5' LV_TEXT-CTEXTA5 ,
      'KBETRA6' LV_TEXT-CTEXTA6 ,
      'ZCYJE1'  LV_TEXT-ZCYJE1  ,
      'ZCYJE2'  LV_TEXT-ZCYJE2  ,
      'ZCYJE3'  LV_TEXT-ZCYJE3  ,
      'ZCYJE4'  LV_TEXT-ZCYJE4  ,
      'ZCYJE5'  LV_TEXT-ZCYJE5  ,
      'ZCYJE6'  LV_TEXT-ZCYJE6  ,
      'ZCYBL1'  LV_TEXT-ZCYBL1  ,
      'ZCYBL2'  LV_TEXT-ZCYBL2  ,
      'ZCYBL3'  LV_TEXT-ZCYBL3  ,
      'ZCYBL4'  LV_TEXT-ZCYBL4  ,
      'ZCYBL5'  LV_TEXT-ZCYBL5  ,
      'ZCYBL6'  LV_TEXT-ZCYBL6  .

  ELSEIF P_RD2 IS NOT INITIAL AND R3 IS NOT INITIAL.

    FILL_FIELD :
      'OEMODM'   'ODM/OEM/NEW',
      'EXTWG'    '系列',
      'BUKRS_SC' '生产公司',
      'PLNMG1'  LV_TEXT-TEXT1   ,
      'PLNMG2'  LV_TEXT-TEXT2   ,
      'PLNMG3'  LV_TEXT-TEXT3   ,
      'PLNMG4'  LV_TEXT-TEXT4   ,
      'PLNMG5'  LV_TEXT-TEXT5   ,
      'PLNMG6'  LV_TEXT-TEXT6   ,
      'KBETR1'  LV_TEXT-CTEXT1  ,
      'KBETR2'  LV_TEXT-CTEXT2  ,
      'KBETR3'  LV_TEXT-CTEXT3  ,
      'KBETR4'  LV_TEXT-CTEXT4  ,
      'KBETR5'  LV_TEXT-CTEXT5  ,
      'KBETR6'  LV_TEXT-CTEXT6  ,
      'PLNMGA1' LV_TEXT-TEXTA1  ,
      'PLNMGA2' LV_TEXT-TEXTA2  ,
      'PLNMGA3' LV_TEXT-TEXTA3  ,
      'PLNMGA4' LV_TEXT-TEXTA4  ,
      'PLNMGA5' LV_TEXT-TEXTA5  ,
      'PLNMGA6' LV_TEXT-TEXTA6  ,
      'KBETRA1' LV_TEXT-CTEXTA1 ,
      'KBETRA2' LV_TEXT-CTEXTA2 ,
      'KBETRA3' LV_TEXT-CTEXTA3 ,
      'KBETRA4' LV_TEXT-CTEXTA4 ,
      'KBETRA5' LV_TEXT-CTEXTA5 ,
      'KBETRA6' LV_TEXT-CTEXTA6 ,
      'ZCYJE1'  LV_TEXT-ZCYJE1  ,
      'ZCYJE2'  LV_TEXT-ZCYJE2  ,
      'ZCYJE3'  LV_TEXT-ZCYJE3  ,
      'ZCYJE4'  LV_TEXT-ZCYJE4  ,
      'ZCYJE5'  LV_TEXT-ZCYJE5  ,
      'ZCYJE6'  LV_TEXT-ZCYJE6  ,
      'ZCYBL1'  LV_TEXT-ZCYBL1  ,
      'ZCYBL2'  LV_TEXT-ZCYBL2  ,
      'ZCYBL3'  LV_TEXT-ZCYBL3  ,
      'ZCYBL4'  LV_TEXT-ZCYBL4  ,
      'ZCYBL5'  LV_TEXT-ZCYBL5  ,
      'ZCYBL6'  LV_TEXT-ZCYBL6  .

  ENDIF.

ENDFORM.

FORM PF_STATUS_SET USING RT_EXTAB TYPE SLIS_T_EXTAB.
  SET PF-STATUS 'STANDARD_FULLSCREEN'.
ENDFORM.

FORM USER_COMMAND USING I_UCOMM LIKE SY-UCOMM
                    IS_SELFIELD TYPE SLIS_SELFIELD.
  DATA:   REF TYPE REF TO CL_GUI_ALV_GRID.
  DATA :  LV_STABLE TYPE LVC_S_STBL.   "刷新稳定性
  RANGES: L_WERKS FOR T001W-WERKS.
  RANGES: L_MATNR FOR MARA-MATNR.
  DATA:   L_BUKRS TYPE T001K-BUKRS.

  LV_STABLE-ROW = '1'.
  LV_STABLE-COL = '1'.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      E_GRID = REF.
  CALL METHOD REF->CHECK_CHANGED_DATA.

  CASE I_UCOMM.
    WHEN '&IC1'."表示双击
*      IF IS_SELFIELD-FIELDNAME =  'EBELN' .
*        CHECK IS_SELFIELD-TABINDEX > 0.
*        CLEAR GT_DATA_A .
*        READ TABLE GT_DATA_A INDEX IS_SELFIELD-TABINDEX.
*        SET PARAMETER ID 'BES' FIELD GT_DATA_A-EBELN.
*        CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
*      ELSE .
*        MESSAGE '请选择有效字段!'TYPE 'S' DISPLAY LIKE 'W'.
*      ENDIF.
    WHEN 'POST_T'.

  ENDCASE.

  CALL METHOD REF->REFRESH_TABLE_DISPLAY
    EXPORTING
      IS_STABLE = LV_STABLE.

ENDFORM.

FORM F_HTML_TOP_OF_PAGE USING PR_DOCUMENT TYPE REF TO CL_DD_DOCUMENT.
*  IF P_RD1 IS NOT INITIAL.
*    CALL METHOD PR_DOCUMENT->ADD_TEXT(
*        TEXT         = '销售库存周转报表'
**       SAP_FONTSIZE = '1'
*        SAP_EMPHASIS = CL_DD_DOCUMENT=>HEADING ).

*    CALL METHOD PR_DOCUMENT->NEW_LINE( ).

*    CALL METHOD PR_DOCUMENT->ADD_TEXT(
*        TEXT         = '查询时间:' && SY-DATUM(4) && '年' && SY-DATUM+4(2) && '月' && SY-DATUM+6(2) && '日'
*        SAP_EMPHASIS = CL_DD_DOCUMENT=>HEADING ).

*    CALL METHOD PR_DOCUMENT->NEW_LINE( ).

*    CALL METHOD PR_DOCUMENT->ADD_TEXT(
*        TEXT         = '查询期间:' && P_BDATJ && '年' && P_POPER && '月'
*        SAP_EMPHASIS = CL_DD_DOCUMENT=>HEADING ).

*  ELSE.
*    CALL METHOD PR_DOCUMENT->ADD_TEXT(
*        TEXT         = '库存周转率后台运行报表'
**       SAP_FONTSIZE = '1'
*        SAP_EMPHASIS = CL_DD_DOCUMENT=>HEADING ).
*  ENDIF.

*  CALL METHOD PR_DOCUMENT->ADD_GAP( WIDTH = 2 ).

*  CALL METHOD PR_DOCUMENT->ADD_LINK(
*      NAME = '163'
*      URL  = 'www.163.com'
*      TEXT = 'netease' ).

*  CALL METHOD PR_DOCUMENT->ADD_LINK(
*      NAME = 'TEXT01'
*      TEXT = '往来供应商对帐明细表' ).

*  CALL METHOD PR_DOCUMENT->NEW_LINE( ).

*  CALL METHOD PR_DOCUMENT->ADD_LINK(
*      NAME = 'TEXT02'
*      TEXT = GV_TOP ).
ENDFORM.                    "f_html_top_of_page

AT SELECTION-SCREEN OUTPUT.
  PERFORM SCREEN_OUTPUT.

AT SELECTION-SCREEN.
  PERFORM SCREEN_SETTING.

START-OF-SELECTION.

  PERFORM SCREEN_SETTING.
  IF P_RD1 IS NOT INITIAL.
    IF S_PBDNR-LOW IS INITIAL.
      MESSAGE '请输入必输字段!'    TYPE 'S' DISPLAY LIKE 'E'.
    ELSE.
      PERFORM FOM_GETDATA .
      PERFORM FRM_DISPLAY .
    ENDIF.
  ELSEIF P_RD2 IS NOT INITIAL.
    IF S_PBDNR1-LOW IS INITIAL OR S_PBDNR2-LOW IS INITIAL.
      MESSAGE '请输入必输字段!'    TYPE 'S' DISPLAY LIKE 'E'.
    ELSE.
      PERFORM FOM_GETDATA .
      PERFORM FRM_DISPLAY .
    ENDIF.
  ENDIF.

上一篇:SQLServer ------------ 将数字转换成 百分比的形式


下一篇:Oracle 表空间增加删除裸设备