*&---------------------------------------------------------------------*
*& Report ZPPR006
*&---------------------------------------------------------------------*
*& Author : NathanSun
*& Create Date : 2019-06-26
*& Program Type : Report
*& Description : 工单异常报表
*&---------------------------------------------------------------------*
REPORT ZPPR006.
*&---------------------------------------------------------------------*
*& 包含 ZMMR118_TOP
*&---------------------------------------------------------------------*
TABLES:AFPO,AFKO.
TYPE-POOLS:SLIS,T001W,ICON.
"定义ALV输出所需变量
DATA: S_LAYOUT TYPE LVC_S_LAYO,
GT_FIELDCAT TYPE LVC_T_FCAT,
IS_VARIANT TYPE DISVARIANT.
DATA: G_TITLE_0200 TYPE STRING,
LV_SUM TYPE STRING,
G_INDEX TYPE SY-INDEX.
DATA GT_EXDATA TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA IW_CELLCOLOR TYPE LVC_T_SCOL WITH HEADER LINE.
DATA L_FILENAME TYPE STRING .
DATA L_MUBAN TYPE STRING .
DATA GV_FULLPATH TYPE STRING .
DATA GV_PATH TYPE STRING .
DATA GV_NAME TYPE STRING .
DATA:FLAG TYPE C .
DATA:I_EVENTS TYPE SLIS_T_EVENT.
DATA:W_EVENTS LIKE LINE OF I_EVENTS.
DATA REF_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA OK_CODE TYPE SY-UCOMM.
DATA OK_SAVE TYPE SY-UCOMM.
TYPES: BEGIN OF GTS_DATA,
PWERK TYPE AFPO-PWERK, "工厂
AUFNR TYPE AFPO-AUFNR, "工单号码
OBJNR TYPE AUFK-OBJNR, "对象号
MATNR TYPE AFPO-MATNR, "产品料号
MAKTX TYPE MAKT-MAKTX, "物料名称
DISPO TYPE AFKO-DISPO, "MRP控制员
FEVOR TYPE AFKO-FEVOR, "生产管理员
GSTRP TYPE AFKO-GSTRP, "基本开始日期
GLTRP TYPE AFKO-GLTRP, "基本完成日期
PSMNG TYPE AFPO-PSMNG, "计划数量
GMNGA TYPE AFRU-GMNGA, "报工数量
WEMNG TYPE AFPO-WEMNG, "收货数量
MEINS TYPE AFPO-MEINS, "单位
LTRMI TYPE AFPO-LTRMI, "收货日期
STTXT TYPE BSVX-STTXT, "工单状态
TYPE TYPE C, "标识
TYPE2 TYPE C, "标识
CF1 TYPE CHAR4, "发料异常警示
CF2 TYPE CHAR4, "报工异常警示
DATUM_JY TYPE DATUM, "建议月结日期
DATUM_SJ TYPE DATUM, "实际月结日期
ZBEZU TYPE CHAR30, "原因分析
CELLCOLOR TYPE LVC_T_SCOL, "单元格颜色
STYLE TYPE LVC_T_STYL, "控制不可编辑
END OF GTS_DATA.
TYPES: BEGIN OF GTS_SUB01 ,
CF1 TYPE CHAR4, "发料异常警示
PWERK TYPE AFPO-PWERK, "工厂
AUFNR TYPE AUFK-AUFNR, "工单号
ERDAT TYPE AUFK-ERDAT, "工单日期
MATNR TYPE AFPO-MATNR, "成品项目号
AUART TYPE AUFK-AUART, "工单类型
OBJNR TYPE AUFK-OBJNR, "工单状态
STTXT TYPE BSVX-STTXT, "工单状态
STLAN TYPE AFKO-STLAN, "BOM类型
MAKTX TYPE MAKT-MAKTX, "成品项目说明
PSMNG TYPE AFPO-PSMNG, "成品定单数量
WEMNG TYPE AFPO-WEMNG, "成品完工数量
AMEIN TYPE AFPO-AMEIN, "成品单位
MATNR_Z TYPE RESB-MATNR, "子件项目号
MAKTX_Z TYPE MAKT-MAKTX, "子件项目号说明
WERKS_Z TYPE RESB-WERKS, "子件发料工厂
MEINS_S TYPE RESB-MEINS, "子件单位
MEINS TYPE RESB-MEINS, "子件单位
DATUV TYPE STPO-DATUV, "工单状态
MENGE TYPE STPO-MENGE, "子件BOM数量
BMENG TYPE STKO-BMENG, "基本数量
BDMNG TYPE RESB-BDMNG, "子件计划数量
MENGE_Y TYPE MSEG-MENGE, "子件已发数量
MENGE_G TYPE MSEG-MENGE, "工单产出数
MENGE_T TYPE MSEG-MENGE, "退料数
MENGE_C TYPE MSEG-MENGE, "差异数
CYBL_C TYPE MSEG-MENGE, "差异比例
END OF GTS_SUB01.
TYPES: BEGIN OF GTS_SUB02,
PWERK TYPE AFPO-PWERK, "工厂
AUFNR TYPE AFPO-AUFNR, "工单号
MATNR TYPE AFPO-MATNR, "产品型号
PSMNG TYPE AFPO-PSMNG, "工单数量
MEINS TYPE AFPO-MEINS, "单位
GMNGA TYPE AFRU-GMNGA, "报工数
VORNR TYPE AFVC-VORNR, "工序
VGW01 TYPE AFVV-VGW01, "标准准备工时
VGW02 TYPE AFVV-VGW02, "标准机器工时
VGW03 TYPE AFVV-VGW03, "标准人工工时
ISM01 TYPE AFRU-ISM01, "实际准备工时
ISM02 TYPE AFRU-ISM02, "实际机器工时
ISM03 TYPE AFRU-ISM03, "实际人工工时
ZXYZB TYPE AFVV-VGW01, "差异准备工时
ZXYJQ TYPE AFVV-VGW01, "差异机器工时
ZXYRG TYPE AFVV-VGW01, "差异人工工时
AUFPL TYPE AFKO-AUFPL, "工艺路线
RMZHL TYPE AFKO-RMZHL, "内部计数器
RUECK TYPE AFKO-RUECK, "操作完成的确认编号
END OF GTS_SUB02.
DATA: LV_POP TYPE MSEG-MENGE VALUE '1'. "比例系数
DATA: GT_S01 TYPE TABLE OF GTS_SUB01 WITH HEADER LINE.
DATA: GT_SU01 TYPE TABLE OF GTS_SUB01 WITH HEADER LINE.
DATA: GT_SUB01 TYPE TABLE OF GTS_SUB01 WITH HEADER LINE.
DATA: GT_SUB01A TYPE TABLE OF GTS_SUB01 WITH HEADER LINE.
DATA: GT_S02 TYPE TABLE OF GTS_SUB02 WITH HEADER LINE.
DATA: GT_SU02 TYPE TABLE OF GTS_SUB02 WITH HEADER LINE.
DATA: GT_SUB02 TYPE TABLE OF GTS_SUB02 WITH HEADER LINE.
DATA: GT_SUB02A TYPE TABLE OF GTS_SUB02 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: JEST TYPE TABLE OF JEST WITH HEADER LINE.
DATA: MESSAGE TYPE BAPI_MSG. "报错信息.
DATA: BEGIN OF STATUS_TMP OCCURS 0,
STAT LIKE JEST-STAT,
EXCL LIKE RC27X-FLG_SEL,
END OF STATUS_TMP.
DATA: STATUS_HDR_TAB LIKE STATUS_TMP OCCURS 0 WITH HEADER LINE,
STATUS_OPR_TAB LIKE STATUS_TMP OCCURS 0 WITH HEADER LINE,
STATUS_CMP_TAB LIKE STATUS_TMP OCCURS 0 WITH HEADER LINE.
TYPES:
BEGIN OF TYP_S_AUFNR,
AUFNR TYPE AUFNR,
END OF TYP_S_AUFNR,
TYP_TS_AUFNR TYPE SORTED TABLE OF TYP_S_AUFNR
WITH NON-UNIQUE KEY AUFNR,
BEGIN OF TYP_S_OBJNR,
AUFNR TYPE AUFNR,
AUFPL TYPE CO_AUFPL,
APLFL TYPE PLNFOLGE,
PLNFL TYPE PLNFOLGE,
OBJNR TYPE J_OBJNR,
END OF TYP_S_OBJNR,
TYP_TS_AUFNR_OBJNR TYPE SORTED TABLE OF TYP_S_OBJNR
WITH NON-UNIQUE KEY AUFNR OBJNR,
TYP_TS_AUFPL_OBJNR TYPE SORTED TABLE OF TYP_S_OBJNR
WITH NON-UNIQUE KEY AUFPL OBJNR,
TYP_TS_OBJNR TYPE SORTED TABLE OF TYP_S_OBJNR,
BEGIN OF TYP_S_VBELN,
VBELN TYPE VBELN,
END OF TYP_S_VBELN,
TYP_TS_VBELN TYPE SORTED TABLE OF TYP_S_VBELN
WITH NON-UNIQUE KEY VBELN.
DATA: YX VALUE 'X'.
*&SPWIZARD: DECLARATION OF TABLECONTROL 'TBC_01' ITSELF
CONTROLS: TBC_01 TYPE TABLEVIEW USING SCREEN 0100.
*&SPWIZARD: LINES OF TABLECONTROL 'TBC_01'
DATA: G_TBC_01_LINES LIKE SY-LOOPC.
*&SPWIZARD: DECLARATION OF TABLECONTROL 'TBC_02' ITSELF
CONTROLS: TBC_02 TYPE TABLEVIEW USING SCREEN 0200.
*&SPWIZARD: LINES OF TABLECONTROL 'TBC_02'
DATA: G_TBC_02_LINES LIKE SY-LOOPC.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME.
*PARAMETERS P_AUFNR TYPE AUFK-AUFNR MODIF ID MXY .
*PARAMETERS P_BOX2 TYPE C AS CHECKBOX MODIF ID MXY .
SELECT-OPTIONS S_PWERK FOR AFPO-PWERK MODIF ID MXZ . "工厂
SELECT-OPTIONS S_MATNR FOR AFPO-MATNR MODIF ID MXZ . "物料
SELECT-OPTIONS S_AUFNR FOR AFPO-AUFNR MODIF ID MXZ . "工单
SELECT-OPTIONS S_GSTRP FOR AFKO-GSTRP MODIF ID MXZ . "开始日期
SELECT-OPTIONS S_GLTRP FOR AFKO-GLTRP MODIF ID MXZ . "完成日期
SELECT-OPTIONS S_GLTRI FOR AFKO-GLTRI MODIF ID MXZ . "工单实际完成日期
SELECT-OPTIONS S_DISPO FOR AFKO-DISPO MODIF ID MXZ . "MRP控制员
SELECT-OPTIONS S_FEVOR FOR AFKO-FEVOR MODIF ID MXZ . "生产管理员
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN:
COMMENT 1(20) TEXT-SYS FOR FIELD P_SYST1 MODIF ID C1,
POSITION 33.
PARAMETERS:
P_SYST1 LIKE TJ02T-TXT04 MODIF ID C1,
P_SYSH1 LIKE JEST-STAT NO-DISPLAY.
SELECTION-SCREEN
POSITION 46.
PARAMETERS:
P_EXCL1 LIKE RCOSA-EXCL1 MODIF ID C1.
SELECTION-SCREEN:
COMMENT 40(5) TEXT-EXC FOR FIELD P_EXCL1 MODIF ID C1,
COMMENT 52(3) TEXT-AND FOR FIELD P_SYST2 MODIF ID C1,
POSITION 58.
PARAMETERS:
P_SYST2 LIKE TJ02T-TXT04 MODIF ID C1,
P_SYSH2 LIKE JEST-STAT NO-DISPLAY.
SELECTION-SCREEN
POSITION 71.
PARAMETERS:
P_EXCL2 LIKE RCOSA-EXCL1 MODIF ID C1.
SELECTION-SCREEN:
COMMENT 65(5) TEXT-EXC FOR FIELD P_EXCL2 MODIF ID C1.
SELECTION-SCREEN END OF LINE.
PARAMETERS:
P_SELID LIKE TJ48T-SELID NO-DISPLAY.
PARAMETERS P_BOX TYPE C AS CHECKBOX MODIF ID MXZ .
SELECTION-SCREEN END OF BLOCK B2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_SYST1.
PERFORM VAL_REQ_STATUS USING 'P_SYST1' CHANGING P_SYST1 P_SYSH1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_SYST2.
PERFORM VAL_REQ_STATUS USING 'P_SYST2' CHANGING P_SYST2 P_SYSH2.
*&---------------------------------------------------------------------*
*& 包含 ZMMR118_CLASS
*&---------------------------------------------------------------------*
*CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
CLASS LCL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
DATA: UCOMM TYPE SY-UCOMM.
METHODS HANDLE_DATA_CHANGED
FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
IMPORTING ER_DATA_CHANGED.
METHODS:HANDLE_BUTTON_CLICK
FOR EVENT BUTTON_CLICK OF CL_GUI_ALV_GRID
IMPORTING ES_ROW_NO ES_COL_ID.
PRIVATE SECTION.
ENDCLASS. "lcl_event_receiver DEFINITION
DATA: EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_DATA_CHANGED.
ENDMETHOD. "handle_data_changed
METHOD HANDLE_BUTTON_CLICK.
CLEAR:G_INDEX.
G_INDEX = ES_ROW_NO-ROW_ID.
READ TABLE GT_DATA[] INTO GT_DATA INDEX ES_ROW_NO-ROW_ID.
IF ES_COL_ID-FIELDNAME = 'CF1'.
CLEAR GT_SUB01[] .
LOOP AT GT_SUB01A INTO GT_SUB01A WHERE PWERK = GT_DATA-PWERK
AND AUFNR = GT_DATA-AUFNR
AND MATNR = GT_DATA-MATNR
.
SELECT SINGLE MAKTX INTO GT_SUB01A-MAKTX FROM MAKT
WHERE MATNR = GT_SUB01A-MATNR
.
SELECT SINGLE MAKTX INTO GT_SUB01A-MAKTX_Z FROM MAKT
WHERE MATNR = GT_SUB01A-MATNR_Z
.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_SUB01A-AUFNR
IMPORTING
OUTPUT = GT_SUB01A-AUFNR.
APPEND GT_SUB01A TO GT_SUB01[] .
CLEAR GT_SUB01A .
ENDLOOP.
CALL SCREEN 0100 STARTING AT 3 3.
ELSE .
CLEAR GT_SUB02[] .
LOOP AT GT_SUB02A INTO GT_SUB02A WHERE PWERK = GT_DATA-PWERK
AND AUFNR = GT_DATA-AUFNR
AND MATNR = GT_DATA-MATNR
.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_SUB02A-AUFNR
IMPORTING
OUTPUT = GT_SUB02A-AUFNR.
APPEND GT_SUB02A TO GT_SUB02[] .
CLEAR GT_SUB02A .
ENDLOOP.
CALL SCREEN 0200 STARTING AT 3 3.
ENDIF.
PERFORM FRM_REF_ALV.
ENDMETHOD.
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
*&---------------------------------------------------------------------*
*& 包含 ZMMR118_FORM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form SCREEN_SETTING
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SCREEN_SETTING .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FOM_GETDATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FOM_GETDATA .
DATA: LTS_OBJNR TYPE TYP_TS_AUFNR_OBJNR.
DATA: GT_AFRU TYPE TABLE OF AFRU WITH HEADER LINE.
DATA: GS_AFKO TYPE AFKO.
DATA: GS_AFVC TYPE AFVC.
DATA: LINE TYPE BSVX-STTXT.
DATA: LV_OBJNR TYPE JEST-OBJNR.
DATA: GT_MSEG TYPE TABLE OF MSEG WITH HEADER LINE.
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: LS_STYLE TYPE LVC_S_STYL.
DATA: LT_STYLE TYPE TABLE OF LVC_S_STYL.
DATA: GT_AFRU1 TYPE TABLE OF AFRU WITH HEADER LINE.
DATA: GT_AFVV TYPE TABLE OF AFVV WITH HEADER LINE.
* APPEND STATUS TO IMPORTED TABLE FOR HEADER SELECTION
PERFORM FILL_STATUS_TABLE
TABLES STATUS_HDR_TAB
USING P_SYST1
P_SYSH1
P_EXCL1
P_SYST2
P_SYSH2
P_EXCL2
.
CLEAR LTS_OBJNR[] .
SELECT AUFNR OBJNR FROM AUFK
INTO CORRESPONDING FIELDS OF TABLE LTS_OBJNR[]
WHERE WERKS IN S_PWERK
AND AUFNR IN S_AUFNR
.
IF STATUS_HDR_TAB[] IS NOT INITIAL.
PERFORM REDUCE_AUFNR_OBJNR_BY_STATUS
TABLES STATUS_HDR_TAB
USING P_SELID
CHANGING LTS_OBJNR[].
ENDIF.
IF LTS_OBJNR[] IS NOT INITIAL.
CLEAR GT_DATA[] .
SELECT
AFPO~PWERK
AFPO~AUFNR
AFPO~MATNR
AFPO~PSMNG
AFPO~WEMNG
AFPO~MEINS
AFPO~LTRMI
AFKO~DISPO
AFKO~FEVOR
AFKO~GSTRP
AFKO~GLTRP
AUFK~OBJNR
INTO CORRESPONDING FIELDS OF TABLE GT_DATA[]
FROM AFPO
INNER JOIN AFKO ON AFPO~AUFNR = AFKO~AUFNR
INNER JOIN AUFK ON AFPO~AUFNR = AUFK~AUFNR
FOR ALL ENTRIES IN LTS_OBJNR[]
WHERE AFPO~AUFNR = LTS_OBJNR-AUFNR
AND AFPO~PWERK IN S_PWERK
AND AFPO~MATNR IN S_MATNR
AND AFPO~AUFNR IN S_AUFNR
AND AFKO~GSTRP IN S_GSTRP
AND AFKO~GLTRP IN S_GLTRP
AND AFKO~GLTRI IN S_GLTRI
AND AFKO~DISPO IN S_DISPO
AND AFKO~FEVOR IN S_FEVOR
.
CLEAR GT_SUB01A[] .
CLEAR GT_SUB02A[] .
LOOP AT GT_DATA.
SELECT SINGLE MAKTX INTO GT_DATA-MAKTX FROM MAKT
WHERE MATNR = GT_DATA-MATNR
.
* 最后一道工序
CLEAR GS_AFKO .
SELECT SINGLE AUFPL INTO CORRESPONDING FIELDS OF GS_AFKO FROM AFKO
WHERE AUFNR = GT_DATA-AUFNR
.
CLEAR GS_AFVC .
SELECT MAX( AFVC~VORNR ) INTO GS_AFVC-VORNR FROM AFVC
WHERE AFVC~AUFPL = GS_AFKO-AUFPL
.
* 报工数量
CLEAR GT_AFRU[] .
SELECT GMNGA INTO CORRESPONDING FIELDS OF TABLE GT_AFRU[] FROM AFRU
WHERE AUFNR = GT_DATA-AUFNR
AND VORNR = GS_AFVC-VORNR
AND STOKZ = ''
AND STZHL = ''
.
CLEAR GT_DATA-GMNGA .
LOOP AT GT_AFRU.
GT_DATA-GMNGA = GT_DATA-GMNGA + GT_AFRU-GMNGA .
CLEAR GT_AFRU .
ENDLOOP.
* 工单状态
CALL FUNCTION 'STATUS_TEXT_EDIT'
EXPORTING
CLIENT = SY-MANDT
OBJNR = GT_DATA-OBJNR
ONLY_ACTIVE = 'X'
SPRAS = SY-LANGU
IMPORTING
LINE = GT_DATA-STTXT.
* 建议月结日期
GT_DATA-DATUM_JY = GT_DATA-GLTRP + 1 .
*------------------------------------------------------------------------------
* 发料异常警示
*------------------------------------------------------------------------------
CLEAR GT_DATA-TYPE .
CLEAR GT_SU01[] .
SELECT
AFPO~PWERK
AUFK~AUFNR
AUFK~ERDAT
AUFK~AUART
AUFK~OBJNR
AFKO~STLAN
AFPO~MATNR
AFPO~PSMNG
AFPO~WEMNG
AFPO~AMEIN
RESB~MATNR AS MATNR_Z
RESB~WERKS AS WERKS_Z
RESB~MEINS
RESB~BDMNG
INTO CORRESPONDING FIELDS OF TABLE GT_SU01[]
FROM RESB
INNER JOIN AFPO ON RESB~AUFNR = AFPO~AUFNR AND RESB~BAUGR = AFPO~MATNR
INNER JOIN AFKO ON AFPO~AUFNR = AFKO~AUFNR
INNER JOIN AUFK ON AFKO~AUFNR = AUFK~AUFNR
WHERE AFPO~PWERK = GT_DATA-PWERK
AND AUFK~AUFNR = GT_DATA-AUFNR
AND AFPO~MATNR = GT_DATA-MATNR
.
GT_S01[] = GT_SU01[] .
SORT GT_SU01[] BY PWERK AUFNR MATNR WERKS_Z MATNR_Z .
DELETE ADJACENT DUPLICATES FROM GT_SU01[] COMPARING PWERK AUFNR MATNR WERKS_Z MATNR_Z.
LOOP AT GT_SU01.
CLEAR GT_SU01-BDMNG .
LOOP AT GT_S01 WHERE PWERK = GT_SU01-PWERK
AND AUFNR = GT_SU01-AUFNR
AND MATNR = GT_SU01-MATNR
AND WERKS_Z = GT_SU01-WERKS_Z
AND MATNR_Z = GT_SU01-MATNR_Z
.
GT_SU01-BDMNG = GT_SU01-BDMNG + GT_S01-BDMNG .
CLEAR GT_S01 .
ENDLOOP.
* 子件BOM数量:
CLEAR STB[] .
CLEAR MATCAT[] .
CLEAR TOPMAT .
CLEAR DSTST .
CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
EXPORTING
CAPID = 'PP01' "应用程序
DATUV = SY-DATUM "系统的当前日期
MTNRV = GT_SU01-MATNR "要展开BOM的物料
WERKS = GT_SU01-PWERK "工厂
EMENG = GT_SU01-PSMNG "需求数量
IMPORTING
TOPMAT = TOPMAT
DSTST = DSTST
TABLES
STB = STB "展开的BOM存放在该内表
MATCAT = MATCAT "下面含有元件的物料存放在该内表
EXCEPTIONS
ALT_NOT_FOUND = 1
CALL_INVALID = 2
MATERIAL_NOT_FOUND = 3
MISSING_AUTHORIZATION = 4
NO_BOM_FOUND = 5
NO_PLANT_DATA = 6
NO_SUITABLE_BOM_FOUND = 7
CONVERSION_ERROR = 8
OTHERS = 9.
READ TABLE STB WITH KEY IDNRK = GT_SU01-MATNR_Z .
IF SY-SUBRC = 0 .
GT_SU01-MEINS_S = STB-MMEIN .
GT_SU01-MENGE = STB-MNGLG .
ENDIF.
* 单位转换
IF GT_SU01-MEINS_S <> GT_SU01-MEINS.
CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
EXPORTING
I_MATNR = GT_SU01-MATNR_Z
I_IN_ME = GT_SU01-MEINS_S
I_OUT_ME = GT_SU01-MEINS
I_MENGE = GT_SU01-MENGE
IMPORTING
E_MENGE = GT_SU01-MENGE
EXCEPTIONS
ERROR_IN_APPLICATION = 1
ERROR = 2
OTHERS = 3.
ENDIF.
* 子件已发数量:
CLEAR GT_MSEG[] .
SELECT MENGE MATNR AUFNR BWART INTO CORRESPONDING FIELDS OF TABLE GT_MSEG[] FROM MSEG
WHERE BWART IN ( '261','262' )
AND MATNR = GT_SU01-MATNR_Z
AND AUFNR = GT_SU01-AUFNR
AND WERKS = GT_SU01-WERKS_Z
.
CLEAR GT_SU01-MENGE_T .
LOOP AT GT_MSEG .
IF GT_MSEG-BWART = '262'.
* 子件退料数量:
GT_SU01-MENGE_T = GT_SU01-MENGE_T + GT_MSEG-MENGE .
GT_MSEG-MENGE = GT_MSEG-MENGE * -1 .
ENDIF.
GT_SU01-MENGE_Y = GT_SU01-MENGE_Y + GT_MSEG-MENGE .
CLEAR GT_MSEG .
ENDLOOP.
* 差异数: 订单BOM用量数 - 已发数
GT_SU01-MENGE_C = GT_SU01-MENGE - GT_SU01-MENGE_Y .
* 差异比例
IF GT_SU01-MENGE <> 0.
GT_SU01-CYBL_C = GT_SU01-MENGE_C / GT_SU01-MENGE .
ENDIF.
* MENGE_C TYPE MSEG-MENGE, "差异数
* CYBL_C TYPE STRING, "差异比例
IF GT_SU01-MENGE_Y < GT_SU01-MENGE * LV_POP.
GT_DATA-TYPE = 'E'.
GT_SU01-CF1 = '@0A@'.
ELSE .
GT_SU01-CF1 = '@08@'.
ENDIF.
MODIFY GT_SU01 .
CLEAR GT_SU01 .
ENDLOOP.
APPEND LINES OF GT_SU01[] TO GT_SUB01A[] .
CLEAR LT_STYLE[] .
CLEAR LS_STYLE .
IF GT_DATA-TYPE = 'E'.
GT_DATA-CF1 = '@0A@'.
LS_STYLE-FIELDNAME = 'CF1'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
ELSE .
GT_DATA-CF1 = '@08@'.
ENDIF.
*------------------------------------------------------------------------------
* 发料异常警示
*------------------------------------------------------------------------------
*------------------------------------------------------------------------------
* 报工异常警示
*------------------------------------------------------------------------------
CLEAR GT_DATA-TYPE2 .
CLEAR GT_SU02[] .
SELECT
AFPO~KDAUF
AFPO~KDPOS
AFPO~PWERK
AFPO~AUFNR
AFPO~MATNR
AFPO~PSMNG
AFPO~MEINS
AFKO~AUFPL
AFVC~VORNR
INTO CORRESPONDING FIELDS OF TABLE GT_SU02[]
FROM AFPO
INNER JOIN AFKO ON AFPO~AUFNR = AFKO~AUFNR
INNER JOIN AFVC ON AFKO~AUFPL = AFVC~AUFPL
WHERE AFPO~PWERK = GT_DATA-PWERK
AND AFPO~AUFNR = GT_DATA-AUFNR
AND AFPO~MATNR = GT_DATA-MATNR
.
SORT GT_SU02[] BY PWERK AUFNR MATNR VORNR .
DELETE ADJACENT DUPLICATES FROM GT_SU02[] COMPARING PWERK AUFNR MATNR VORNR.
LOOP AT GT_SU02.
*实际人工工时 & 实际机器工时 & 实际准备工时
CLEAR GT_AFRU1[] .
SELECT
AFRU~AUFNR
AFRU~BUDAT
AFRU~RUECK
AFRU~RMZHL
AFRU~AUFPL
AFRU~APLZL
AFRU~ISM01
AFRU~ILE01
AFRU~ISM02
AFRU~ILE02
AFRU~ISM03
AFRU~ILE03
AFRU~STOKZ
AFRU~GMNGA
INTO CORRESPONDING FIELDS OF TABLE GT_AFRU1[]
FROM AFRU
WHERE AFRU~AUFNR = GT_SU02-AUFNR
AND AFRU~AUFPL = GT_SU02-AUFPL
AND AFRU~VORNR = GT_SU02-VORNR
.
*标准人工工时 & 标准机器工时 & 标准准备工时
CLEAR GT_AFVV[] .
SELECT
AFVV~AUFPL
AFVV~APLZL
AFVV~VGE01
AFVV~VGW01
AFVV~VGE02
AFVV~VGW02
AFVV~VGE03
AFVV~VGW03
AFVV~BMSCH
INTO CORRESPONDING FIELDS OF TABLE GT_AFVV[]
FROM AFVV
WHERE AFVV~AUFPL = GT_SU02-AUFPL
.
LOOP AT GT_AFRU1 .
IF GT_AFRU1-STOKZ IS NOT INITIAL.
GT_AFRU1-GMNGA = GT_AFRU1-GMNGA * -1 .
GT_AFRU1-ISM01 = GT_AFRU1-ISM01 * -1 .
GT_AFRU1-ISM02 = GT_AFRU1-ISM02 * -1 .
GT_AFRU1-ISM03 = GT_AFRU1-ISM03 * -1 .
ENDIF.
GT_SU02-GMNGA = GT_SU02-GMNGA + GT_AFRU1-GMNGA .
IF GT_AFRU1-ILE01 = 'S'.
GT_AFRU1-ISM01 = GT_AFRU1-ISM01 / 3600 .
ELSEIF GT_AFRU1-ILE01 = 'MIN'.
GT_AFRU1-ISM01 = GT_AFRU1-ISM01 / 60 .
ENDIF.
IF GT_AFRU1-ILE02 = 'S'.
GT_AFRU1-ISM02 = GT_AFRU1-ISM02 / 3600 .
ELSEIF GT_AFRU1-ILE02 = 'MIN'.
GT_AFRU1-ISM02 = GT_AFRU1-ISM02 / 60 .
ENDIF.
IF GT_AFRU1-ILE03 = 'S'.
GT_AFRU1-ISM03 = GT_AFRU1-ISM03 / 3600 .
ELSEIF GT_AFRU1-ILE03 = 'MIN'.
GT_AFRU1-ISM03 = GT_AFRU1-ISM03 / 60 .
ENDIF.
GT_SU02-ISM01 = GT_SU02-ISM01 + GT_AFRU1-ISM01 .
GT_SU02-ISM02 = GT_SU02-ISM02 + GT_AFRU1-ISM02 .
GT_SU02-ISM03 = GT_SU02-ISM03 + GT_AFRU1-ISM03 .
CLEAR GT_AFVV.
READ TABLE GT_AFVV WITH KEY AUFPL = GT_AFRU1-AUFPL APLZL = GT_AFRU1-APLZL .
IF GT_AFVV-BMSCH <> 0.
GT_AFVV-VGW01 = GT_AFVV-VGW01 .
GT_AFVV-VGW02 = GT_AFVV-VGW02 * GT_AFRU1-GMNGA / GT_AFVV-BMSCH .
GT_AFVV-VGW03 = GT_AFVV-VGW03 * GT_AFRU1-GMNGA / GT_AFVV-BMSCH .
ENDIF.
IF GT_AFVV-VGE01 = 'S'.
GT_AFVV-VGW01 = GT_AFVV-VGW01 / 3600 .
ELSEIF GT_AFVV-VGE01 = 'MIN'.
GT_AFVV-VGW01 = GT_AFVV-VGW01 / 60 .
ENDIF.
IF GT_AFVV-VGE02 = 'S'.
GT_AFVV-VGW02 = GT_AFVV-VGW02 / 3600 .
ELSEIF GT_AFVV-VGE02 = 'MIN'.
GT_AFVV-VGW02 = GT_AFVV-VGW02 / 60 .
ENDIF.
IF GT_AFVV-VGE03 = 'S'.
GT_AFVV-VGW03 = GT_AFVV-VGW03 / 3600 .
ELSEIF GT_AFVV-VGE03 = 'MIN'.
GT_AFVV-VGW03 = GT_AFVV-VGW03 / 60 .
ENDIF.
GT_SU02-VGW01 = GT_SU02-VGW01 + GT_AFVV-VGW01 .
GT_SU02-VGW02 = GT_SU02-VGW02 + GT_AFVV-VGW02 .
GT_SU02-VGW03 = GT_SU02-VGW03 + GT_AFVV-VGW03 .
CLEAR GT_AFRU1 .
ENDLOOP.
* 差异准备工时
GT_SU02-ZXYZB = GT_SU02-ISM01 - GT_SU02-VGW01 .
* 差异机器工时
GT_SU02-ZXYJQ = GT_SU02-ISM02 - GT_SU02-VGW02 .
* 差异人工工时
GT_SU02-ZXYRG = GT_SU02-ISM03 - GT_SU02-VGW03 .
MODIFY GT_SU02 .
CLEAR GT_SU02 .
ENDLOOP.
APPEND LINES OF GT_SU02[] TO GT_SUB02A[] .
CLEAR LS_STYLE .
IF GT_DATA-WEMNG > GT_DATA-GMNGA.
GT_DATA-CF2 = '@0A@'.
LS_STYLE-FIELDNAME = 'CF2'.
LS_STYLE-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_BUTTON.
APPEND LS_STYLE TO LT_STYLE.
GT_DATA-STYLE = LT_STYLE.
ELSE .
GT_DATA-CF2 = '@08@'.
ENDIF.
*------------------------------------------------------------------------------
* 报工异常警示
*------------------------------------------------------------------------------
MODIFY GT_DATA .
CLEAR GT_DATA .
ENDLOOP.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FILL_STATUS_TABLE
*&---------------------------------------------------------------------*
FORM FILL_STATUS_TABLE TABLES STATUS_TAB STRUCTURE STATUS_HDR_TAB
USING SYST1 LIKE TJ02T-TXT04
SYSH1 LIKE JEST-STAT
EXCL1 LIKE RCOSA-EXCL1
SYST2 LIKE TJ02T-TXT04
SYSH2 LIKE JEST-STAT
EXCL2 LIKE RCOSA-EXCL1.
DATA STATUS_TMP LIKE STATUS_HDR_TAB.
* Append status from selection screen to imported status table
IF NOT SYSH1 IS INITIAL.
STATUS_TMP-STAT = SYSH1.
STATUS_TMP-EXCL = EXCL1.
COLLECT STATUS_TMP INTO STATUS_TAB.
ELSEIF NOT SYST1 IS INITIAL.
CALL FUNCTION 'STATUS_TEXT_CONVERSION'
EXPORTING
LANGUAGE = SY-LANGU
TXT04 = SYST1
IMPORTING
STATUS_NUMBER = STATUS_TMP-STAT
EXCEPTIONS
INSUFFICIENT_INPUT = 1
NOT_FOUND = 2
OBJECT_NOT_FOUND = 3
WRONG_MODE = 4
OTHERS = 5.
IF SY-SUBRC EQ 0.
STATUS_TMP-EXCL = EXCL1.
COLLECT STATUS_TMP INTO STATUS_TAB.
ENDIF.
ENDIF.
IF NOT SYSH2 IS INITIAL.
STATUS_TMP-STAT = SYSH2.
STATUS_TMP-EXCL = EXCL2.
COLLECT STATUS_TMP INTO STATUS_TAB.
ELSEIF NOT SYST2 IS INITIAL.
CALL FUNCTION 'STATUS_TEXT_CONVERSION'
EXPORTING
LANGUAGE = SY-LANGU
TXT04 = SYST2
IMPORTING
STATUS_NUMBER = STATUS_TMP-STAT
EXCEPTIONS
INSUFFICIENT_INPUT = 1
NOT_FOUND = 2
OBJECT_NOT_FOUND = 3
WRONG_MODE = 4
OTHERS = 5.
IF SY-SUBRC EQ 0.
STATUS_TMP-EXCL = EXCL2.
COLLECT STATUS_TMP INTO STATUS_TAB.
ENDIF.
ENDIF.
ENDFORM. " FILL_STATUS_TABLE
*&---------------------------------------------------------------------*
*& Form REDUCE_AUFNR_OBJNR_BY_STATUS
*&---------------------------------------------------------------------*
FORM REDUCE_AUFNR_OBJNR_BY_STATUS
TABLES STATUS_TAB STRUCTURE STATUS_HDR_TAB
USING SELID LIKE P_SELID
CHANGING CTS_OBJNR TYPE TYP_TS_OBJNR.
* Statusobjekte
DATA:
OBJNR_TAB LIKE JSTO_PRE OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS:
<LS_OBJNR> TYPE TYP_S_OBJNR.
CHECK NOT SELID IS INITIAL
OR NOT STATUS_TAB[] IS INITIAL.
* preread
LOOP AT CTS_OBJNR[] ASSIGNING <LS_OBJNR>.
OBJNR_TAB-OBJNR = <LS_OBJNR>-OBJNR.
APPEND OBJNR_TAB.
ENDLOOP.
CALL FUNCTION 'STATUS_PRE_READ'
TABLES
JSTO_PRE_TAB = OBJNR_TAB.
DATA OBJECTS_DELETED.
PERFORM REDUCE_OBJNR_BY_STATUS
TABLES OBJNR_TAB
STATUS_TAB
USING SELID
CHANGING OBJECTS_DELETED.
IF OBJECTS_DELETED = YX.
* Alle Aufträge entfernen, deren OBJNR nicht mehr in der Tabelle
* OBJNR_TAB enthalten ist.
IF OBJNR_TAB[] IS INITIAL.
REFRESH CTS_OBJNR[].
ELSE.
SORT OBJNR_TAB BY OBJNR.
LOOP AT CTS_OBJNR[] ASSIGNING <LS_OBJNR>.
READ TABLE OBJNR_TAB
WITH KEY OBJNR = <LS_OBJNR>-OBJNR
BINARY SEARCH.
IF SY-SUBRC <> 0.
DELETE CTS_OBJNR[].
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
ENDFORM. " REDUCE_AUFNR_OBJNR_BY_STATUS
*&---------------------------------------------------------------------*
*& Form REDUCE_OBJNR_BY_STATUS
*&---------------------------------------------------------------------*
FORM REDUCE_OBJNR_BY_STATUS
TABLES OBJNR_TAB STRUCTURE OBJNR_TAB
STATUS_TAB STRUCTURE STATUS_HDR_TAB
USING SELID LIKE P_SELID
CHANGING OBJECTS_DELETED.
DATA OBJNR_CNT LIKE SY-DBCNT.
CLEAR OBJECTS_DELETED.
CHECK NOT OBJNR_TAB[] IS INITIAL.
DESCRIBE TABLE OBJNR_TAB LINES OBJNR_CNT.
* Statusprüfung gegen Status in Statustabelle
LOOP AT STATUS_TAB.
IF OBJNR_TAB[] IS INITIAL.
EXIT.
ELSE.
* Alle Objektnummern, bei denen der geforderte Status (nicht) sitzt,
* werden aus der Tabelle OBJNR_TAB gelöscht.
CALL FUNCTION 'STATUS_CHECK_MULTI'
EXPORTING
STATUS = STATUS_TAB-STAT
FLG_EXCLUDE = STATUS_TAB-EXCL
TABLES
OBJECTS = OBJNR_TAB.
ENDIF.
ENDLOOP.
* Statusprüfung gegen das Selektionsschema
IF NOT SELID IS INITIAL.
LOOP AT OBJNR_TAB.
DATA FLG_STATUS_OK TYPE C. "Statusprüfung OK
CALL FUNCTION 'STATUS_CHECK_BY_SELSCHEM'
EXPORTING
OBJNR = OBJNR_TAB-OBJNR
SELID = SELID
IMPORTING
FULLFILL = FLG_STATUS_OK
EXCEPTIONS
NO_STAT_SCHEME = 01
NO_STAT_TAB = 02.
IF SY-SUBRC IS INITIAL
AND FLG_STATUS_OK IS INITIAL.
DELETE OBJNR_TAB.
ENDIF.
ENDLOOP.
ENDIF.
DESCRIBE TABLE OBJNR_TAB LINES SY-DBCNT.
IF SY-DBCNT <> OBJNR_CNT.
OBJECTS_DELETED = YX.
ENDIF.
ENDFORM. " REDUCE_OBJNR_BY_STATUS
*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_DISPLAY .
CLEAR S_LAYOUT.
S_LAYOUT-ZEBRA = 'X'.
S_LAYOUT-CWIDTH_OPT = 'X'.
S_LAYOUT-CTAB_FNAME = 'CELLCOLOR'. "单元格颜色内表字段
S_LAYOUT-STYLEFNAME = 'STYLE'. "内部表字段的字段名称
* s_layout-box_fieldname = 'BOX'.
PERFORM FRM_FILL_FIELD .
W_EVENTS-NAME = 'CALLER_EXIT'. "slis_ev_caller_exit_at_start事件
W_EVENTS-FORM = 'FM_BUTTON'.
APPEND W_EVENTS TO I_EVENTS .
CLEAR IS_VARIANT .
IS_VARIANT-REPORT = SY-REPID.
IS_VARIANT-HANDLE = '1'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_SAVE = 'A'
IS_VARIANT = IS_VARIANT
IS_LAYOUT_LVC = S_LAYOUT
IT_FIELDCAT_LVC = GT_FIELDCAT
I_CALLBACK_PROGRAM = SY-REPID
IT_EVENTS = I_EVENTS
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 fm_button
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->E_GRID text
*----------------------------------------------------------------------*
FORM FM_BUTTON USING E_GRID TYPE SLIS_DATA_CALLER_EXIT.
* DATA: l_ref_alv TYPE REF TO cl_gui_alv_grid.
* IF ref_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF_GRID.
* ENDIF.
** 设置回车事件
* CALL METHOD ref_grid->register_edit_event
* EXPORTING
* i_event_id = cl_gui_alv_grid=>mc_evt_enter
* EXCEPTIONS
* error = 1
* OTHERS = 2.
* 设置光标焦点移开被修改单元格后触发事件
CALL METHOD REF_GRID->REGISTER_EDIT_EVENT
EXPORTING
I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED
EXCEPTIONS
ERROR = 1
OTHERS = 2.
* CALL METHOD ref_grid->register_edit_event
* EXPORTING
* i_event_id = cl_gui_alv_grid=>mc_evt_modified
* EXCEPTIONS
* error = 1
* OTHERS = 2.
CREATE OBJECT EVENT_RECEIVER.
SET HANDLER EVENT_RECEIVER->HANDLE_DATA_CHANGED FOR REF_GRID.
SET HANDLER EVENT_RECEIVER->HANDLE_BUTTON_CLICK FOR REF_GRID.
ENDFORM. "fm_button
FORM FRM_FILL_FIELD .
DATA: WA_FIELDCAT TYPE LINE OF LVC_T_FCAT.
DEFINE FILL_FIELD.
WA_FIELDCAT-FIELDNAME = &1.
WA_FIELDCAT-COLTEXT = &2.
IF WA_FIELDCAT-FIELDNAME = 'CKBOX' .
WA_FIELDCAT-CHECKBOX = 'X'.
WA_FIELDCAT-EDIT = 'X'.
ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'PLNBEZ'
OR WA_FIELDCAT-FIELDNAME = 'MATNR'
OR WA_FIELDCAT-FIELDNAME = 'MATNR_S'
.
WA_FIELDCAT-REF_TABLE = 'MARA'.
WA_FIELDCAT-REF_FIELD = 'MATNR'.
ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'ARKTX' OR WA_FIELDCAT-FIELDNAME = 'WAKTX' .
WA_FIELDCAT-REF_TABLE = 'VBAP'.
WA_FIELDCAT-REF_FIELD = 'ARKTX'.
ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'AUFNR' .
WA_FIELDCAT-REF_TABLE = 'AUFK'.
WA_FIELDCAT-REF_FIELD = 'AUFNR'.
ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'BLDAT'
OR WA_FIELDCAT-FIELDNAME = 'BUDAT'
.
WA_FIELDCAT-REF_TABLE = 'MATDOC'.
WA_FIELDCAT-REF_FIELD = 'BLDAT'.
* WA_FIELDCAT-EDIT = 'X'.
ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'MAKTX'
OR WA_FIELDCAT-FIELDNAME = 'MAKTX_S'
.
WA_FIELDCAT-REF_TABLE = 'MAKT'.
WA_FIELDCAT-REF_FIELD = 'MAKTX'.
ENDIF .
IF WA_FIELDCAT-FIELDNAME = 'ZDATUM'.
WA_FIELDCAT-OUTPUTLEN = '15'.
ENDIF.
IF WA_FIELDCAT-FIELDNAME = 'CF1'
OR WA_FIELDCAT-FIELDNAME = 'CF2'.
WA_FIELDCAT-ICON = 'X'.
ENDIF.
APPEND WA_FIELDCAT TO GT_FIELDCAT.
CLEAR WA_FIELDCAT.
END-OF-DEFINITION.
FILL_FIELD :
'PWERK' '工厂',
'AUFNR' '工单号码',
'MATNR' '产品料号',
'MAKTX' '物料名称',
'DISPO' 'MRP控制员',
'FEVOR' '生产管理员',
'GSTRP' '基本开始日期',
'GLTRP' '基本完成日期',
'PSMNG' '计划数量',
'GMNGA' '报工数量',
'WEMNG' '收货数量',
'MEINS' '单位',
'LTRMI' '收货日期',
'STTXT' '工单状态',
'CF1' '发料异常警示',
'CF2' '报工异常警示',
'DATUM_JY' '建议月结日期',
'DATUM_SJ' '实际月结日期',
'ZBEZU' '原因分析'.
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.
DATA: NEXTNO TYPE CHAR10.
DATA: ZRSPOS TYPE ZTGDTL-ZRSPOS .
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 'ALL'.
ENDCASE.
CALL METHOD REF->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LV_STABLE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_REF_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_REF_ALV .
DATA LS_STBL TYPE LVC_S_STBL.
IF REF_GRID IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = REF_GRID.
ENDIF.
LS_STBL-ROW = ABAP_TRUE.
LS_STBL-COL = ABAP_TRUE.
* CALL METHOD ref_grid->check_changed_data.
CALL METHOD REF_GRID->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LS_STBL.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form val_req_status
*&---------------------------------------------------------------------*
* F4-Help to select system status by text, providing also code
*----------------------------------------------------------------------*
* -->I_DYNPF Name of dynpro field
* -->C_TXT04 Status short text
* -->C_STAT Status code
*----------------------------------------------------------------------*
FORM VAL_REQ_STATUS USING I_DYNPF
CHANGING C_TXT04 LIKE TJ02T-TXT04
C_STAT LIKE JEST-STAT.
TYPES: BEGIN OF TY_VALUE,
ISTAT TYPE J_ISTAT,
TXT04 TYPE J_TXT04,
TXT30 TYPE J_TXT30,
END OF TY_VALUE.
DATA: L_VALUE TYPE DYNFIELDVALUE,
L_REPID TYPE SY-REPID,
LS_DYNP TYPE DYNPREAD,
LS_TJ02 TYPE TJ02,
LS_VALUE TYPE TJ02T,
LS_RETURN TYPE DDSHRETVAL,
LT_DYNP TYPE STANDARD TABLE OF DYNPREAD,
LT_TJ02 TYPE STANDARD TABLE OF TJ02,
LT_VALUE TYPE STANDARD TABLE OF TJ02T,
LT_RETURN TYPE STANDARD TABLE OF DDSHRETVAL.
* personal value key
DATA: L_PVALKEY TYPE DDSHPVKEY.
* Get current value from screen
LS_DYNP-FIELDNAME = I_DYNPF.
APPEND LS_DYNP TO LT_DYNP.
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
DYNAME = SY-REPID
DYNUMB = SY-DYNNR
TABLES
DYNPFIELDS = LT_DYNP
EXCEPTIONS
OTHERS = 0.
READ TABLE LT_DYNP INTO LS_DYNP INDEX 1.
* Get all possible values
SELECT * FROM TJ02 INTO TABLE LT_TJ02
WHERE NODIS = SPACE.
IF LT_TJ02 IS NOT INITIAL.
SELECT * FROM TJ02T INTO TABLE LT_VALUE
FOR ALL ENTRIES IN LT_TJ02
WHERE ISTAT = LT_TJ02-ISTAT
AND SPRAS = SY-LANGU.
ENDIF.
IF LINES( LT_TJ02 ) <> LINES( LT_VALUE ).
* Not all status available in current language, try in german
* as in FORM value_state(saplcoss)
LOOP AT LT_TJ02 INTO LS_TJ02.
READ TABLE LT_VALUE INTO LS_VALUE WITH KEY ISTAT = LS_TJ02-ISTAT.
CHECK SY-SUBRC <> 0.
SELECT SINGLE * FROM TJ02T INTO LS_VALUE
WHERE ISTAT = LS_TJ02-ISTAT
AND SPRAS = 'D'.
IF SY-SUBRC = 0.
APPEND LS_VALUE TO LT_VALUE.
ENDIF.
ENDLOOP.
ENDIF.
SORT LT_VALUE BY ISTAT.
* Call own F4-help, not showing internal status number
L_VALUE = LS_DYNP-FIELDVALUE.
L_REPID = 'PPIO_ENTRY'.
* fill key for personal value list
L_PVALKEY = SY-UNAME.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
DDIC_STRUCTURE = 'TJ02T'
RETFIELD = 'TXT04'
PVALKEY = L_PVALKEY
VALUE = L_VALUE
VALUE_ORG = 'S'
CALLBACK_PROGRAM = L_REPID
CALLBACK_FORM = 'VAL_REQ_STATUS_CALLBACK'
TABLES
VALUE_TAB = LT_VALUE
RETURN_TAB = LT_RETURN.
* Get selectect value and internal status number
READ TABLE LT_RETURN INTO LS_RETURN WITH KEY FIELDNAME = 'ISTAT'.
IF SY-SUBRC = 0.
READ TABLE LT_VALUE WITH KEY ISTAT = LS_RETURN-FIELDVAL
INTO LS_VALUE.
CHECK SY-SUBRC = 0.
C_TXT04 = LS_VALUE-TXT04.
C_STAT = LS_VALUE-ISTAT.
ELSE.
CLEAR: C_TXT04, C_STAT.
ENDIF.
ENDFORM. "val_req_status
*----------------------------------------------------------------------*
* INCLUDE TABLECONTROL_FORMS *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form USER_OK_TC *
*&---------------------------------------------------------------------*
FORM USER_OK_TC USING P_TC_NAME TYPE DYNFNAM
P_TABLE_NAME
P_MARK_NAME
CHANGING P_OK LIKE SY-UCOMM.
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
DATA: L_OK TYPE SY-UCOMM,
L_OFFSET TYPE I.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*
*&SPWIZARD: Table control specific operations *
*&SPWIZARD: evaluate TC name and operations *
SEARCH P_OK FOR P_TC_NAME.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
L_OFFSET = STRLEN( P_TC_NAME ) + 1.
L_OK = P_OK+L_OFFSET.
*&SPWIZARD: execute general and TC specific operations *
CASE L_OK.
WHEN 'INSR'. "insert row
PERFORM FCODE_INSERT_ROW USING P_TC_NAME
P_TABLE_NAME.
CLEAR P_OK.
WHEN 'DELE'. "delete row
PERFORM FCODE_DELETE_ROW USING P_TC_NAME
P_TABLE_NAME
P_MARK_NAME.
CLEAR P_OK.
WHEN 'P--' OR "top of list
'P-' OR "previous page
'P+' OR "next page
'P++'. "bottom of list
PERFORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME
L_OK.
CLEAR P_OK.
* WHEN 'L--'. "total left
* PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME.
*
* WHEN 'L-'. "column left
* PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME.
*
* WHEN 'R+'. "column right
* PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME.
*
* WHEN 'R++'. "total right
* PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME.
*
WHEN 'MARK'. "mark all filled lines
PERFORM FCODE_TC_MARK_LINES USING P_TC_NAME
P_TABLE_NAME
P_MARK_NAME .
CLEAR P_OK.
WHEN 'DMRK'. "demark all filled lines
PERFORM FCODE_TC_DEMARK_LINES USING P_TC_NAME
P_TABLE_NAME
P_MARK_NAME .
CLEAR P_OK.
* WHEN 'SASCEND' OR
* 'SDESCEND'. "sort column
* PERFORM FCODE_SORT_TC USING P_TC_NAME
* l_ok.
ENDCASE.
ENDFORM. " USER_OK_TC
*&---------------------------------------------------------------------*
*& Form FCODE_INSERT_ROW *
*&---------------------------------------------------------------------*
FORM FCODE_INSERT_ROW
USING P_TC_NAME TYPE DYNFNAM
P_TABLE_NAME .
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
DATA L_LINES_NAME LIKE FELD-NAME.
DATA L_SELLINE LIKE SY-STEPL.
DATA L_LASTLINE TYPE I.
DATA L_LINE TYPE I.
DATA L_TABLE_NAME LIKE FELD-NAME.
FIELD-SYMBOLS <TC> TYPE CXTAB_CONTROL.
FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.
FIELD-SYMBOLS <LINES> TYPE I.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*
ASSIGN (P_TC_NAME) TO <TC>.
*&SPWIZARD: get the table, which belongs to the tc *
CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body
ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline
*&SPWIZARD: get looplines of TableControl *
CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_LINES_NAME.
ASSIGN (L_LINES_NAME) TO <LINES>.
*&SPWIZARD: get current line *
GET CURSOR LINE L_SELLINE.
IF SY-SUBRC <> 0. " append line to table
L_SELLINE = <TC>-LINES + 1.
*&SPWIZARD: set top line *
IF L_SELLINE > <LINES>.
<TC>-TOP_LINE = L_SELLINE - <LINES> + 1 .
ELSE.
<TC>-TOP_LINE = 1.
ENDIF.
ELSE. " insert line into table
L_SELLINE = <TC>-TOP_LINE + L_SELLINE - 1.
L_LASTLINE = <TC>-TOP_LINE + <LINES> - 1.
ENDIF.
*&SPWIZARD: set new cursor line *
L_LINE = L_SELLINE - <TC>-TOP_LINE + 1.
*&SPWIZARD: insert initial line *
INSERT INITIAL LINE INTO <TABLE> INDEX L_SELLINE.
<TC>-LINES = <TC>-LINES + 1.
*&SPWIZARD: set cursor *
SET CURSOR LINE L_LINE.
ENDFORM. " FCODE_INSERT_ROW
*&---------------------------------------------------------------------*
*& Form FCODE_DELETE_ROW *
*&---------------------------------------------------------------------*
FORM FCODE_DELETE_ROW
USING P_TC_NAME TYPE DYNFNAM
P_TABLE_NAME
P_MARK_NAME .
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
DATA L_TABLE_NAME LIKE FELD-NAME.
FIELD-SYMBOLS <TC> TYPE CXTAB_CONTROL.
FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.
FIELD-SYMBOLS <WA>.
FIELD-SYMBOLS <MARK_FIELD>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*
ASSIGN (P_TC_NAME) TO <TC>.
*&SPWIZARD: get the table, which belongs to the tc *
CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body
ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline
*&SPWIZARD: delete marked lines *
DESCRIBE TABLE <TABLE> LINES <TC>-LINES.
LOOP AT <TABLE> ASSIGNING <WA>.
*&SPWIZARD: access to the component 'FLAG' of the table header *
ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.
IF <MARK_FIELD> = 'X'.
DELETE <TABLE> INDEX SYST-TABIX.
IF SY-SUBRC = 0.
<TC>-LINES = <TC>-LINES - 1.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM. " FCODE_DELETE_ROW
*&---------------------------------------------------------------------*
*& Form COMPUTE_SCROLLING_IN_TC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TC_NAME name of tablecontrol
* -->P_OK ok code
*----------------------------------------------------------------------*
FORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME
P_OK.
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
DATA L_TC_NEW_TOP_LINE TYPE I.
DATA L_TC_NAME LIKE FELD-NAME.
DATA L_TC_LINES_NAME LIKE FELD-NAME.
DATA L_TC_FIELD_NAME LIKE FELD-NAME.
FIELD-SYMBOLS <TC> TYPE CXTAB_CONTROL.
FIELD-SYMBOLS <LINES> TYPE I.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*
ASSIGN (P_TC_NAME) TO <TC>.
*&SPWIZARD: get looplines of TableControl *
CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_TC_LINES_NAME.
ASSIGN (L_TC_LINES_NAME) TO <LINES>.
*&SPWIZARD: is no line filled? *
IF <TC>-LINES = 0.
*&SPWIZARD: yes, ... *
L_TC_NEW_TOP_LINE = 1.
ELSE.
*&SPWIZARD: no, ... *
CALL FUNCTION 'SCROLLING_IN_TABLE'
EXPORTING
ENTRY_ACT = <TC>-TOP_LINE
ENTRY_FROM = 1
ENTRY_TO = <TC>-LINES
LAST_PAGE_FULL = 'X'
LOOPS = <LINES>
OK_CODE = P_OK
OVERLAPPING = 'X'
IMPORTING
ENTRY_NEW = L_TC_NEW_TOP_LINE
EXCEPTIONS
* NO_ENTRY_OR_PAGE_ACT = 01
* NO_ENTRY_TO = 02
* NO_OK_CODE_OR_PAGE_GO = 03
OTHERS = 0.
ENDIF.
*&SPWIZARD: get actual tc and column *
GET CURSOR FIELD L_TC_FIELD_NAME
AREA L_TC_NAME.
IF SYST-SUBRC = 0.
IF L_TC_NAME = P_TC_NAME.
*&SPWIZARD: et actual column *
SET CURSOR FIELD L_TC_FIELD_NAME LINE 1.
ENDIF.
ENDIF.
*&SPWIZARD: set the new top line *
<TC>-TOP_LINE = L_TC_NEW_TOP_LINE.
ENDFORM. " COMPUTE_SCROLLING_IN_TC
*&---------------------------------------------------------------------*
*& Form FCODE_TC_MARK_LINES
*&---------------------------------------------------------------------*
* marks all TableControl lines
*----------------------------------------------------------------------*
* -->P_TC_NAME name of tablecontrol
*----------------------------------------------------------------------*
FORM FCODE_TC_MARK_LINES USING P_TC_NAME
P_TABLE_NAME
P_MARK_NAME.
*&SPWIZARD: EGIN OF LOCAL DATA-----------------------------------------*
DATA L_TABLE_NAME LIKE FELD-NAME.
FIELD-SYMBOLS <TC> TYPE CXTAB_CONTROL.
FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.
FIELD-SYMBOLS <WA>.
FIELD-SYMBOLS <MARK_FIELD>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*
ASSIGN (P_TC_NAME) TO <TC>.
*&SPWIZARD: get the table, which belongs to the tc *
CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body
ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline
*&SPWIZARD: mark all filled lines *
LOOP AT <TABLE> ASSIGNING <WA>.
*&SPWIZARD: access to the component 'FLAG' of the table header *
ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.
<MARK_FIELD> = 'X'.
ENDLOOP.
ENDFORM. "fcode_tc_mark_lines
*&---------------------------------------------------------------------*
*& Form FCODE_TC_DEMARK_LINES
*&---------------------------------------------------------------------*
* demarks all TableControl lines
*----------------------------------------------------------------------*
* -->P_TC_NAME name of tablecontrol
*----------------------------------------------------------------------*
FORM FCODE_TC_DEMARK_LINES USING P_TC_NAME
P_TABLE_NAME
P_MARK_NAME .
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
DATA L_TABLE_NAME LIKE FELD-NAME.
FIELD-SYMBOLS <TC> TYPE CXTAB_CONTROL.
FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.
FIELD-SYMBOLS <WA>.
FIELD-SYMBOLS <MARK_FIELD>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*
ASSIGN (P_TC_NAME) TO <TC>.
*&SPWIZARD: get the table, which belongs to the tc *
CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body
ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline
*&SPWIZARD: demark all filled lines *
LOOP AT <TABLE> ASSIGNING <WA>.
*&SPWIZARD: access to the component 'FLAG' of the table header *
ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.
<MARK_FIELD> = SPACE.
ENDLOOP.
ENDFORM. "fcode_tc_mark_lines
*&---------------------------------------------------------------------*
*& 包含 ZMMR118_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'PF_0100'.
SET TITLEBAR 'TITLE_0100' WITH G_TITLE_0200.
ENDMODULE.
*&SPWIZARD: OUTPUT MODULE FOR TC 'TBC_01'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR
MODULE TBC_01_CHANGE_TC_ATTR OUTPUT.
DESCRIBE TABLE GT_SUB01 LINES TBC_01-lines.
ENDMODULE.
*&SPWIZARD: OUTPUT MODULE FOR TC 'TBC_01'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: GET LINES OF TABLECONTROL
MODULE TBC_01_GET_LINES OUTPUT.
G_TBC_01_LINES = SY-LOOPC.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_0200 OUTPUT.
SET PF-STATUS 'PF_0100'.
SET TITLEBAR 'TITLE_0200' WITH G_TITLE_0200.
ENDMODULE.
*&SPWIZARD: OUTPUT MODULE FOR TC 'TBC_02'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR
MODULE TBC_02_CHANGE_TC_ATTR OUTPUT.
DESCRIBE TABLE GT_SUB02 LINES TBC_02-lines.
ENDMODULE.
*&SPWIZARD: OUTPUT MODULE FOR TC 'TBC_02'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: GET LINES OF TABLECONTROL
MODULE TBC_02_GET_LINES OUTPUT.
G_TBC_02_LINES = SY-LOOPC.
ENDMODULE.
*&---------------------------------------------------------------------*
*& 包含 ZMMR118_PAI
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module CANCEL INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE CANCEL INPUT.
LEAVE TO SCREEN 0 .
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
OK_SAVE = SY-UCOMM .
CLEAR SY-UCOMM .
CLEAR OK_CODE .
CASE OK_SAVE.
WHEN 'BACK' .
LEAVE TO SCREEN 0 .
WHEN OTHERS .
ENDCASE .
ENDMODULE.
*&SPWIZARD: INPUT MODULE FOR TC 'TBC_01'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: PROCESS USER COMMAND
MODULE TBC_01_USER_COMMAND INPUT.
OK_CODE = SY-UCOMM.
PERFORM USER_OK_TC USING 'TBC_01'
'GT_SUB01'
' '
CHANGING OK_CODE.
SY-UCOMM = OK_CODE.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0200 INPUT.
OK_SAVE = SY-UCOMM .
CLEAR SY-UCOMM .
CLEAR OK_CODE .
CASE OK_SAVE.
WHEN 'BACK' .
LEAVE TO SCREEN 0 .
WHEN OTHERS .
ENDCASE .
ENDMODULE.
*&SPWIZARD: INPUT MODULE FOR TC 'TBC_02'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: PROCESS USER COMMAND
MODULE TBC_02_USER_COMMAND INPUT.
OK_CODE = SY-UCOMM.
PERFORM USER_OK_TC USING 'TBC_02'
'GT_SUB02'
' '
CHANGING OK_CODE.
SY-UCOMM = OK_CODE.
ENDMODULE.
AT SELECTION-SCREEN.
PERFORM SCREEN_SETTING.
START-OF-SELECTION.
PERFORM FOM_GETDATA .
PERFORM FRM_DISPLAY.