*&---------------------------------------------------------------------* *& Report ZRHSSD002 *& *&---------------------------------------------------------------------* *&create by ly 20170123 *&for Inventory count input MI04 *& *& DEVK940966 2017.01.23 16:59:32 LIYUAN *&---------------------------------------------------------------------* REPORT ZRHSSD002 MESSAGE-ID ZCRM. "INVENTROY HEAD DATA TABLE TABLES:IKPF. TYPE-POOLS:SLIS. TYPES:BEGIN OF TY_ITAB, SEL(1), ICON(4), MESSAGE(100), MATNR TYPE ISEG-MATNR, CHARG TYPE ISEG-CHARG, ERFMG TYPE ISEG-ERFMG, ERFME TYPE ISEG-ERFME, END OF TY_ITAB. "Inventory item data itab DATA:GT_ITEM TYPE TABLE OF BAPI_PHYSINV_ITEM, GW_ITEM LIKE LINE OF GT_ITEM, GW_HEAD TYPE BAPI_PHYSINV_HEAD, GT_RETURN TYPE TABLE OF BAPIRET2, GW_RETURN LIKE LINE OF GT_RETURN, GT_ITEM_INPUT TYPE TABLE OF BAPI_PHYSINV_COUNT_ITEMS, GW_ITEM_INPUT LIKE LINE OF GT_ITEM_INPUT. DATA:GT_EXCEL_T TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE, GS_EXCEL_T LIKE LINE OF GT_EXCEL_T. DATA:GT_FIELDCAT TYPE LVC_T_FCAT. DATA GS_FIELDCAT LIKE LINE OF GT_FIELDCAT. DATA LS_LAYOUT TYPE LVC_S_LAYO. DATA:GT_ITAB TYPE TABLE OF TY_ITAB, GW_ITAB LIKE LINE OF GT_ITAB. DATA:LV_S TYPE STRING, LV_N TYPE STRING VALUE '0123456789.-'. DATA:GV_FM TYPE C."GL VALUE FOR DIFF FM. DEFINE APPEND_FIELDCAT . CLEAR GS_FIELDCAT. GS_FIELDCAT-FIELDNAME = &1. GS_FIELDCAT-SCRTEXT_L = &2. GS_FIELDCAT-OUTPUTLEN = &3. GS_FIELDCAT-NO_ZERO = &4. APPEND GS_FIELDCAT TO GT_FIELDCAT. END-OF-DEFINITION. SELECTION-SCREEN BEGIN OF BLOCK BLK01 WITH FRAME TITLE TEXT-001. PARAMETERS:P_IBLNR TYPE IKPF-IBLNR OBLIGATORY MEMORY ID IBN, P_GJAHR TYPE IKPF-GJAHR OBLIGATORY DEFAULT SY-DATUM+0(4), P_DATE TYPE IIKPF-ZLDAT OBLIGATORY DEFAULT SY-DATUM, P_FILE LIKE RLGRAP-FILENAME OBLIGATORY. SELECTION-SCREEN END OF BLOCK BLK01. AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE. PERFORM FRM_GET_FILEPATH. START-OF-SELECTION. CLEAR:GV_FM. PERFORM PRM_DATA_CHECK. PERFORM PRM_UPLOAD. PERFORM PRM_SET_FIELD. PERFORM PRM_SHOW. *&---------------------------------------------------------------------* *& Form FRM_GET_FILEPATH *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_GET_FILEPATH . CALL FUNCTION 'WS_FILENAME_GET' EXPORTING MASK = ',Excel(*.xls),*.XLS,*.XLSX,' TITLE = text-012 IMPORTING FILENAME = P_FILE EXCEPTIONS INV_WINSYS = 1 NO_BATCH = 2 SELECTION_CANCEL = 3 SELECTION_ERROR = 4 OTHERS = 5. IF SY-SUBRC <> 0. MESSAGE S000 DISPLAY LIKE 'E'."(ZCRM) TYPE 'S' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. ENDFORM. "FRM_GET_FILEPATH *&---------------------------------------------------------------------* *& Form PRM_DATA_CHECK *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM PRM_DATA_CHECK . CALL FUNCTION 'BAPI_MATPHYSINV_GETDETAIL' EXPORTING PHYSINVENTORY = P_IBLNR FISCALYEAR = P_GJAHR IMPORTING HEAD = GW_HEAD TABLES ITEMS = GT_ITEM RETURN = GT_RETURN. READ TABLE GT_RETURN INTO GW_RETURN WITH KEY TYPE = 'E'. IF SY-SUBRC = 0. MESSAGE GW_RETURN-MESSAGE TYPE 'S' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. IF GW_HEAD-DELETE_STATUS = 'X'. MESSAGE S001 DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. IF GW_HEAD-FREEZEBOOKINV = 'X'. MESSAGE S002 DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. SORT GT_ITEM[] BY MATERIAL. ENDFORM. "PRM_DATA_CHECK *&---------------------------------------------------------------------* *& Form PRM_UPLOAD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM PRM_UPLOAD . IF P_FILE IS NOT INITIAL. *将excel数据传入内表 CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING FILENAME = P_FILE I_BEGIN_COL = '1' I_BEGIN_ROW = '2' I_END_COL = '20' I_END_ROW = '5000' TABLES INTERN = GT_EXCEL_T. ENDIF. IF GT_EXCEL_T[] IS INITIAL. MESSAGE S003 DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. LOOP AT GT_EXCEL_T INTO GS_EXCEL_T. AT NEW ROW. CLEAR:GW_ITAB. ENDAT. CASE GS_EXCEL_T-COL. WHEN 1."MATNR GW_ITAB-MATNR = GS_EXCEL_T-VALUE. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING INPUT = GW_ITAB-MATNR IMPORTING OUTPUT = GW_ITAB-MATNR. READ TABLE GT_ITEM INTO GW_ITEM WITH KEY MATERIAL = GW_ITAB-MATNR BINARY SEARCH. IF SY-SUBRC = 0. IF GW_ITEM-QUANTITY <> 0. GV_FM = '1'."CHANGE MODE * GW_ITAB-MESSAGE = text-008. * GW_ITAB-ICON = '@0A@'. ENDIF. ELSE. GW_ITAB-MESSAGE = text-009. GW_ITAB-ICON = '@0A@'. ENDIF. WHEN 2."ERFMG CLEAR:LV_S. LV_S = GS_EXCEL_T-VALUE. IF LV_S CO LV_N. GW_ITAB-ERFMG = GS_EXCEL_T-VALUE. ELSE. GW_ITAB-MESSAGE = text-010. GW_ITAB-ICON = '@0A@'. ENDIF. WHEN 3."CHARG GW_ITAB-CHARG = GS_EXCEL_T-VALUE. WHEN OTHERS. ENDCASE. AT END OF ROW. APPEND GW_ITAB TO GT_ITAB. ENDAT. ENDLOOP. ENDFORM. "PRM_UPLOAD *&---------------------------------------------------------------------* *& Form PRM_SET_FIELD *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM PRM_SET_FIELD . REFRESH GT_FIELDCAT. LS_LAYOUT-CWIDTH_OPT = 'X'. "优化列宽选项是否设置 LS_LAYOUT-ZEBRA = 'X'. LS_LAYOUT-BOX_FNAME = 'SEL'. APPEND_FIELDCAT:'ICON' TEXT-002 1 '', 'MESSAGE' TEXT-003 100 '', 'MATNR' TEXT-004 18 'X', 'ERFMG' TEXT-005 17 'X'. * 'CHARG' TEXT-006 17 'X'. ENDFORM. "PRM_SET_FIELD *&---------------------------------------------------------------------* *& Form PRM_SHOW *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM PRM_SHOW . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING I_CALLBACK_PROGRAM = SY-REPID IS_LAYOUT_LVC = LS_LAYOUT IT_FIELDCAT_LVC = GT_FIELDCAT[] I_CALLBACK_PF_STATUS_SET = 'PRM_SET_STATUS' I_CALLBACK_USER_COMMAND = 'PRM_USER_COMMAND' * i_grid_title = lv_title I_DEFAULT = 'X' I_SAVE = 'A' TABLES T_OUTTAB = GT_ITAB EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2. IF SY-SUBRC <> 0. ENDIF. ENDFORM. "PRM_SHOW *&---------------------------------------------------------------------* *& Form PRM_SET_STATUS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->RT_EXTAB text *----------------------------------------------------------------------* FORM PRM_SET_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.. SET PF-STATUS 'ZSTAT'. ENDFORM. "PRM_SET_STATUS *&---------------------------------------------------------------------* *& Form PRM_USER_COMMAND *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_UCOMM text * -->P_SELFIELD text *----------------------------------------------------------------------* FORM PRM_USER_COMMAND USING P_UCOMM LIKE SY-UCOMM P_SELFIELD TYPE SLIS_SELFIELD. DATA:LR_GRID TYPE REF TO CL_GUI_ALV_GRID. CHECK P_UCOMM EQ 'EXCU'. CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING E_GRID = LR_GRID. CLEAR:GT_ITEM_INPUT[],GW_ITEM_INPUT,GT_RETURN[],GW_RETURN. LOOP AT GT_ITAB INTO GW_ITAB WHERE SEL = 'X' AND ICON = ''. READ TABLE GT_ITEM INTO GW_ITEM WITH KEY MATERIAL = GW_ITAB-MATNR BINARY SEARCH. IF SY-SUBRC = 0. GW_ITEM_INPUT-ITEM = GW_ITEM-ITEM. GW_ITEM_INPUT-MATERIAL = GW_ITEM-MATERIAL. GW_ITEM_INPUT-BATCH = GW_ITEM-BATCH. GW_ITEM_INPUT-ENTRY_QNT = GW_ITAB-ERFMG. IF GW_ITEM_INPUT-ENTRY_QNT = 0. GW_ITEM_INPUT-ZERO_COUNT = 'X'. ENDIF. GW_ITEM_INPUT-ENTRY_UOM = GW_ITEM-ENTRY_UOM. APPEND GW_ITEM_INPUT TO GT_ITEM_INPUT. CLEAR:GW_ITEM_INPUT. ENDIF. ENDLOOP. IF GT_ITEM_INPUT[] IS INITIAL. MESSAGE text-011 TYPE 'S' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ELSE. IF GV_FM IS INITIAL. CALL FUNCTION 'BAPI_MATPHYSINV_COUNT' EXPORTING PHYSINVENTORY = P_IBLNR FISCALYEAR = P_GJAHR COUNT_DATE = P_DATE TABLES ITEMS = GT_ITEM_INPUT RETURN = GT_RETURN. ELSE. CALL FUNCTION 'BAPI_MATPHYSINV_CHANGECOUNT' EXPORTING PHYSINVENTORY = P_IBLNR FISCALYEAR = P_GJAHR TABLES ITEMS = GT_ITEM_INPUT RETURN = GT_RETURN. ENDIF. READ TABLE GT_RETURN INTO GW_RETURN WITH KEY TYPE = 'E'. IF SY-SUBRC <> 0. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING WAIT = 'X'. LOOP AT GT_ITAB INTO GW_ITAB WHERE SEL = 'X' AND ICON = ''. GW_ITAB-ICON = '@08@'. GW_ITAB-MESSAGE = text-013. MODIFY GT_ITAB FROM GW_ITAB. ENDLOOP. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. READ TABLE GT_RETURN INTO GW_RETURN WITH KEY TYPE = 'E'. IF SY-SUBRC = 0. * MESSAGE GW_RETURN-MESSAGE TYPE 'S' DISPLAY LIKE 'E'. LOOP AT GT_ITAB INTO GW_ITAB WHERE SEL = 'X' AND ICON = ''. GW_ITAB-ICON = '@0A@'. GW_ITAB-MESSAGE = GW_RETURN-MESSAGE. MODIFY GT_ITAB FROM GW_ITAB. ENDLOOP. ENDIF. ENDIF. ENDIF. CALL METHOD LR_GRID->REFRESH_TABLE_DISPLAY. ENDFORM. "PRM_USER_COMMAND