*&---------------------------------------------------------------------*
*& REPORT ZRSR3057*&*&---------------------------------------------------------------------**& DESCRIPTION : Production orders planning quantity & withdraw & confirmed*& CREATED BY : HUIYAN*& DATE : 2009.10.16*&-----------------------------------------------------------------------REPORT ZRSR3057.************************************************************************* T A B L E S *************************************************************************TABLES : RESB,AFKO,AUFK,MAKT,MBEW,MSEG,CAUFV.************************************************************************* I N T E R N A L T A B L E / D A T A *************************************************************************DATA : BEGIN OF WA_ITAB , WERKS LIKE RESB-WERKS, "工厂 AUFNR LIKE AFKO-AUFNR, "订单号 PLNBEZ LIKE AFKO-PLNBEZ, "成品料号 MAKTX LIKE MAKT-MAKTX, "成品描述 GAMNG LIKE AFKO-GAMNG, "订单数量总计 GMEIN LIKE AFKO-GMEIN, "条目单位 ERFMG1 LIKE MSEG-ERFMG, "101 102 数量 RSPOS LIKE RESB-RSPOS, "项目 MATNR LIKE RESB-MATNR, "组件料号 MAKTX2 LIKE MAKT-MAKTX, "组件描述 ERFMG LIKE RESB-ERFMG, "物料需求量 ERFME LIKE RESB-ERFME, "条目单位 MEINS LIKE RESB-MEINS, "基本计量单位 PLANG LIKE MSEG-ERFMG, "计划用量 ERFMG2 LIKE MSEG-ERFMG, "311 312发料数量 ERFME2 LIKE RESB-ERFME, "条目单位 ERFMG3 LIKE MSEG-ERFMG, "261 262数量 ERFME3 LIKE RESB-ERFME, "条目单位 VPRSV LIKE MBEW-VPRSV, "价格控制指示符 VERPR LIKE MBEW-VERPR, "移动平均价格/周期单价 STPRS LIKE MBEW-STPRS, "标准价格 PEINH LIKE MBEW-PEINH, "价格单位 BKLAS LIKE MBEW-BKLAS, "评估类 PRICE TYPE P DECIMALS 8, DIFF1 LIKE MSEG-ERFMG, DIFF2 LIKE MSEG-ERFMG, END OF WA_ITAB.DATA :ITAB LIKE WA_ITAB OCCURS 100 WITH HEADER LINE. DATA:BEGIN OF X_MSEG OCCURS 100, MATNR LIKE MSEG-MATNR, AUFNR LIKE MSEG-AUFNR, BWART LIKE MSEG-BWART, ERFMG LIKE MSEG-ERFMG, ERFME LIKE MSEG-ERFME, END OF X_MSEG. DATA:BEGIN OF IT_FILE1 OCCURS 100, "物料号 MATNR LIKE MAST-MATNR, END OF IT_FILE1. DATA:BEGIN OF IT_FILE2 OCCURS 100, AUFNR LIKE AUFK-AUFNR, "生产订单号 END OF IT_FILE2. DATA:TMPTXT LIKE MSEG-SGTXT,tmpAUFNR like AUFK-AUFNR. DATA:RATE1(16) TYPE P DECIMALS 9, RATE2(16) TYPE P DECIMALS 9, RATE3(16) TYPE P DECIMALS 9, RATE(16) TYPE P DECIMALS 9, TMP_QTY TYPE I.************************************************************************* A L V D A T A D E C L A R A T I O N S *************************************************************************TYPE-POOLS : SLIS.* ALV VARIABLE DECLARATIONDATA : GS_LAYOUT TYPE SLIS_LAYOUT_ALV.DATA : LFIELDX TYPE SLIS_T_FIELDCAT_ALV.DATA : LFIELD LIKE LINE OF LFIELDX.DATA : SORTINFO TYPE SLIS_T_SORTINFO_ALV.DATA : WA_SORTINFO LIKE LINE OF SORTINFO.DATA : G_REPID LIKE SY-REPID.DATA : G_TITLE TYPE SY-TITLE.DATA : G_USER_COMMAND TYPE SLIS_FORMNAME VALUE 'USER_COMMAND'.DATA : G_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.************************************************************************* S E L E C T I O N S C R E E N *************************************************************************SELECTION-SCREEN BEGIN OF BLOCK INPUT WITH FRAME.PARAMETERS P_1 RADIOBUTTON GROUP RD1 DEFAULT 'X' . "一、手工输入SELECTION-SCREEN BEGIN OF BLOCK 01 WITH FRAME TITLE TEXT-001.SELECT-OPTIONS : S_MATNR FOR RESB-MATNR MODIF ID F00.PARAMETER : P_WERKS LIKE AUFM-WERKS DEFAULT '301' MODIF ID F03.SELECT-OPTIONS : S_AUFNR FOR AUFK-AUFNR MODIF ID F00.SELECT-OPTIONS : S_AUART FOR AUFK-AUART MODIF ID F00.SELECTION-SCREEN END OF BLOCK 01.SELECTION-SCREEN SKIP 2.SELECTION-SCREEN COMMENT /1(70) TEXT-002.SELECTION-SCREEN SKIP.SELECTION-SCREEN BEGIN OF LINE. PARAMETERS: P_CH1 RADIOBUTTON GROUP RD1.SELECTION-SCREEN COMMENT 15(10) TEXT-F01 FOR FIELD P_CH1. PARAMETERS: P_FILE1 LIKE RLGRAP-FILENAME MODIF ID F01.SELECTION-SCREEN END OF LINE.SELECTION-SCREEN SKIP.SELECTION-SCREEN BEGIN OF LINE. PARAMETERS: P_CH2 RADIOBUTTON GROUP RD1.SELECTION-SCREEN COMMENT 15(10) TEXT-F02 FOR FIELD P_CH2. PARAMETERS: P_FILE2 LIKE RLGRAP-FILENAME MODIF ID F02.SELECTION-SCREEN END OF LINE .SELECTION-SCREEN END OF BLOCK INPUT.*----------------------------------------------------------------------* INITIALIZATION.*----------------------------------------------------------------------*LOOP AT SCREEN. IF SCREEN-GROUP1 = 'F01' OR SCREEN-GROUP1 = 'F02' OR SCREEN-GROUP1 = 'F03'. SCREEN-INPUT = 0. MODIFY SCREEN. ENDIF. ENDLOOP.*----------------------------------------------------------------------*AT SELECTION-SCREEN OUTPUT.*----------------------------------------------------------------------*** 手工输入IF P_1 = 'X'.LOOP AT SCREEN. IF SCREEN-GROUP1 = 'F00'. SCREEN-INPUT = 1. MODIFY SCREEN. ENDIF. IF SCREEN-GROUP1 = 'F01' OR SCREEN-GROUP1 = 'F02' OR SCREEN-GROUP1 = 'F03'. SCREEN-INPUT = 0. CLEAR: P_FILE1 ,P_FILE2. MODIFY SCREEN. ENDIF. ENDLOOP. ENDIF.IF P_CH1 = 'X'.LOOP AT SCREEN. IF SCREEN-GROUP1 = 'F01'. SCREEN-INPUT = 1. MODIFY SCREEN. ENDIF. IF SCREEN-GROUP1 = 'F00' OR SCREEN-GROUP1 = 'F02' OR SCREEN-GROUP1 = 'F03'. SCREEN-INPUT = 0. CLEAR: P_FILE2. REFRESH:S_MATNR,S_AUFNR,S_AUART. MODIFY SCREEN. ENDIF. ENDLOOP. ENDIF.IF P_CH2 = 'X'.LOOP AT SCREEN. IF SCREEN-GROUP1 = 'F02'. SCREEN-INPUT = 1. MODIFY SCREEN. ENDIF. IF SCREEN-GROUP1 = 'F01' OR SCREEN-GROUP1 = 'F00' OR SCREEN-GROUP1 = 'F03'. SCREEN-INPUT = 0. CLEAR: P_FILE1. REFRESH:S_MATNR,S_AUFNR,S_AUART. MODIFY SCREEN. ENDIF. ENDLOOP. ENDIF.*----------------------------------------------------------------------*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE1.*----------------------------------------------------------------------* CALL FUNCTION 'WS_FILENAME_GET' EXPORTING DEF_FILENAME = '' DEF_PATH = 'C:\' MASK = ',文本文件(*.TXT),*.TXT.' MODE = 'O' TITLE = '选择上传文件(SELECT UPLOAD FILE)' IMPORTING FILENAME = P_FILE1 EXCEPTIONS INV_WINSYS = 1 NO_BATCH = 2 SELECTION_CANCEL = 3 SELECTION_ERROR = 4 OTHERS = 5.*----------------------------------------------------------------------*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE2.*----------------------------------------------------------------------* CALL FUNCTION 'WS_FILENAME_GET' EXPORTING DEF_FILENAME = '' DEF_PATH = 'C:\' MASK = ',文本文件(*.TXT),*.TXT.' MODE = 'O' TITLE = '选择上传文件(SELECT UPLOAD FILE)' IMPORTING FILENAME = P_FILE2 EXCEPTIONS INV_WINSYS = 1 NO_BATCH = 2 SELECTION_CANCEL = 3 SELECTION_ERROR = 4 OTHERS = 5.************************************************************************* S T A R T - O F - S E L E C T I O N ************************************************************************* START-OF-SELECTION. IF P_1 = 'X'.** 手工输入 IF S_AUFNR IS INITIAL AND S_MATNR IS INITIAL AND S_AUART IS INITIAL. MESSAGE I001(00) WITH '请至少输入生产订单号或物料号或订单类型!' '( PLEASE ENTER AT LEAST THE PRODUCTION ORDERS OR MATERIAL OR THE TYPE OF PRODUCTION ORDERS ! )'. STOP. ENDIF. PERFORM SELECT_DATA. ELSE.** 本地上传 IF P_CH1 = 'X'. IF P_FILE1 IS INITIAL. MESSAGE I001(00) WITH '请上传物料号文件!' '( PLEASE UPLOAD A DOCUMENT OF MATERIALS ! )'. STOP. ENDIF. PERFORM UPLOAD1. "上传物料号 PERFORM GET_DATA1. ELSE. IF P_FILE2 IS INITIAL. MESSAGE I001(00) WITH '请上传订单号文件!' '( PLEASE UPLOAD A DOCUMENT OF PRODUCTION ORDERS ! )'. STOP. ENDIF. PERFORM UPLOAD2. "上传订单号 PERFORM GET_DATA2. ENDIF. ENDIF. if itab[] is INITIAL. MESSAGE I001(00) WITH '无相关数据!'. STOP. endif. PERFORM PROCESS. IF SY-LANGU = 'E'. PERFORM PREPARE_FIELDCAT. ELSEIF SY-LANGU = '1'. PERFORM PREPARE_FIELDCAT_CHINESE. ENDIF.PERFORM DISPLAY_ALV_REPORT.*&---------------------------------------------------------------------**& FORM UPLOAD1*&---------- -----------------------------------------------------------** 从PC上传物料号到内表IT_FILE1中*&---------------------------------------------------------------------*FORM UPLOAD1. CALL FUNCTION 'WS_UPLOAD' EXPORTING FILENAME = P_FILE1 FILETYPE = 'DAT' TABLES DATA_TAB = IT_FILE1 EXCEPTIONS CONVERSION_ERROR = 1 FILE_OPEN_ERROR = 2 FILE_READ_ERROR = 3 INVALID_TYPE = 4 NO_BATCH = 5 UNKNOWN_ERROR = 6 INVALID_TABLE_WIDTH = 7 GUI_REFUSE_FILETRANSFER = 8 CUSTOMER_ERROR = 9 OTHERS = 10. IF SY-SUBRC NE 0. MESSAGE I000(FB) WITH '打开文件' P_FILE1 '错误'. EXIT. ENDIF.if IT_FILE1[] is initial. MESSAGE I001(00) WITH '文件中无数据!'. STOP. endif.*-对上传的数据中的物料号进行处理 LOOP AT IT_FILE1. TRANSLATE IT_FILE1-MATNR TO UPPER CASE. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = IT_FILE1-MATNR IMPORTING OUTPUT = IT_FILE1-MATNR. MODIFY IT_FILE1. ENDLOOP. ENDFORM.*&---------------------------------------------------------------------**& FORM UPLOAD2*&---------------------------------------------------------------------** 从PC上传订单号到内表IT_FILE2中*&---------------------------------------------------------------------*FORM UPLOAD2. CALL FUNCTION 'WS_UPLOAD' EXPORTING FILENAME = P_FILE2 FILETYPE = 'DAT' TABLES DATA_TAB = IT_FILE2 EXCEPTIONS CONVERSION_ERROR = 1 FILE_OPEN_ERROR = 2 FILE_READ_ERROR = 3 INVALID_TYPE = 4 NO_BATCH = 5 UNKNOWN_ERROR = 6 INVALID_TABLE_WIDTH = 7 GUI_REFUSE_FILETRANSFER = 8 CUSTOMER_ERROR = 9 OTHERS = 10. IF SY-SUBRC NE 0. MESSAGE I000(FB) WITH '打开文件' P_FILE2 '错误'. EXIT. ENDIF.if IT_FILE2[] is initial. MESSAGE I001(00) WITH '文件中无数据!'. STOP. endif.*-对上传的数据中的订单号进行处理 LOOP AT IT_FILE2. TRANSLATE IT_FILE2-AUFNR TO UPPER CASE. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = IT_FILE2-AUFNR IMPORTING OUTPUT = IT_FILE2-AUFNR. MODIFY IT_FILE2. ENDLOOP. ENDFORM. " UPLOAD2*-------------------------** FORM DISPLAY_ALV_REPORT **-------------------------*FORM DISPLAY_ALV_REPORT. GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. GS_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'. G_REPID = SY-REPID. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING I_CALLBACK_PROGRAM = G_REPID I_CALLBACK_TOP_OF_PAGE = G_TOP_OF_PAGE I_CALLBACK_USER_COMMAND = G_USER_COMMAND I_GRID_TITLE = G_TITLE I_SAVE = 'A' IT_FIELDCAT = LFIELDX "LFIELDX[] IS_LAYOUT = GS_LAYOUT IT_SORT = SORTINFO TABLES T_OUTTAB = ITAB. ENDFORM. "DISPLAY_ALV_REPORT*&---------------------------------------------------------------------**& FORM SELECT_DATA*&---------------------------------------------------------------------** TEXT*----------------------------------------------------------------------** --> P1 TEXT* <-- P2 TEXT*----------------------------------------------------------------------*FORM SELECT_DATA . IF NOT S_AUFNR IS INITIAL. SELECT AFKO~AUFNR AFKO~PLNBEZ AFKO~GAMNG AFKO~GMEIN MAKT~MAKTX RESB~WERKS RESB~MATNR RESB~RSPOS RESB~ERFMG RESB~ERFME RESB~MEINS FROM AFKO JOIN RESB ON RESB~AUFNR = AFKO~AUFNR JOIN MAKT ON MAKT~MATNR = AFKO~PLNBEZ AND MAKT~SPRAS = '1' INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE AFKO~AUFNR IN S_AUFNR. ELSEIF S_AUFNR IS INITIAL. SELECT AFKO~AUFNR AFKO~PLNBEZ AFKO~GAMNG AFKO~GMEIN MAKT~MAKTX RESB~WERKS RESB~MATNR RESB~RSPOS RESB~ERFMG RESB~ERFME RESB~MEINS FROM AFKO JOIN RESB ON RESB~AUFNR = AFKO~AUFNR JOIN MAKT ON MAKT~MATNR = AFKO~PLNBEZ AND MAKT~SPRAS = '1' JOIN CAUFV ON CAUFV~AUFNR = AFKO~AUFNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE AFKO~PLNBEZ IN S_MATNR AND RESB~WERKS = P_WERKS AND CAUFV~AUART IN S_AUART. ENDIF. ENDFORM. " SELECT_DATA*&---------------------------------------------------------------------**& FORM GET_DATA1*&---------------------------------------------------------------------** TEXT*----------------------------------------------------------------------** --> P1 TEXT* <-- P2 TEXT*----------------------------------------------------------------------*FORM GET_DATA1 . SELECT AFKO~AUFNR AFKO~PLNBEZ AFKO~GAMNG AFKO~GMEIN MAKT~MAKTX RESB~WERKS RESB~MATNR RESB~RSPOS RESB~ERFMG RESB~ERFME RESB~MEINS FROM AFKO JOIN RESB ON RESB~AUFNR = AFKO~AUFNR JOIN MAKT ON MAKT~MATNR = AFKO~PLNBEZ AND MAKT~SPRAS = '1' JOIN CAUFV ON CAUFV~AUFNR = AFKO~AUFNR INTO CORRESPONDING FIELDS OF TABLE ITAB FOR ALL ENTRIES IN IT_FILE1 WHERE AFKO~PLNBEZ = IT_FILE1-MATNR AND RESB~WERKS = P_WERKS AND CAUFV~AUART IN S_AUART. ENDFORM. " GET_DATA1*&---------------------------------------------------------------------**& FORM GET_DATA2*&---------------------------------------------------------------------** TEXT*----------------------------------------------------------------------** --> P1 TEXT* <-- P2 TEXT*----------------------------------------------------------------------*FORM GET_DATA2 . SELECT AFKO~AUFNR AFKO~PLNBEZ AFKO~GAMNG AFKO~GMEIN MAKT~MAKTX RESB~WERKS RESB~MATNR RESB~RSPOS RESB~ERFMG RESB~ERFME RESB~MEINS FROM AFKO JOIN RESB ON RESB~AUFNR = AFKO~AUFNR JOIN MAKT ON MAKT~MATNR = AFKO~PLNBEZ AND MAKT~SPRAS = '1' INTO CORRESPONDING FIELDS OF TABLE ITAB FOR ALL ENTRIES IN IT_FILE2 WHERE AFKO~AUFNR = IT_FILE2-AUFNR. ENDFORM. " GET_DATA2