*&---------------------------------------------------------------------* *& Report ZPPR002 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT zppr002 NO STANDARD PAGE HEADING MESSAGE-ID zpp. INCLUDE zppr002_top. SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001. SELECT-OPTIONS:s_werks FOR marc-werks NO-EXTENSION NO INTERVALS OBLIGATORY, s_dispo FOR marc-dispo, s_matkl FOR mara-matkl, s_matnr FOR marc-matnr, s_gstrp FOR afko-gstrp NO-EXTENSION OBLIGATORY. PARAMETERS:p_edatu TYPE vbep-edatu OBLIGATORY. SELECTION-SCREEN END OF BLOCK blk1. SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002. PARAMETERS:p_rb1 RADIOBUTTON GROUP r1 DEFAULT ‘X‘, p_rb2 RADIOBUTTON GROUP r1. SELECTION-SCREEN END OF BLOCK blk2. INITIALIZATION. PERFORM frm_initialization. START-OF-SELECTION. PERFORM frm_auth_check. PERFORM frm_get_data. PERFORM frm_process_data. PERFORM frm_display_alv. *&---------------------------------------------------------------------* *& Form FRM_INITIALIZATION *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_initialization . IF s_gstrp[] IS INITIAL. s_gstrp-sign = ‘I‘. s_gstrp-option = ‘EQ‘. s_gstrp-low = sy-datum + 1. APPEND s_gstrp. ENDIF. IF p_edatu IS INITIAL. p_edatu = sy-datum + 1. ENDIF. * IF s_werks IS INITIAL. * s_werks-sign = ‘I‘. * s_werks-option = ‘EQ‘. * s_werks-low = ‘2001‘. * APPEND s_werks. * ENDIF. ENDFORM. " FRM_INITIALIZATION *&---------------------------------------------------------------------* *& Form FRM_GET_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_get_data . DATA:l_datum TYPE sy-datum. DATA:lt_rxsjh TYPE TABLE OF ztsd_rxsjh, lw_rxsjh TYPE ztsd_rxsjh. "查询出“MRP控制者”(MARC-DISPO)为P01、P02、P03或P08,或“物料组”(MARC-MATKL)为5010110的所有物料 SELECT marc~matnr marc~werks marc~disgr marc~eisbe marc~frtme marc~dispo mara~meins mara~matkl t438m~auart INTO CORRESPONDING FIELDS OF TABLE gt_matnr FROM marc INNER JOIN mara ON mara~matnr EQ marc~matnr LEFT JOIN t438m ON t438m~werks = marc~werks AND t438m~mtart = marc~disgr WHERE marc~werks IN s_werks AND marc~matnr IN s_matnr AND ( marc~dispo IN (‘P01‘,‘P02‘,‘P03‘,‘P08‘) OR mara~matkl EQ ‘5010110‘ ). IF s_matkl[] IS NOT INITIAL. DELETE gt_matnr WHERE matkl NOT IN s_matkl. ENDIF. IF s_dispo[] IS NOT INITIAL. DELETE gt_matnr WHERE dispo NOT IN s_dispo. ENDIF. * SELECT marc~matnr marc~werks marc~disgr marc~eisbe marc~frtme mara~meins t438m~auart * APPENDING CORRESPONDING FIELDS OF TABLE gt_matnr * FROM marc * INNER JOIN mara * ON mara~matnr = marc~matnr * LEFT JOIN t438m * ON t438m~werks = marc~werks * AND t438m~mtart = marc~disgr * WHERE marc~werks IN s_werks * AND marc~matnr IN s_matnr * AND mara~matkl EQ ‘5010110‘. * SELECT marc~matnr marc~werks marc~disgr marc~eisbe marc~frtme mara~meins t438m~auart * APPENDING CORRESPONDING FIELDS OF TABLE gt_matnr * FROM marc * INNER JOIN mara * ON mara~matnr = marc~matnr * LEFT JOIN t438m * ON t438m~werks = marc~werks * AND t438m~mtart = marc~disgr * WHERE marc~werks IN s_werks * AND marc~matnr IN s_matnr * AND marc~dispo IN s_dispo * AND mara~matkl IN s_matkl. IF gt_matnr IS INITIAL. MESSAGE s000 WITH ‘没有符合条件的数据‘ DISPLAY LIKE ‘E‘. STOP. ELSE. LOOP AT gt_matnr INTO gw_matnr WHERE frtme IS INITIAL. gw_matnr-frtme = gw_matnr-meins. MODIFY gt_matnr FROM gw_matnr TRANSPORTING frtme. ENDLOOP. ENDIF. SORT gt_matnr BY matnr werks. DELETE ADJACENT DUPLICATES FROM gt_matnr COMPARING matnr werks. "物料描述 SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_makt FROM makt FOR ALL ENTRIES IN gt_matnr WHERE matnr = gt_matnr-matnr AND spras = sy-langu. "生产订单编号和数量 SELECT afpo~aufnr afpo~posnr afpo~dwerk afpo~matnr afpo~dauat afpo~psmng afko~gstrp INTO CORRESPONDING FIELDS OF TABLE gt_afpo FROM afpo INNER JOIN afko ON afko~aufnr EQ afpo~aufnr FOR ALL ENTRIES IN gt_matnr WHERE afpo~dwerk EQ gt_matnr-werks AND afpo~matnr EQ gt_matnr-matnr AND afpo~dauat EQ gt_matnr-auart AND afko~gstrp IN s_gstrp. "订单开始时间 IF gt_afpo IS NOT INITIAL. SELECT aufnr objnr INTO CORRESPONDING FIELDS OF TABLE gt_objnr FROM aufk FOR ALL ENTRIES IN gt_afpo WHERE aufnr = gt_afpo-aufnr . SORT gt_objnr BY aufnr . LOOP AT gt_afpo INTO gw_afpo. CLEAR:g_line,gw_objnr . READ TABLE gt_objnr INTO gw_objnr WITH KEY aufnr = gw_afpo-aufnr BINARY SEARCH . IF sy-subrc = 0. "状态读取 CALL FUNCTION ‘STATUS_TEXT_EDIT‘ EXPORTING objnr = gw_objnr-objnr spras = sy-langu IMPORTING line = g_line EXCEPTIONS object_not_found = 1 OTHERS = 2. FIND ‘DLFL‘ IN g_line . IF sy-subrc = 0. DELETE gt_afpo. ENDIF. ENDIF. ENDLOOP. ENDIF. "工艺路线版本和版本描述 SELECT mapl~matnr mapl~werks mapl~plnty mapl~plnnr mapl~plnal mapl~zaehl plko~ktext INTO CORRESPONDING FIELDS OF TABLE gt_gylx FROM mapl INNER JOIN plko ON plko~plnty = mapl~plnty AND plko~plnnr = mapl~plnnr AND plko~plnal = mapl~plnal AND plko~zaehl = mapl~zaehl WHERE mapl~plnty = ‘N‘ AND mapl~loekz = ‘‘. "未清提单 SELECT vbbe~werks vbbe~matnr vbbe~vbeln vbbe~posnr vbbe~etenr vbbe~omeng AS bmeng vbbe~meins AS vrkme INTO CORRESPONDING FIELDS OF TABLE gt_wqdd FROM vbbe FOR ALL ENTRIES IN gt_matnr WHERE vbbe~werks EQ gt_matnr-werks AND vbbe~matnr EQ gt_matnr-matnr AND vbbe~vbtyp IN (‘J‘,‘C‘) AND vbbe~mbdat LE p_edatu. * SELECT vbap~werks vbap~lgort vbap~matnr vbep~vbeln vbep~posnr vbep~etenr vbep~vrkme vbep~bmeng * INTO CORRESPONDING FIELDS OF TABLE gt_wqdd * FROM vbap * INNER JOIN vbuk * ON vbuk~vbeln = vbap~vbeln * INNER JOIN vbep * ON vbep~vbeln = vbap~vbeln * AND vbep~posnr = vbap~posnr * FOR ALL ENTRIES IN gt_matnr * WHERE vbap~werks EQ gt_matnr-werks * AND vbap~matnr EQ gt_matnr-matnr * AND vbuk~vbtyp = ‘C‘ * AND vbuk~lfstk = ‘A‘ * AND vbep~edatu LE p_edatu. "汇总未清提单数量 LOOP AT gt_wqdd INTO gw_wqdd. CLEAR gw_matnr. READ TABLE gt_matnr INTO gw_matnr WITH KEY matnr = gw_wqdd-matnr werks = gw_wqdd-werks BINARY SEARCH. CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘ EXPORTING i_matnr = gw_matnr-matnr i_in_me = gw_wqdd-vrkme i_out_me = gw_matnr-frtme i_menge = gw_wqdd-bmeng IMPORTING e_menge = gw_wqdd-bmeng EXCEPTIONS error_in_application = 1 error = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. CLEAR gw_wqddsl. MOVE-CORRESPONDING gw_wqdd TO gw_wqddsl. COLLECT gw_wqddsl INTO gt_wqddsl. ENDLOOP. "当前库存 SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_mard FROM mard INNER JOIN t001l ON t001l~werks = mard~werks AND t001l~lgort = mard~lgort FOR ALL ENTRIES IN gt_matnr WHERE mard~werks = gt_matnr-werks AND mard~matnr = gt_matnr-matnr AND t001l~diskz NE ‘1‘. "汇总当前库存数量 LOOP AT gt_mard INTO gw_mard. CLEAR gw_matnr. READ TABLE gt_matnr INTO gw_matnr WITH KEY matnr = gw_mard-matnr werks = gw_mard-werks BINARY SEARCH. CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘ EXPORTING i_matnr = gw_matnr-matnr i_in_me = gw_matnr-meins i_out_me = gw_matnr-frtme i_menge = gw_mard-labst IMPORTING e_menge = gw_mard-labst EXCEPTIONS error_in_application = 1 error = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. CLEAR gw_dqkcsl. MOVE-CORRESPONDING gw_mard TO gw_dqkcsl. COLLECT gw_dqkcsl INTO gt_dqkcsl. ENDLOOP. * "在产订单 SELECT afpo~aufnr afpo~posnr afpo~dwerk afpo~matnr afpo~dauat afpo~psmng afko~gstrp INTO CORRESPONDING FIELDS OF TABLE gt_afpo_zc FROM afpo INNER JOIN afko ON afko~aufnr EQ afpo~aufnr FOR ALL ENTRIES IN gt_matnr WHERE afpo~dwerk EQ gt_matnr-werks AND afpo~matnr EQ gt_matnr-matnr AND afko~gstrp IN s_gstrp. "订单开始时间 "汇总在产数量 LOOP AT gt_afpo_zc INTO gw_afpo. CLEAR gw_zcsl. MOVE-CORRESPONDING gw_afpo TO gw_zcsl. gw_zcsl-werks = gw_afpo-dwerk. * SELECT SINGLE gstrp INTO gw_zcsl-gstrp * FROM afko * WHERE aufnr = gw_afpo-aufnr. gw_zcsl-zcsl = gw_zcsl-psmng - gw_zcsl-wemng. COLLECT gw_zcsl INTO gt_zcsl. ENDLOOP. SORT gt_zcsl BY werks matnr gstrp. "前1-7天出货量 DATA:l_date_low TYPE sy-datum, l_date_high TYPE sy-datum. l_date_low = sy-datum - 7. l_date_high = sy-datum." - 1. "加当天出货数量 SELECT lips~vbeln lips~posnr lips~werks lips~matnr lips~lfimg lips~vrkme likp~wadat_ist AS lfdat INTO CORRESPONDING FIELDS OF TABLE gt_lips FROM lips INNER JOIN likp ON likp~vbeln = lips~vbeln INNER JOIN vbuk ON vbuk~vbeln = lips~vbeln FOR ALL ENTRIES IN gt_matnr WHERE lips~werks = gt_matnr-werks AND lips~matnr = gt_matnr-matnr AND likp~lfart = ‘ZLF1‘ AND likp~wadat_ist BETWEEN l_date_low AND l_date_high "WADAT_IST lfdat AND vbuk~wbstk = ‘C‘. "汇总出货量 LOOP AT gt_lips INTO gw_lips. gw_chl-werks = gw_lips-werks. gw_chl-matnr = gw_lips-matnr. CLEAR gw_matnr. READ TABLE gt_matnr INTO gw_matnr WITH KEY matnr = gw_lips-matnr werks = gw_lips-werks BINARY SEARCH. CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘ EXPORTING i_matnr = gw_lips-matnr i_in_me = gw_lips-vrkme i_out_me = gw_matnr-frtme i_menge = gw_lips-lfimg IMPORTING e_menge = gw_lips-lfimg EXCEPTIONS error_in_application = 1 error = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. CLEAR g_ts. CALL FUNCTION ‘FIMA_DAYS_AND_MONTHS_AND_YEARS‘ EXPORTING i_date_from = gw_lips-lfdat i_date_to = sy-datum IMPORTING e_days = g_ts. CASE g_ts. WHEN ‘0‘. gw_chl-zq0tchl = gw_lips-lfimg. WHEN ‘1‘. gw_chl-zq1tchl = gw_lips-lfimg. WHEN ‘2‘. gw_chl-zq2tchl = gw_lips-lfimg. WHEN ‘3‘. gw_chl-zq3tchl = gw_lips-lfimg. WHEN ‘4‘. gw_chl-zq4tchl = gw_lips-lfimg. WHEN ‘5‘. gw_chl-zq5tchl = gw_lips-lfimg. WHEN ‘6‘. gw_chl-zq6tchl = gw_lips-lfimg. WHEN ‘7‘. gw_chl-zq7tchl = gw_lips-lfimg. WHEN OTHERS. ENDCASE. COLLECT gw_chl INTO gt_chl. CLEAR gw_chl. ENDLOOP. "日提货计划 CLEAR l_datum. l_datum = sy-datum + 1. SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_rxsjh FROM ztsd_rxsjh FOR ALL ENTRIES IN gt_matnr WHERE zwerks = gt_matnr-werks AND zjhqj = l_datum AND zmatnr = gt_matnr-matnr. SORT lt_rxsjh BY zwerks zvkorg zjhqj zmatnr zbanbe DESCENDING. DELETE ADJACENT DUPLICATES FROM lt_rxsjh COMPARING zwerks zvkorg zjhqj zmatnr. "汇总日销售计划量 CLEAR:gw_rxsjh,gt_rxsjh. LOOP AT lt_rxsjh INTO lw_rxsjh. gw_rxsjh-zwerks = lw_rxsjh-zwerks. gw_rxsjh-zjhqj = lw_rxsjh-zjhqj. gw_rxsjh-zmatnr = lw_rxsjh-zmatnr. CLEAR gw_matnr. READ TABLE gt_matnr INTO gw_matnr WITH KEY matnr = gw_rxsjh-zmatnr werks = gw_rxsjh-zwerks BINARY SEARCH. CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘ EXPORTING i_matnr = gw_matnr-matnr i_in_me = lw_rxsjh-zmeins i_out_me = gw_matnr-frtme i_menge = lw_rxsjh-zxjhsl1 IMPORTING e_menge = gw_rxsjh-zxjhsl1 EXCEPTIONS error_in_application = 1 error = 2 OTHERS = 3. CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘ EXPORTING i_matnr = gw_matnr-matnr i_in_me = lw_rxsjh-zmeins i_out_me = gw_matnr-frtme i_menge = lw_rxsjh-zxjhsl2 IMPORTING e_menge = gw_rxsjh-zxjhsl2 EXCEPTIONS error_in_application = 1 error = 2 OTHERS = 3. CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘ EXPORTING i_matnr = gw_matnr-matnr i_in_me = lw_rxsjh-zmeins i_out_me = gw_matnr-frtme i_menge = lw_rxsjh-zxjhsl3 IMPORTING e_menge = gw_rxsjh-zxjhsl3 EXCEPTIONS error_in_application = 1 error = 2 OTHERS = 3. "MODIFY gt_rxsjh FROM gw_rxsjh TRANSPORTING zxjhsl1 zxjhsl2 zxjhsl3. COLLECT gw_rxsjh INTO gt_rxsjh. ENDLOOP. ENDFORM. " FRM_GET_DATA *&---------------------------------------------------------------------* *& Form FRM_PROCESS_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_process_data . DATA:l_begin_d TYPE sy-datum, l_end_d TYPE sy-datum. DATA:l_times TYPE i, l_sqr TYPE i. IF s_gstrp-high IS INITIAL. l_end_d = s_gstrp-low. ELSE. l_end_d = s_gstrp-high. ENDIF. SORT gt_afpo BY matnr dwerk gstrp aufnr. SORT gt_makt BY matnr. SORT gt_gylx BY matnr werks. SORT gt_wqddsl BY matnr werks. SORT gt_dqkcsl BY matnr werks. SORT gt_zcsl BY matnr werks gstrp. SORT gt_chl BY matnr werks. SORT gt_rxsjh BY zmatnr zwerks."zvkorg. LOOP AT gt_matnr INTO gw_matnr. l_begin_d = s_gstrp-low. CLEAR l_times. DO. l_times = l_times + 1. IF l_begin_d GT l_end_d. EXIT. ENDIF. gw_output-gstrp = l_begin_d. gw_output-werks = gw_matnr-werks. gw_output-matnr = gw_matnr-matnr. gw_output-auart = gw_matnr-auart. gw_output-eisbe = gw_matnr-eisbe. "安全库存 CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘ EXPORTING i_matnr = gw_matnr-matnr i_in_me = gw_matnr-meins i_out_me = gw_matnr-frtme i_menge = gw_output-eisbe IMPORTING e_menge = gw_output-eisbe EXCEPTIONS error_in_application = 1 error = 2 OTHERS = 3. gw_output-frtme = gw_matnr-frtme. "生产单位 READ TABLE gt_makt INTO gw_makt WITH KEY matnr = gw_matnr-matnr BINARY SEARCH. IF sy-subrc = 0. gw_output-maktx = gw_makt-maktx. ENDIF. "生产订单号和生产订单数量 CLEAR gw_afpo. READ TABLE gt_afpo INTO gw_afpo WITH KEY matnr = gw_matnr-matnr dwerk = gw_matnr-werks gstrp = l_begin_d BINARY SEARCH. IF sy-subrc = 0. gw_output-aufnr = gw_afpo-aufnr. gw_output-psmng = gw_afpo-psmng. CLEAR:g_fname,gw_tline,gt_tline. CONCATENATE sy-mandt gw_output-aufnr INTO g_fname. CALL FUNCTION ‘READ_TEXT‘ EXPORTING id = ‘KOPF‘ language = sy-langu name = g_fname object = ‘AUFK‘ TABLES lines = gt_tline EXCEPTIONS id = 1 language = 2 name = 3 not_found = 4 object = 5 reference_check = 6 wrong_access_to_archive = 7 OTHERS = 8. "原料来源 READ TABLE gt_tline INTO gw_tline INDEX 1. IF sy-subrc = 0. gw_output-zylly = gw_tline-tdline. ENDIF. ENDIF. "工艺路线版本&工艺路线版本描述 READ TABLE gt_gylx INTO gw_gylx WITH KEY matnr = gw_matnr-matnr werks = gw_matnr-werks BINARY SEARCH. IF sy-subrc = 0. gw_output-plnnr = gw_gylx-plnnr. gw_output-plnal = gw_gylx-plnal. gw_output-ktext = gw_gylx-ktext. ENDIF. "未清提单数量 READ TABLE gt_wqddsl INTO gw_wqddsl WITH KEY matnr = gw_matnr-matnr werks = gw_matnr-werks BINARY SEARCH. IF sy-subrc = 0. gw_output-zwqddsl = gw_wqddsl-bmeng. ENDIF. "当前库存 READ TABLE gt_dqkcsl INTO gw_dqkcsl WITH KEY matnr = gw_matnr-matnr werks = gw_matnr-werks BINARY SEARCH. IF sy-subrc = 0. gw_output-zdqkc = gw_dqkcsl-labst. ENDIF. "在产数量 READ TABLE gt_zcsl INTO gw_zcsl WITH KEY matnr = gw_matnr-matnr werks = gw_matnr-werks gstrp = l_begin_d BINARY SEARCH. IF sy-subrc = 0. gw_output-zzcsl = gw_zcsl-zcsl. ENDIF. "后X天销售计划量 CLEAR gw_rxsjh. READ TABLE gt_rxsjh INTO gw_rxsjh WITH KEY zmatnr = gw_matnr-matnr zwerks = gw_matnr-werks "zvkorg = gw_matnr-werks BINARY SEARCH. IF sy-subrc = 0. gw_output-zh1txsjhl = gw_rxsjh-zxjhsl1. gw_output-zh2txsjhl = gw_rxsjh-zxjhsl2. gw_output-zh3txsjhl = gw_rxsjh-zxjhsl3. ENDIF. IF l_times EQ 1. gw_output-zjyscsl = gw_output-zwqddsl + gw_output-zh1txsjhl - gw_output-zdqkc - gw_output-zzcsl + gw_output-eisbe. ELSE. gw_output-zjyscsl = gw_output-zh1txsjhl. ENDIF. IF gw_output-zjyscsl LT 0. gw_output-zjyscsl = 0. ENDIF. "出货数量 CLEAR gw_chl. READ TABLE gt_chl INTO gw_chl WITH KEY matnr = gw_matnr-matnr werks = gw_matnr-werks BINARY SEARCH. IF sy-subrc = 0. gw_output-zq0tchl = gw_chl-zq0tchl. gw_output-zq1tchl = gw_chl-zq1tchl. gw_output-zq2tchl = gw_chl-zq2tchl. gw_output-zq3tchl = gw_chl-zq3tchl. gw_output-zq4tchl = gw_chl-zq4tchl. gw_output-zq5tchl = gw_chl-zq5tchl. gw_output-zq6tchl = gw_chl-zq6tchl. gw_output-zq7tchl = gw_chl-zq7tchl. ENDIF. APPEND gw_output TO gt_output. CLEAR gw_output. l_sqr = l_sqr + 1. l_begin_d = l_begin_d + 1. ENDDO. ENDLOOP. IF p_rb1 EQ ‘X‘. DELETE gt_output WHERE zjyscsl EQ 0. ENDIF. l_sqr = 0. LOOP AT gt_output INTO gw_output. l_sqr = l_sqr + 1. gw_output-sqr = l_sqr. IF gw_output-aufnr IS NOT INITIAL. gw_style-style = cl_gui_alv_grid=>mc_style_disabled. " 设置为不可编辑状态 gw_style-fieldname = ‘AUART‘. " 需要编辑的列名 APPEND gw_style TO gw_output-style. gw_style-fieldname = ‘PLNAL‘. " 需要编辑的列名 APPEND gw_style TO gw_output-style. gw_style-fieldname = ‘PLNNR‘. " 需要编辑的列名 APPEND gw_style TO gw_output-style. gw_style-fieldname = ‘ZJYSCSL‘. " 需要编辑的列名 APPEND gw_style TO gw_output-style. gw_style-fieldname = ‘ZYLLY‘. " 需要编辑的列名 APPEND gw_style TO gw_output-style. ENDIF. MODIFY gt_output FROM gw_output TRANSPORTING sqr style. ENDLOOP. ENDFORM. " FRM_PROCESS_DATA *&---------------------------------------------------------------------* *& Form FRM_DISPLAY_ALV *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_display_alv . PERFORM frm_build_fieldcat. gw_layout-zebra = ‘X‘. gw_layout-cwidth_opt = ‘X‘. gw_layout-stylefname = ‘STYLE‘. gw_events-name = ‘CALLER_EXIT‘. "slis_ev_caller_exit_at_start事件 调用来获取ALV对象并注册回车事件 gw_events-form = ‘FRM_CALLER_EXIT‘. APPEND gw_events TO gt_events. CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘ EXPORTING i_callback_program = sy-repid i_callback_pf_status_set = ‘FRM_PF_STATUS_SET‘ i_callback_user_command = ‘FRM_USER_COMMAND‘ "i_grid_settings = gw_setting is_layout_lvc = gw_layout it_fieldcat_lvc = gt_fieldcat " it_sort_lvc = gt_sort it_events = gt_events i_default = ‘X‘ i_save = ‘A‘ TABLES t_outtab = gt_output EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ENDFORM. " FRM_DISPLAY_ALV *&---------------------------------------------------------------------* *& Form FRM_BUILD_FIELDCAT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_build_fieldcat . mcr_fieldcat:‘ZSEL‘ ‘选择‘ ‘X‘ ‘‘ ‘‘, ‘ICON‘ ‘状态‘ ‘‘ ‘ICON‘ ‘ID‘, ‘MSG‘ ‘消息‘ ‘‘ ‘‘ ‘‘, ‘AUFNR‘ ‘生产订单号‘ ‘‘ ‘AUFK‘ ‘AUFNR‘, ‘SQR‘ ‘序号‘ ‘‘ ‘‘ ‘‘, ‘GSTRP‘ ‘计划生产日期‘ ‘‘ ‘‘ ‘‘, ‘PSMNG‘ ‘生产订单数量‘ ‘‘ ‘‘ ‘‘, ‘WERKS‘ ‘工厂‘ ‘‘ ‘MARC‘ ‘WERKS‘, ‘MATNR‘ ‘物料编码‘ ‘‘ ‘MARC‘ ‘MATNR‘, ‘MAKTX‘ ‘物料描述‘ ‘‘ ‘‘ ‘‘, ‘AUART‘ ‘订单类型‘ ‘X‘ ‘T438M‘ ‘AUART‘, ‘PLNNR‘ ‘组‘ ‘X‘ ‘MAPL‘ ‘PLNNR‘, "工艺路线版本编码 ‘PLNAL‘ ‘组计算器‘ ‘X‘ ‘MAPL‘ ‘PLNAL‘, ‘KTEXT‘ ‘工艺路线版本描述‘ ‘‘ ‘‘ ‘‘, ‘ZWQDDSL‘ ‘未清提单数量‘ ‘‘ ‘‘ ‘‘, ‘ZH1TXSJHL‘ ‘后1天销售计划量‘ ‘‘ ‘‘ ‘‘, ‘ZH2TXSJHL‘ ‘后2天销售计划量‘ ‘‘ ‘‘ ‘‘, ‘ZH3TXSJHL‘ ‘后3天销售计划量‘ ‘‘ ‘‘ ‘‘, ‘ZDQKC‘ ‘当前库存‘ ‘‘ ‘‘ ‘‘, ‘ZZCSL‘ ‘在产数量‘ ‘‘ ‘‘ ‘‘, ‘EISBE‘ ‘安全库存‘ ‘‘ ‘‘ ‘‘, ‘ZJYSCSL‘ ‘建议生产数量‘ ‘X‘ ‘VBEP‘ ‘BMENG‘, ‘FRTME‘ ‘单位‘ ‘‘ ‘MARC‘ ‘FRTME‘, ‘ZYLLY‘ ‘原料来源‘ ‘X‘ ‘‘ ‘‘, ‘ZQ0TCHL‘ ‘当天出货数量‘ ‘‘ ‘‘ ‘‘, ‘ZQ1TCHL‘ ‘前1天出货数量‘ ‘‘ ‘‘ ‘‘, ‘ZQ2TCHL‘ ‘前2天出货数量‘ ‘‘ ‘‘ ‘‘, ‘ZQ3TCHL‘ ‘前3天出货数量‘ ‘‘ ‘‘ ‘‘, ‘ZQ4TCHL‘ ‘前4天出货数量‘ ‘‘ ‘‘ ‘‘, ‘ZQ5TCHL‘ ‘前5天出货数量‘ ‘‘ ‘‘ ‘‘, ‘ZQ6TCHL‘ ‘前6天出货数量‘ ‘‘ ‘‘ ‘‘, ‘ZQ7TCHL‘ ‘前7天出货数量‘ ‘‘ ‘‘ ‘‘. * ‘ZQ1TXSJHL‘ ‘前1天销售计划量‘ ‘‘ ‘‘ ‘‘, * ‘ZQ2TXSJHL‘ ‘前2天销售计划量‘ ‘‘ ‘‘ ‘‘, * ‘ZQ3TXSJHL‘ ‘前3天销售计划量‘ ‘‘ ‘‘ ‘‘, * ‘ZQ4TXSJHL‘ ‘前4天销售计划量‘ ‘‘ ‘‘ ‘‘, * ‘ZQ5TXSJHL‘ ‘前5天销售计划量‘ ‘‘ ‘‘ ‘‘, * ‘ZQ6TXSJHL‘ ‘前6天销售计划量‘ ‘‘ ‘‘ ‘‘, * ‘ZQ7TXSJHL‘ ‘前7天销售计划量‘ ‘‘ ‘‘ ‘‘. ENDFORM. " FRM_BUILD_FIELDCAT *&---------------------------------------------------------------------* *& Form FRM_AUTH_CHECK *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_auth_check . AUTHORITY-CHECK OBJECT ‘C_AFKO_AWA‘ ID ‘ACTVT‘ DUMMY ID ‘AUTYP‘ DUMMY ID ‘AUFART‘ DUMMY ID ‘WERKS‘ FIELD s_werks-low . IF sy-subrc <> 0. MESSAGE e000 WITH ‘没有工厂‘ s_werks-low ‘权限‘. ENDIF. ENDFORM. " FRM_AUTH_CHECK FORM frm_pf_status_set USING rt_extab TYPE slis_t_extab. SET PF-STATUS ‘STANDARD_FULLSCREEN‘. ENDFORM. FORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. CALL METHOD g_grid->check_changed_data. CLEAR:gt_message[]. CASE r_ucomm. WHEN ‘ALL‘. gw_output-zsel = ‘X‘. MODIFY gt_output FROM gw_output TRANSPORTING zsel WHERE zsel NE ‘X‘. WHEN ‘DALL‘. CLEAR gw_output-zsel. MODIFY gt_output FROM gw_output TRANSPORTING zsel WHERE zsel EQ ‘X‘. WHEN ‘CREATE‘. PERFORM frm_create_prodord. WHEN ‘SCBCAP‘. PERFORM frm_scbcap. WHEN ‘CHANGE‘. PERFORM frm_change_prodord. WHEN ‘KCXQQD‘. PERFORM frm_kcxqqd. WHEN ‘BACK‘ OR ‘EXIT‘ OR ‘CANC‘. LEAVE SCREEN. WHEN OTHERS. ENDCASE. " rs_selfield-refresh = ‘X‘. "刷新ALV * 稳定刷新 g_stbl-row = ‘X‘." 基于行的稳定刷新 g_stbl-col = ‘X‘." 基于列稳定刷新 CALL METHOD g_grid->refresh_table_display EXPORTING is_stable = g_stbl. IF gt_message[] IS NOT INITIAL. CALL FUNCTION ‘USMD_MESSAGE_POPUP‘ EXPORTING it_message = gt_message[] if_save_necessary = gv_necessary. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_CREATE_PRODORD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_create_prodord . DATA:lt_output LIKE TABLE OF gw_output. DATA:gs_keko TYPE keko. CALL METHOD g_grid->check_changed_data * IMPORTING * e_valid = * CHANGING * c_refresh = ‘X‘ . CLEAR:gw_order,gt_order,lt_output,gt_message[]. LOOP AT gt_output INTO gw_output WHERE aufnr IS INITIAL AND zjyscsl GT 0 AND zsel EQ ‘X‘. gw_orderdata-material = gw_output-matnr. gw_orderdata-plant = gw_output-werks. gw_orderdata-order_type = gw_output-auart. gw_orderdata-basic_start_date = gw_output-gstrp. gw_orderdata-basic_end_date = gw_output-gstrp. gw_orderdata-quantity = gw_output-zjyscsl. gw_orderdata-quantity_uom = gw_output-frtme. gw_orderdata-routing_type = ‘N‘. gw_orderdata-routing_group = gw_output-plnnr. gw_orderdata-routing_counter = gw_output-plnal. "add by ly 20151124 SELECT SINGLE * INTO CORRESPONDING FIELDS OF gs_keko FROM keko WHERE matnr = gw_output-matnr AND werks = gw_output-werks AND bwkey = gw_output-werks AND kadat LE sy-datum AND bidat GE sy-datum AND freig = ‘X‘. IF sy-subrc <> 0. gs_message-msgid = ‘ZPP‘. gs_message-msgty = ‘E‘. gs_message-msgno = ‘000‘. gs_message-msgv1 = ‘物料‘. gs_message-msgv2 = gw_output-matnr. gs_message-msgv3 = ‘未下达标准成本估算!‘. APPEND gs_message TO gt_message. CONTINUE. ENDIF. "add by ly 20151124 CLEAR:gw_return,g_aufnr. CALL FUNCTION ‘BAPI_PRODORD_CREATE‘ EXPORTING orderdata = gw_orderdata IMPORTING return = gw_return order_number = g_aufnr " ORDER_TYPE = . IF g_aufnr IS NOT INITIAL. * CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘ * EXPORTING * wait = ‘X‘. gw_output-aufnr = g_aufnr. gw_output-psmng = gw_output-zjyscsl. gw_output-icon = icon_led_green. gw_order-order_number = gw_output-aufnr. APPEND gw_order TO gt_order. APPEND gw_output TO lt_output. ELSE. * CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘. * * gw_output-icon = icon_led_red. ENDIF. gw_output-msg = gw_return-message. IF gw_output-aufnr IS NOT INITIAL. gw_style-style = cl_gui_alv_grid=>mc_style_disabled. " 设置为不可编辑状态 gw_style-fieldname = ‘AUART‘. " 需要编辑的列名 APPEND gw_style TO gw_output-style. gw_style-fieldname = ‘PLNAL‘. " 需要编辑的列名 APPEND gw_style TO gw_output-style. gw_style-fieldname = ‘PLNNR‘. " 需要编辑的列名 APPEND gw_style TO gw_output-style. gw_style-fieldname = ‘ZJYSCSL‘. " 需要编辑的列名 APPEND gw_style TO gw_output-style. gw_style-fieldname = ‘ZYLLY‘. " 需要编辑的列名 APPEND gw_style TO gw_output-style. ENDIF. MODIFY gt_output FROM gw_output. ENDLOOP. IF gt_order IS NOT INITIAL. WAIT UP TO 5 SECONDS. LOOP AT lt_output INTO gw_output. IF gw_output-zylly IS NOT INITIAL. CONCATENATE sy-mandt gw_output-aufnr INTO g_fname. CLEAR:gw_tline,gt_tline. gw_tline-tdline = gw_output-zylly. APPEND gw_tline TO gt_tline. CALL FUNCTION ‘CREATE_TEXT‘ EXPORTING fid = ‘KOPF‘ flanguage = sy-langu fname = g_fname fobject = ‘AUFK‘ TABLES flines = gt_tline EXCEPTIONS no_init = 1 no_save = 2 OTHERS = 3. IF sy-subrc = 0. UPDATE aufk SET ltext = 1 WHERE aufnr = gw_output-aufnr. ENDIF. ENDIF. ENDLOOP. CALL FUNCTION ‘BAPI_PRODORD_RELEASE‘ TABLES orders = gt_order. CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘ EXPORTING wait = ‘X‘. ENDIF. * IF gt_message[] IS NOT INITIAL. * CALL FUNCTION ‘USMD_MESSAGE_POPUP‘ * EXPORTING * it_message = gt_message[] * if_save_necessary = gv_necessary. * ENDIF. ENDFORM. " FRM_CREATE_PRODORD *&---------------------------------------------------------------------* *& Form FRM_CHANGE_PRODORD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_change_prodord . * CLEAR gt_row. * CALL METHOD g_grid->get_selected_rows * IMPORTING * et_index_rows = gt_row ** et_row_no = * . * READ TABLE gt_row INTO gw_row INDEX 1. * IF sy-subrc NE 0. * MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘. * RETURN. * ENDIF. * * READ TABLE gt_output INTO gw_output INDEX gw_row-index. READ TABLE gt_output INTO gw_output WITH KEY zsel = ‘X‘. IF sy-subrc NE 0. MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘. RETURN. ENDIF. IF gw_output-aufnr IS INITIAL. MESSAGE s000 WITH ‘生产订单为空,请先创建生产订单‘ DISPLAY LIKE ‘E‘. RETURN. ENDIF. SET PARAMETER ID ‘ANR‘ FIELD gw_output-aufnr. CALL TRANSACTION ‘CO02‘ AND SKIP FIRST SCREEN. ENDFORM. " FRM_CHANGE_PRODORD *&---------------------------------------------------------------------* *& Form FRM_KCXQQD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_kcxqqd . * CLEAR gt_row. * CALL METHOD g_grid->get_selected_rows * IMPORTING * et_index_rows = gt_row ** et_row_no = * . * READ TABLE gt_row INTO gw_row INDEX 1. * IF sy-subrc NE 0. * MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘. * RETURN. * ENDIF. * * READ TABLE gt_output INTO gw_output INDEX gw_row-index. READ TABLE gt_output INTO gw_output WITH KEY zsel = ‘X‘. IF sy-subrc NE 0. MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘. RETURN. ENDIF. SET PARAMETER ID ‘MAT‘ FIELD gw_output-matnr. SET PARAMETER ID ‘WRK‘ FIELD gw_output-werks. CALL TRANSACTION ‘MD04‘ AND SKIP FIRST SCREEN. ENDFORM. " FRM_KCXQQD FORM frm_caller_exit USING e_grid TYPE slis_data_caller_exit. CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR‘ IMPORTING e_grid = g_grid. " 设置enter事件 CALL METHOD g_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_enter EXCEPTIONS error = 1 OTHERS = 2. * 设置 单光标焦点移开被修改单元格后既触发事件 * CALL METHOD g_grid->register_edit_event * EXPORTING * i_event_id = cl_gui_alv_grid=>mc_evt_modified * EXCEPTIONS * error = 1 * OTHERS = 2. CLEAR gw_f4. gw_f4-fieldname = ‘PLNNR‘. gw_f4-register = ‘X‘. gw_f4-chngeafter = ‘X‘. APPEND gw_f4 TO gt_f4. CALL METHOD g_grid->register_f4_for_fields EXPORTING it_f4 = gt_f4[]. CREATE OBJECT gt_event_receiver. * SET HANDLER gt_event_receiver->handle_modify FOR g_grid. SET HANDLER gt_event_receiver->handle_onf4 FOR g_grid. ENDFORM. INCLUDE zppr002_module. *&---------------------------------------------------------------------* *& Form FRM_UNIT_CONVERT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_GW_MATNR_MATNR text * -->P_GW_MATNR_FRTME text * -->P_GW_WQDD_VRKME text * -->P_GW_WQDD_BMENG text *----------------------------------------------------------------------* FORM frm_unit_convert USING p_matnr p_in_unit p_out_unit p_in_sl CHANGING c_out_sl. ENDFORM. " FRM_UNIT_CONVERT *&---------------------------------------------------------------------* *& Form FRM_SCBCAP *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_scbcap . * CLEAR gt_row. * CALL METHOD g_grid->get_selected_rows * IMPORTING * et_index_rows = gt_row ** et_row_no = * . * READ TABLE gt_row INTO gw_row INDEX 1. * IF sy-subrc NE 0. * MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘. * RETURN. * ENDIF. * * READ TABLE gt_output INTO gw_output INDEX gw_row-index. READ TABLE gt_output INTO gw_output WITH KEY zsel = ‘X‘. IF sy-subrc NE 0. MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘. RETURN. ENDIF. IF gw_output-aufnr IS INITIAL. MESSAGE s000 WITH ‘生产订单编号为空,请先创建生产订单‘ DISPLAY LIKE ‘E‘. RETURN. ELSE. CALL SCREEN 100 STARTING AT 30 5 ENDING AT 65 13. ENDIF. ENDFORM. " FRM_SCBCAP *&---------------------------------------------------------------------* *& Form FRM_QD_SCBC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_qd_scbc . PERFORM frm_save_longtext. ENDFORM. " FRM_QD_SCBC *&---------------------------------------------------------------------* *& Form FRM_SAVE_LONGTEXT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_save_longtext . DATA:l_sl TYPE char20, l_mseh3 TYPE t006a-mseh3. IF ( g_jb + g_yb + g_bb ) GT gw_output-psmng. MESSAGE s000 WITH ‘生产订单‘ gw_output-aufnr ‘班次安排的数量之和要小于订单数量‘ DISPLAY LIKE ‘E‘. LEAVE SCREEN . ENDIF. CONCATENATE sy-mandt gw_output-aufnr INTO g_fname. CLEAR l_mseh3. SELECT SINGLE mseh3 INTO l_mseh3 FROM t006a WHERE spras = sy-langu AND msehi = gw_output-frtme. CLEAR:gw_tline,gt_tline. gw_tline-tdline = gw_output-zylly. APPEND gw_tline TO gt_tline. l_sl = g_jb. SHIFT l_sl LEFT DELETING LEADING space. CONCATENATE ‘甲班‘ l_sl l_mseh3 INTO gw_tline-tdline SEPARATED BY ‘-‘. APPEND gw_tline TO gt_tline. l_sl = g_yb. SHIFT l_sl LEFT DELETING LEADING space. CONCATENATE ‘乙班‘ l_sl l_mseh3 INTO gw_tline-tdline SEPARATED BY ‘-‘. APPEND gw_tline TO gt_tline. l_sl = g_bb. SHIFT l_sl LEFT DELETING LEADING space. CONCATENATE ‘丙班‘ l_sl l_mseh3 INTO gw_tline-tdline SEPARATED BY ‘-‘. APPEND gw_tline TO gt_tline. CALL FUNCTION ‘CREATE_TEXT‘ EXPORTING fid = ‘KOPF‘ flanguage = sy-langu fname = g_fname fobject = ‘AUFK‘ TABLES flines = gt_tline EXCEPTIONS no_init = 1 no_save = 2 OTHERS = 3. IF sy-subrc EQ 0. UPDATE aufk SET ltext = 1 WHERE aufnr = gw_output-aufnr. MESSAGE s000 WITH ‘生产订单‘ gw_output-aufnr ‘班次已安排‘. ELSE. MESSAGE s000 WITH ‘生产订单‘ gw_output-aufnr ‘班次安排失败‘ DISPLAY LIKE ‘E‘. ENDIF. LEAVE TO SCREEN 0. ENDFORM. " FRM_SAVE_LONGTEXT *&---------------------------------------------------------------------* *& Form FRM_GET_BC *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM frm_get_bc . DATA:l_index TYPE i, l_zbc TYPE string, l_menge TYPE string, l_meins TYPE string. CLEAR:g_fname,gw_tline,gt_tline. CONCATENATE sy-mandt gw_output-aufnr INTO g_fname. CALL FUNCTION ‘READ_TEXT‘ EXPORTING id = ‘KOPF‘ language = sy-langu name = g_fname object = ‘AUFK‘ TABLES lines = gt_tline EXCEPTIONS id = 1 language = 2 name = 3 not_found = 4 object = 5 reference_check = 6 wrong_access_to_archive = 7 OTHERS = 8. CLEAR:g_jb,g_yb,g_bb. LOOP AT gt_tline INTO gw_tline. CLEAR:l_zbc,l_menge,l_meins. SPLIT gw_tline-tdline AT ‘-‘ INTO l_zbc l_menge l_meins. CASE l_zbc. WHEN ‘甲班‘. g_jb = l_menge. WHEN ‘乙班‘. g_yb = l_menge. WHEN ‘丙班‘. g_bb = l_menge. WHEN OTHERS. ENDCASE. ENDLOOP. * IF g_jb IS NOT INITIAL OR g_yb IS NOT INITIAL AND g_bb IS NOT INITIAL. * "READ TABLE gt_order WITH KEY order_number = gw_output-aufnr TRANSPORTING NO FIELDS. * "IF sy-subrc NE 0. * LOOP AT SCREEN. * IF screen-name = ‘G_JB‘ OR screen-name = ‘G_YB‘ OR screen-name = ‘G_BB‘ . * screen-input = 0. * ELSEIF screen-name = ‘QUEDING‘ . * screen-input = 0. * screen-invisible = 0. * ENDIF. * MODIFY SCREEN. * ENDLOOP. * ENDIF. ENDFORM. " FRM_GET_BC FORM frm_plnnr TABLES it_shlp STRUCTURE seahlpres CHANGING r_shlp TYPE shlp_descr_t r_callcontrol LIKE ddshf4ctrl. DATA: ls_interface TYPE ddshiface. DATA: l_tabix TYPE sy-tabix. LOOP AT r_shlp-interface INTO ls_interface. l_tabix = sy-tabix. IF ls_interface-valfield IS INITIAL. ls_interface-valfield = ls_interface-shlpfield. MODIFY r_shlp-interface FROM ls_interface INDEX l_tabix. ENDIF. ENDLOOP. ENDFORM.
时间: 2024-10-27 12:25:09