*&---------------------------------------------------------------------**& Form FRM_RETRIVE_DATA*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM FRM_RETRIVE_DATA . DATA: LIT_RAW_DATA TYPE TRUXS_T_TEXT_DATA. DATA:LV_INDEX TYPE SY-INDEX. IF P_FILE IS INITIAL. MESSAGE TEXT-004 TYPE 'S'. LEAVE LIST-PROCESSING. ENDIF.*---提示消息:读取数据中..... CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' EXPORTING TEXT = TEXT-005.*---将EXCEL中的文件导入内表 CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' EXPORTING* I_FIELD_SEPERATOR =* I_LINE_HEADER = I_TAB_RAW_DATA = LIT_RAW_DATA I_FILENAME = P_FILE TABLES I_TAB_CONVERTED_DATA = GT_EXCEL EXCEPTIONS CONVERSION_FAILED = 1 OTHERS = 2 . IF SY-SUBRC <> 0. "提示消息:文件导入失败 MESSAGE TEXT-006 TYPE 'S'. LEAVE LIST-PROCESSING. ENDIF.*---判断是否存在相应的选择数据 DELETE GT_EXCEL INDEX 1. IF GT_EXCEL IS INITIAL. MESSAGE TEXT-007 TYPE 'S'. LEAVE LIST-PROCESSING. ENDIF.* CLEAR :LV_INDEX. LOOP AT GT_EXCEL INTO GS_EXCEL.* LV_INDEX = LV_INDEX + 1.* GS_OUTPUT-INDEX = LV_INDEX. MOVE-CORRESPONDING GS_EXCEL TO GS_OUTPUT. GS_OUTPUT-POSTP = 'L'. APPEND GS_OUTPUT TO GT_OUTPUT. ENDLOOP.* CLEAR GT_EXCEL.ENDFORM. " FRM_RETRIVE_DATA*&---------------------------------------------------------------------**& Form FRM_PROCESS_DATA*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM FRM_PROCESS_DATA . DATA:LWA_BOM_HEADER TYPE BICSK, LWA_GROUP_DATA TYPE BGR00, LIT_BOM_ITEM TYPE TABLE OF BICSP WITH HEADER LINE, LIT_BOM_SUB_ITEM TYPE TABLE OF BICSU WITH HEADER LINE, LV_MSGID TYPE T100-ARBGB, LV_MSGNO TYPE T100-MSGNR, LV_MSGTY TYPE SY-MSGTY, LV_MSGV1 TYPE SY-MSGV1, LV_MSGV2 TYPE SY-MSGV2, LV_MSGV3 TYPE SY-MSGV3, LV_MSGV4 TYPE SY-MSGV4. DATA:LWA_BAPIRET2 TYPE BAPIRET2. TYPES: BEGIN OF TY_MAST, MATNR(18),"物料号 STLAN(1),"用途 WERKS(4),"工厂 STLAL(2), END OF TY_MAST. DATA:LIT_MAST TYPE TABLE OF TY_MAST WITH HEADER LINE. DATA:LWA_TEMP TYPE TY_OUTPUT. DATA:LV_FLG TYPE CHAR1. DATA:LV_END TYPE CHAR1.*-----用来判断物料是否重复,如果重复则FLAG=‘X’. TYPES: BEGIN OF ty_check_exist, MATNR(18),"物料号 FLAG(1) TYPE C,"是否已存在(重复) END OF ty_check_exist. DATA: ls_exist TYPE ty_check_exist, lt_exist TYPE TABLE OF ty_check_exist, lv_flag(1) TYPE C. CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL' EXPORTING DATE_INTERNAL = s_datuv-low IMPORTING DATE_EXTERNAL = gv_datuv EXCEPTIONS DATE_INTERNAL_IS_INVALID = 1 OTHERS = 2 . IF SY-SUBRC <> 0.* Implement suitable error handling here ENDIF.*-----先将数据按照工厂,用途,物料,组件进行排序,并删除重复数据,然后再按照工厂,用途,物料,项目号进行排序* SORT GT_OUTPUT BY WERKS STLAN MATNR IDNRK.* DELETE ADJACENT DUPLICATES FROM GT_OUTPUT.* SORT GT_OUTPUT BY WERKS STLAN MATNR POSNR. LOOP AT GT_OUTPUT INTO GS_OUTPUT. TRANSLATE GS_OUTPUT-SANKA TO UPPER CASE. MODIFY GT_OUTPUT FROM GS_OUTPUT. ENDLOOP.*-----判断物料是否重复,重复则设置FLAG=‘X’,无重复则为‘’。 LOOP AT GT_OUTPUT INTO GS_OUTPUT WHERE MATNR IS NOT INITIAL."修改:添加where条件,不判断子项目记录 AT NEW MATNR. IF lt_exist IS INITIAL. ls_exist-MATNR = GS_OUTPUT-MATNR. ls_exist-FLAG = ''. APPEND ls_exist TO lt_exist. ELSE. lv_flag = ''. LOOP AT lt_exist INTO ls_exist. IF ls_exist-MATNR = GS_OUTPUT-MATNR. lv_flag = 'X'. EXIT. ENDIF. ENDLOOP. IF lv_flag = 'X'. ls_exist-MATNR = GS_OUTPUT-MATNR. ls_exist-FLAG = 'X'. MODIFY lt_exist FROM ls_exist TRANSPORTING FLAG WHERE MATNR = ls_exist-MATNR. ELSE. ls_exist-MATNR = GS_OUTPUT-MATNR. ls_exist-FLAG = ''. APPEND ls_exist TO lt_exist. ENDIF. ENDIF. ENDAT. ENDLOOP.*-----判断是否已经有该物料的BOM存在,如果存在的话则删除。 SELECT MATNR STLAN WERKS STLAL FROM MAST INTO CORRESPONDING FIELDS OF TABLE LIT_MAST FOR ALL ENTRIES IN GT_OUTPUT WHERE MATNR = GT_OUTPUT-MATNR AND WERKS = GT_OUTPUT-WERKS AND STLAN = GT_OUTPUT-STLAN. DATA PARENT_STYPE TYPE BICSP-STYPE."修改:添加该变量,记录当前结点,为写子项目记录做标记 DATA PARENT_XLINE TYPE BICSP-XLINE."修改:添加该变量,记录当前结点,为写子项目记录做标记 DATA PARENT_MATNR TYPE string."修改:添加该变量,记录当前结点,物料号 DATA PARENT_STLAN TYPE string."修改:添加该变量,记录当前结点,用途 DATA PARENT_WERKS TYPE string."修改:添加该变量,记录当前结点,工厂 DATA PARENT_STLAL TYPE string."修改:添加该变量,记录当前结点,可选BOM DATA COUNTER_XLINE TYPE I. COUNTER_XLINE = '0001'. CLEAR GS_OUTPUT. LOOP AT GT_OUTPUT INTO GS_OUTPUT."修改:将子物料的BOM表头信息添加上去。 IF GS_OUTPUT-MATNR IS NOT INITIAL. PARENT_MATNR = GS_OUTPUT-MATNR. PARENT_STLAN = GS_OUTPUT-STLAN. PARENT_WERKS = GS_OUTPUT-WERKS. PARENT_STLAL = GS_OUTPUT-STLAL. CONTINUE. ENDIF. IF PARENT_MATNR IS NOT INITIAL AND PARENT_STLAN IS NOT INITIAL AND PARENT_WERKS IS NOT INITIAL AND PARENT_STLAL IS NOT INITIAL. GS_OUTPUT-MATNR = PARENT_MATNR. GS_OUTPUT-STLAN = PARENT_STLAN. GS_OUTPUT-WERKS = PARENT_WERKS. GS_OUTPUT-STLAL = PARENT_STLAL. MODIFY GT_OUTPUT FROM GS_OUTPUT. ENDIF. ENDLOOP.