赞
踩
*&---------------------------------------------------------------------*
*& Report ZMMR102
*&---------------------------------------------------------------------*
*& Author : NathanSun
*& Create Date : 2019-06-26
*& Program Type : Report
*& Description : 准时交货率报表
*&---------------------------------------------------------------------*
REPORT ZMMR107.
*&---------------------------------------------------------------------*
*& 包含 YN_TEST02_TOP
*&---------------------------------------------------------------------*
TABLES:EKPO,EKKO,EKET.
TYPE-POOLS:SLIS,T001W.
"定义ALV输出所需变量
DATA: S_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA:TOPMAT LIKE CSTMAT .
DATA:DSTST LIKE CSDATA-XFELD .
DATA:STB LIKE STPOX OCCURS 0 WITH HEADER LINE .
DATA:MATCAT LIKE CSCMAT OCCURS 0 WITH HEADER LINE .
DATA:GT_MARD LIKE MARD OCCURS 0 WITH HEADER LINE .
DATA:GT_MSKA LIKE MSKA OCCURS 0 WITH HEADER LINE .
DATA:E_MT61D LIKE MT61D .
DATA:E_MDKP LIKE MDKP .
DATA:MDPSX LIKE MDPS OCCURS 0 WITH HEADER LINE .
DATA:MDEZX LIKE MDEZ OCCURS 0 WITH HEADER LINE .
DATA:MDSUX LIKE MDSU OCCURS 0 WITH HEADER LINE .
TYPES: BEGIN OF GTS_DATA,
WERKS TYPE EKPO-WERKS, "工厂
LIFNR TYPE EKKO-LIFNR, "供应商
WERKS_C TYPE EKPO-WERKS, "工厂
LIFNR_C TYPE EKKO-LIFNR, "供应商
KOSTL TYPE EKKN-KOSTL, "运至
KTEXT TYPE CSKST-KTEXT, "描述
EBELN TYPE EKKO-EBELN, "PO号码
EBELP TYPE EKPO-EBELP, "项目
ETENR TYPE EKET-ETENR, "计划行
ZITEM TYPE CHAR6, "序号
MATNR TYPE EKPO-MATNR, "物料号
TXZ01 TYPE EKPO-TXZ01, "说明
EINDT TYPE EKET-EINDT, "承诺日期
BUDAT TYPE MATDOC-BUDAT, "收货日期
ZSSHL TYPE CHAR10, "准时收货率
MENGE TYPE EKET-MENGE, "订单数量
ERFMG TYPE MATDOC-ERFMG, "收货数量
ZJHBL TYPE EKET-MENGE, "交货比例
FLAG TYPE C, "标记
FLAGP TYPE C, "标记
CLR TYPE CHAR4, "可以控制行颜色
ZTEXT1 TYPE CHAR10, "Total 分部:
ZTEXT2 TYPE CHAR10, "供应商:
ZTEXT3 TYPE CHAR10, "交易宗数:
ZTEXT4 TYPE CHAR10, "准时交货率:
ZTEXT5 TYPE CHAR10, "准时交货率:&
ZTEXT6 TYPE CHAR10, "准时收货的宗数
ZTEXT7 TYPE WAMNG, "准时交货率N
ZTEXT8 TYPE CHAR10, "交货比例T
END OF GTS_DATA.
DATA: GT_DATA_MATDOC TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_M TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_EKET TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_E TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_HEAD TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GT_DATA_A TYPE TABLE OF GTS_DATA WITH HEADER LINE.
DATA: GV_TOP TYPE SDYDO_TEXT_ELEMENT.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS: S_BUKRS FOR EKKO-BUKRS MODIF ID C1 . "公司代码
SELECT-OPTIONS: S_WERKS FOR EKPO-WERKS MODIF ID C1 . "工厂
SELECT-OPTIONS: S_EKORG FOR EKKO-EKORG MODIF ID C1 . "采购组织
SELECT-OPTIONS: S_LIFNR FOR EKKO-LIFNR MODIF ID C1 . "供应商
SELECT-OPTIONS: S_EINDT FOR EKET-EINDT MODIF ID C1 OBLIGATORY. "期间
PARAMETERS: S_RCFTQ TYPE NUMC3 MODIF ID C1 . "提前容差范围
PARAMETERS: S_RCFZH TYPE NUMC3 MODIF ID C1 . "推后容差范围
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& Form SCREEN_SETTING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SCREEN_SETTING .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FOM_GETDATA .
DATA LV_SUM TYPE CHAR6 .
DATA LV_SUMP TYPE CHAR6 .
DATA LV_ETENR TYPE EETEN .
DATA LV_NEW TYPE C .
DATA LV_END TYPE C .
DATA LV_NE TYPE N .
DATA LV_NM TYPE N .
*计划行维度
CLEAR GT_DATA_EKET[] .
SELECT EKPO~EBELN
EKPO~EBELP
EKPO~WERKS
EKPO~MATNR
EKPO~TXZ01
EKET~ETENR
EKET~EINDT
EKET~MENGE
EKKO~BUKRS
EKKO~LIFNR
FROM EKPO
INNER JOIN EKET ON EKPO~EBELN = EKET~EBELN AND EKPO~EBELP = EKET~EBELP
* INNER JOIN MATDOC ON EKPO~EBELN = MATDOC~EBELN AND EKPO~EBELP = MATDOC~EBELP
INNER JOIN EKKO ON EKPO~EBELN = EKKO~EBELN
INTO CORRESPONDING FIELDS OF TABLE GT_DATA_EKET[]
WHERE EKKO~BUKRS IN S_BUKRS
AND EKPO~WERKS IN S_WERKS
AND EKKO~EKORG IN S_EKORG
AND EKKO~LIFNR IN S_LIFNR
* AND MATDOC~CANCELLED = ''
* AND MATDOC~REVERSAL_MOVEMENT = ''
AND EKET~EINDT IN S_EINDT
.
*收货维度
CLEAR GT_DATA_MATDOC[] .
SELECT EKPO~EBELN
EKPO~EBELP
EKPO~WERKS
EKPO~MATNR
EKPO~TXZ01
MATDOC~BUDAT
MATDOC~ERFMG
EKKO~BUKRS
EKKO~LIFNR
FROM EKPO
* INNER JOIN EKET ON EKPO~EBELN = EKET~EBELN AND EKPO~EBELP = EKET~EBELP
INNER JOIN MATDOC ON EKPO~EBELN = MATDOC~EBELN AND EKPO~EBELP = MATDOC~EBELP
INNER JOIN EKKO ON EKPO~EBELN = EKKO~EBELN
INTO CORRESPONDING FIELDS OF TABLE GT_DATA_MATDOC[]
WHERE EKKO~BUKRS IN S_BUKRS
AND EKPO~WERKS IN S_WERKS
AND EKKO~EKORG IN S_EKORG
AND EKKO~LIFNR IN S_LIFNR
AND MATDOC~CANCELLED = ''
AND MATDOC~REVERSAL_MOVEMENT = ''
* AND EKET~EINDT IN S_EINDT
.
GT_DATA_HEAD[] = GT_DATA_EKET[] .
SORT GT_DATA_HEAD[] BY EBELN EBELP .
DELETE ADJACENT DUPLICATES FROM GT_DATA_HEAD[] COMPARING EBELN EBELP.
CLEAR GT_DATA[] .
LOOP AT GT_DATA_HEAD.
CLEAR GT_DATA_E[] .
LOOP AT GT_DATA_EKET WHERE EBELN = GT_DATA_HEAD-EBELN AND EBELP = GT_DATA_HEAD-EBELP.
APPEND GT_DATA_EKET TO GT_DATA_E[] .
CLEAR GT_DATA_EKET .
ENDLOOP.
CLEAR LV_NE .
LV_NE = LINES( GT_DATA_E[] ) .
CLEAR GT_DATA_M[] .
LOOP AT GT_DATA_MATDOC WHERE EBELN = GT_DATA_HEAD-EBELN AND EBELP = GT_DATA_HEAD-EBELP.
APPEND GT_DATA_MATDOC TO GT_DATA_M[] .
CLEAR GT_DATA_MATDOC .
ENDLOOP.
CLEAR LV_NM .
LV_NM = LINES( GT_DATA_M[] ) .
SORT GT_DATA_M[] BY BUDAT .
CLEAR LV_ETENR .
LOOP AT GT_DATA_M.
ADD 1 TO LV_ETENR .
GT_DATA_M-ETENR = LV_ETENR .
MODIFY GT_DATA_M.
CLEAR GT_DATA_M.
ENDLOOP.
IF LV_NM > LV_NE.
SORT GT_DATA_E[] BY ETENR DESCENDING .
LOOP AT GT_DATA_M.
CLEAR GT_DATA_E.
READ TABLE GT_DATA_E WITH KEY EBELN = GT_DATA_M-EBELN EBELP = GT_DATA_M-EBELP ETENR = GT_DATA_M-ETENR .
GT_DATA_M-ETENR = GT_DATA_E-ETENR .
GT_DATA_M-EINDT = GT_DATA_E-EINDT .
GT_DATA_M-MENGE = GT_DATA_E-MENGE .
IF SY-SUBRC <> 0.
READ TABLE GT_DATA_E INDEX 1.
GT_DATA_M-ETENR = GT_DATA_E-ETENR .
GT_DATA_M-EINDT = GT_DATA_E-EINDT .
GT_DATA_M-MENGE = GT_DATA_E-MENGE .
ENDIF.
APPEND GT_DATA_M TO GT_DATA[] .
MODIFY GT_DATA_M.
CLEAR GT_DATA_M.
ENDLOOP.
ELSE.
LOOP AT GT_DATA_E.
CLEAR GT_DATA_M.
READ TABLE GT_DATA_M WITH KEY EBELN = GT_DATA_E-EBELN EBELP = GT_DATA_E-EBELP ETENR = GT_DATA_E-ETENR .
GT_DATA_E-BUDAT = GT_DATA_M-BUDAT .
GT_DATA_E-ERFMG = GT_DATA_M-ERFMG .
APPEND GT_DATA_E TO GT_DATA[] .
MODIFY GT_DATA_E.
CLEAR GT_DATA_E.
ENDLOOP.
ENDIF.
ENDLOOP.
DELETE GT_DATA[] WHERE EINDT NOT IN S_EINDT .
SORT GT_DATA[] BY WERKS LIFNR EBELN EBELP ETENR.
CLEAR LV_SUM .
CLEAR LV_SUMP .
LOOP AT GT_DATA WHERE FLAG IS INITIAL.
CLEAR LV_NEW .
AT NEW LIFNR .
LV_NEW = 'X'.
ENDAT .
CLEAR LV_END .
AT END OF LIFNR .
LV_END = 'X'.
ENDAT .
SELECT SINGLE KOSTL INTO GT_DATA-KOSTL FROM EKKN
WHERE EBELN = GT_DATA-EBELN
AND EBELP = GT_DATA-EBELP
.
SELECT SINGLE KTEXT INTO GT_DATA-KTEXT FROM CSKT
WHERE KOSTL = GT_DATA-KOSTL
AND SPRAS = SY-LANGU
.
IF GT_DATA-BUDAT IS NOT INITIAL.
IF GT_DATA-BUDAT >= GT_DATA-EINDT."滞后
IF GT_DATA-BUDAT - GT_DATA-EINDT - S_RCFZH > 0.
GT_DATA-FLAGP = 'X'.
GT_DATA-ZSSHL = '0%'.
ELSE.
GT_DATA-ZSSHL = '100%'.
ENDIF.
ELSE . "提前
IF GT_DATA-EINDT - GT_DATA-BUDAT - S_RCFTQ > 0.
GT_DATA-FLAGP = 'X'.
GT_DATA-ZSSHL = '0%'.
ELSE.
GT_DATA-ZSSHL = '100%'.
ENDIF.
ENDIF.
ELSE .
GT_DATA-FLAGP = 'X'.
GT_DATA-ZSSHL = '0%'.
ENDIF.
IF LV_NEW IS NOT INITIAL.
CLEAR LV_SUM .
CLEAR LV_SUMP .
ENDIF.
ADD 1 TO LV_SUM .
GT_DATA-ZITEM = LV_SUM .
IF GT_DATA-FLAGP IS INITIAL .
ADD 1 TO LV_SUMP .
ENDIF.
GT_DATA-ZTEXT6 = LV_SUMP .
IF LV_END IS NOT INITIAL.
CLEAR GT_DATA_A.
GT_DATA_A-WERKS = GT_DATA-WERKS .
GT_DATA_A-LIFNR = GT_DATA-LIFNR .
GT_DATA_A-WERKS_C = GT_DATA-WERKS .
GT_DATA_A-LIFNR_C = GT_DATA-LIFNR .
GT_DATA_A-ZITEM = GT_DATA-ZITEM .
GT_DATA_A-ZTEXT6 = GT_DATA-ZTEXT6 .
GT_DATA_A-FLAG = 'X'.
GT_DATA_A-ZTEXT1 = 'Total 分部:'.
GT_DATA_A-ZTEXT2 = '供应商:'.
GT_DATA_A-ZTEXT3 = '交易宗数:'.
GT_DATA_A-ZTEXT4 = '准时交货率:'.
IF GT_DATA_A-ZITEM <> 0.
GT_DATA_A-ZTEXT7 = GT_DATA_A-ZTEXT6 / GT_DATA_A-ZITEM * 100.
GT_DATA_A-ZTEXT5 = GT_DATA_A-ZTEXT7 && '%' .
ENDIF.
GT_DATA_A-CLR = 'C310'.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_DATA_A-LIFNR_C
IMPORTING
OUTPUT = GT_DATA_A-LIFNR_C.
APPEND GT_DATA_A TO GT_DATA .
ENDIF.
*SELECT SINGLE
GT_DATA-WERKS_C = GT_DATA-WERKS .
GT_DATA-LIFNR_C = GT_DATA-LIFNR .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_DATA-LIFNR_C
IMPORTING
OUTPUT = GT_DATA-LIFNR_C.
* 'MENGE' '订单数量',
* 'ERFMG' '收货数量',
IF GT_DATA-MENGE <> 0.
GT_DATA-ZJHBL = GT_DATA-ERFMG / GT_DATA-MENGE * 100.
ENDIF.
GT_DATA-ZTEXT8 = GT_DATA-ZJHBL && '%' .
MODIFY GT_DATA.
CLEAR GT_DATA.
ENDLOOP.
SORT GT_DATA[] BY WERKS LIFNR FLAG ZITEM.
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-INFO_FIELDNAME = 'CLR'. "行颜色代码的字段
* s_layout-box_fieldname = 'BOX'.
PERFORM FRM_FILL_FIELD .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
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'
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 = 'AUFNR' .
wa_fieldcat-ref_tabname = 'AUFK'.
wa_fieldcat-ref_fieldname = 'AUFNR'.
ENDIF.
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
END-OF-DEFINITION.
FILL_FIELD :
'ZTEXT1' '',
'WERKS_C' '工厂',
'ZTEXT2' '',
'LIFNR_C' '供应商',
'KOSTL' '运至',
'KTEXT' '描述',
'EBELN' 'PO号码',
'EBELP' '项目',
'ETENR' '计划行',
'ZTEXT3' '',
'ZITEM' '序号',
'MATNR' '物料号',
'TXZ01' '说明',
'EINDT' '承诺日期',
'BUDAT' '收货日期',
'ZSSHL' '准时收货率',
'ZTEXT4' '',
'ZTEXT5' '',
'MENGE' '订单数量',
'ERFMG' '收货数量',
'ZTEXT8' '交货比例'.
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'."表示双击
WHEN 'POST_T'.
ENDCASE.
CALL METHOD REF->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LV_STABLE.
ENDFORM.
INITIALIZATION .
AT SELECTION-SCREEN.
PERFORM SCREEN_SETTING.
START-OF-SELECTION.
PERFORM FOM_GETDATA .
PERFORM FRM_DISPLAY.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。