工艺路线批导(备份)详解编程语言

*&---------------------------------------------------------------------* 
*& Report  ZPPC001 
*& 
*&---------------------------------------------------------------------* 
*& SAP Module     PP 
*& Author         Leon 
*& Created Date   2015.5.15 
*& Description    工艺路线批量导入 
*&---------------------------------------------------------------------* 
REPORT ZPPC001 NO STANDARD PAGE HEADING. 
TABLES: SSCRFIELDS. 
DATA: BEGIN OF gt_upload OCCURS 0, 
werks   TYPE werks_d,         " 工厂 
matnr   TYPE matnr,           " 物料 
plnal   LIKE plko-plnal,      " 组计数器(版本) 
vornr   LIKE plpo-vornr,      " 工序 
arbpl   LIKE crhd-arbpl,      " 工作中心 
ltxa1   LIKE plpo-ltxa1,      " 工序描述 
*  bmsch   LIKE plpo-bmsch, 
bmsch(17),                    " 基本数量 
meinh   LIKE plpo-meinh,      " 工序单位 
vgw01(17),                    " 人工 
vge01   LIKE plpo-vge01,      " 单位 
vgw02(17),                    " 其它制费 
vge02   LIKE plpo-vge02, 
vgw03(17),                    " 
vge03   LIKE plpo-vge03, 
vgw04(17),                    " 蒸汽 
vge04   LIKE plpo-vge04, 
vgw05(17),                    " 天然气 
vge05   LIKE plpo-vge05, 
seq     TYPE I, 
maktx   LIKE makt-maktx, 
ktext   LIKE plko-ktext,      " 任务清单描述(版本描述) 
status(10), 
message TYPE string, 
tabix   TYPE I,               " 内部序号,仅供程序使用 
END OF gt_upload. 
DATA: gs_upload LIKE LINE OF gt_upload. 
FIELD-SYMBOLS: <fs_upload> LIKE gs_upload. 
DATA: gv_flag,                                    " 是否可上载标识 
gv_commit.                                  " 重复提交标识 
********************************************************************** 
* ALV Variable 
********************************************************************** 
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, 
gt_sort     TYPE slis_t_sortinfo_alv, 
gs_fieldcat LIKE LINE OF gt_fieldcat, 
gs_layout   TYPE slis_layout_alv. 
********************************************************************** 
* Macro Definition 
********************************************************************** 
DEFINE def_fieldcat. 
CLEAR gs_fieldcat. 
gs_fieldcat-fieldname       = &1.   " fieldname 
gs_fieldcat-seltext_s       = &2.   " description 
gs_fieldcat-seltext_m       = &2. 
gs_fieldcat-seltext_l       = &2. 
gs_fieldcat-key             = &3.   " key column 
gs_fieldcat-outputlen       = &4.   " output length 
gs_fieldcat-no_zero         = &5.   " no zero 
gs_fieldcat-do_sum          = &6.   " sum 
gs_fieldcat-ref_tabname     = &7.   " reference table 
gs_fieldcat-ref_fieldname   = &8.   " reference field 
APPEND gs_fieldcat TO gt_fieldcat. 
END-OF-DEFINITION. 
CONSTANTS c_default_filename TYPE string 
VALUE 'C:/route v1.0.xls'. 
SELECTION-SCREEN FUNCTION KEY 1. 
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. 
PARAMETERS: p_fname TYPE string, 
p_sline TYPE I DEFAULT 2 OBLIGATORY. 
SELECTION-SCREEN END OF BLOCK b1. 
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002. 
PARAMETERS: p_datuv TYPE datuv. 
SELECTION-SCREEN END OF BLOCK b2. 
INITIALIZATION. 
PERFORM initial_data. 
AT SELECTION-SCREEN. 
PERFORM template_download. 
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname. 
PERFORM f4_for_file_name. 
START-OF-SELECTION. 
PERFORM check_input. 
PERFORM get_data. 
PERFORM process_data. 
PERFORM display_data. 
FORM check_input. 
IF p_fname IS INITIAL. 
MESSAGE TEXT-E02 TYPE 'S' DISPLAY LIKE 'E'. 
STOP. 
ENDIF. 
ENDFORM. 
FORM get_data. 
PERFORM read_excel_to_table. 
PERFORM check_authority. 
ENDFORM. 
FORM process_data. 
DATA: lv_msg TYPE STRING. 
DATA: BEGIN OF lt_exist OCCURS 0, 
matnr LIKE marc-matnr, 
werks LIKE marc-werks, 
END OF lt_exist. 
SELECT matnr werks INTO TABLE lt_exist 
FROM marc 
FOR ALL ENTRIES IN gt_upload 
WHERE matnr EQ gt_upload-matnr 
AND werks EQ gt_upload-werks. 
SORT lt_exist BY matnr werks. 
LOOP AT gt_upload ASSIGNING <fs_upload>. 
<fs_upload>-status = icon_led_yellow. 
READ TABLE lt_exist WITH KEY matnr = <fs_upload>-matnr werks = <fs_upload>-werks BINARY SEARCH. 
IF sy-subrc NE 0. 
<fs_upload>-status  = icon_led_red. 
CLEAR lv_msg. 
lv_msg = TEXT-E09 && <fs_upload>-werks && TEXT-E10 && <fs_upload>-matnr. 
<fs_upload>-MESSAGE = lv_msg. 
gv_flag = 'X'. 
CONTINUE. 
ENDIF. 
ENDLOOP. 
ENDFORM. 
FORM display_data. 
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' 
EXPORTING 
text = TEXT-S02. 
CLEAR: gs_layout,gt_fieldcat[]. 
PERFORM frm_set_layout. 
PERFORM frm_set_fieldcat. 
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 
EXPORTING 
*      I_INTERFACE_CHECK                 = ' ' 
*      I_BYPASSING_BUFFER                = ' ' 
*      I_BUFFER_ACTIVE                   = ' ' 
i_callback_program                = sy-repid 
i_callback_pf_status_set          = 'FRM_PF_STATUS' 
i_callback_user_command           = 'FRM_USER_COMMAND' 
*      I_CALLBACK_TOP_OF_PAGE            = ' ' 
*      I_CALLBACK_HTML_TOP_OF_PAGE       = ' ' 
*      I_CALLBACK_HTML_END_OF_LIST       = ' ' 
*      I_STRUCTURE_NAME                  = 
*      I_BACKGROUND_ID                   = ' ' 
*      I_GRID_TITLE                      = 
*      I_GRID_SETTINGS                   = 
is_layout                         = gs_layout 
it_fieldcat                       = gt_fieldcat 
*      IT_EXCLUDING                      = 
*      IT_SPECIAL_GROUPS                 = 
*      it_sort                           = gt_sort 
*      IT_FILTER                         = 
*      IS_SEL_HIDE                       = 
i_default                         = 'X' 
i_save                            = 'A' 
*      IS_VARIANT                        = 
*      IT_EVENTS                         = 
*      IT_EVENT_EXIT                     = 
*      IS_PRINT                          = 
*      IS_REPREP_ID                      = 
*      I_SCREEN_START_COLUMN             = 0 
*      I_SCREEN_START_LINE               = 0 
*      I_SCREEN_END_COLUMN               = 0 
*      I_SCREEN_END_LINE                 = 0 
*      I_HTML_HEIGHT_TOP                 = 0 
*      I_HTML_HEIGHT_END                 = 0 
*      IT_ALV_GRAPHICS                   = 
*      IT_HYPERLINK                      = 
*      IT_ADD_FIELDCAT                   = 
*      IT_EXCEPT_QINFO                   = 
*      IR_SALV_FULLSCREEN_ADAPTER        = 
*    IMPORTING 
*      E_EXIT_CAUSED_BY_CALLER           = 
*      ES_EXIT_CAUSED_BY_USER            = 
TABLES 
t_outtab                          = gt_upload 
EXCEPTIONS 
program_error                     = 1 
OTHERS                            = 2. 
IF sy-subrc <> 0. 
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
ENDIF. 
ENDFORM. 
FORM save_upload_data. 
DATA: lt_task TYPE TABLE OF bapi1012_tsk_c WITH HEADER LINE, 
lt_matnr_alloc TYPE TABLE OF bapi1012_mtk_c WITH HEADER LINE, 
lt_oper TYPE TABLE OF bapi1012_opr_c WITH HEADER LINE, 
lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE, 
lv_result, 
lv_msg TYPE string, 
lv_from TYPE I, 
lv_to TYPE I, 
lv_tabix TYPE sy-tabix. 
DATA: lv_group LIKE mapl-plnnr.       " 
*  DATA: BEGIN OF lt_mara OCCURS 0, 
*    matnr LIKE mara-matnr, 
*    meins LIKE mara-meins, 
*  END OF lt_mara. 
DATA: BEGIN OF lt_mapl OCCURS 0, 
matnr LIKE mapl-matnr, 
werks LIKE mapl-werks, 
plnnr LIKE mapl-plnnr, 
END OF lt_mapl. 
SORT gt_upload BY werks matnr plnal vornr. 
IF gt_upload[] IS NOT INITIAL. 
*    SELECT DISTINCT matnr meins INTO TABLE lt_mara 
*      FROM mara 
*      FOR ALL ENTRIES IN gt_upload 
*      WHERE matnr EQ gt_upload-matnr. 
*    SORT lt_mara BY matnr. 
SELECT matnr werks plnnr INTO TABLE lt_mapl 
FROM mapl 
FOR ALL ENTRIES IN gt_upload 
WHERE matnr EQ gt_upload-matnr 
AND werks EQ gs_upload-werks 
AND plnty EQ 'N'. 
SORT lt_mapl BY matnr werks. 
ENDIF. 
LOOP AT gt_upload. 
gs_upload = gt_upload. 
lv_tabix = sy-tabix. 
AT NEW plnal. 
lv_from = lv_tabix. 
CLEAR lt_task. 
READ TABLE lt_mapl WITH KEY matnr = gs_upload-matnr werks = gs_upload-werks BINARY SEARCH. 
IF sy-subrc EQ 0. 
lt_task-task_list_group = lt_mapl-plnnr. 
ENDIF. 
*      lt_task-group_counter = gs_upload-plnal.         " 自动产生组计数器 
IF p_datuv IS NOT INITIAL. 
lt_task-valid_from = p_datuv. 
ELSE. 
lt_task-valid_from = sy-datum. 
ENDIF. 
lt_task-task_list_usage = '1'. 
lt_task-plant = gs_upload-werks. 
lt_task-task_list_status = '4'. 
lt_task-description = gs_upload-ktext. 
*      READ TABLE lt_mara WITH KEY matnr = gs_upload-matnr BINARY SEARCH. 
*      IF sy-subrc EQ 0. 
*        lt_task-task_measure_unit = lt_mara-meins. 
*      ENDIF. 
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' 
EXPORTING 
INPUT                = gs_upload-meinh 
IMPORTING 
OUTPUT               = gs_upload-meinh 
EXCEPTIONS 
UNIT_NOT_FOUND       = 1 
OTHERS               = 2. 
lt_task-task_measure_unit = gs_upload-meinh. 
APPEND lt_task. 
CLEAR lt_matnr_alloc. 
lt_matnr_alloc-material = gs_upload-matnr. 
lt_matnr_alloc-plant = gs_upload-werks. 
READ TABLE lt_mapl WITH KEY matnr = gs_upload-matnr werks = gs_upload-werks BINARY SEARCH. 
IF sy-subrc EQ 0. 
lt_matnr_alloc-task_list_group = lt_mapl-plnnr. 
ENDIF. 
*      lt_matnr_alloc-group_counter = gs_upload-plnal. 
IF p_datuv IS NOT INITIAL. 
lt_matnr_alloc-valid_from = p_datuv. 
ELSE. 
lt_matnr_alloc-valid_from = sy-datum. 
ENDIF. 
APPEND lt_matnr_alloc. 
ENDAT. 
CLEAR lt_oper. 
READ TABLE lt_mapl WITH KEY matnr = gs_upload-matnr werks = gs_upload-werks BINARY SEARCH. 
IF sy-subrc EQ 0. 
lt_oper-task_list_group = lt_mapl-plnnr. 
ENDIF. 
*    lt_oper-group_counter = gs_upload-plnal. 
IF p_datuv IS NOT INITIAL. 
lt_oper-valid_from = p_datuv. 
ELSE. 
lt_oper-valid_from = sy-datum. 
ENDIF. 
lt_oper-activity = gs_upload-vornr. 
lt_oper-work_cntr = gs_upload-arbpl. 
*    lt_oper-control_key = .            " 由工作中心自动带出 
lt_oper-plant = gs_upload-werks. 
lt_oper-description = gs_upload-ltxa1. 
lt_oper-operation_measure_unit = lt_task-task_measure_unit. 
lt_oper-base_quantity = gs_upload-bmsch. 
lt_oper-denominator = 1.            " 分母,必输 
lt_oper-nominator = 1. 
lt_oper-cost_relevant = 'X'. 
lt_oper-ind_splitting_reqrd = 'X'. 
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' 
EXPORTING 
INPUT                = gs_upload-vge01 
IMPORTING 
OUTPUT               = gs_upload-vge01 
EXCEPTIONS 
UNIT_NOT_FOUND       = 1 
OTHERS               = 2. 
lt_oper-std_unit_01  = gs_upload-vge01. 
lt_oper-std_value_01 = gs_upload-vgw01. 
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' 
EXPORTING 
INPUT                = gs_upload-vge02 
IMPORTING 
OUTPUT               = gs_upload-vge02 
EXCEPTIONS 
UNIT_NOT_FOUND       = 1 
OTHERS               = 2. 
lt_oper-std_unit_02  = gs_upload-vge02. 
lt_oper-std_value_02 = gs_upload-vgw02. 
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' 
EXPORTING 
INPUT                = gs_upload-vge03 
IMPORTING 
OUTPUT               = gs_upload-vge03 
EXCEPTIONS 
UNIT_NOT_FOUND       = 1 
OTHERS               = 2. 
lt_oper-std_unit_03  = gs_upload-vge03. 
lt_oper-std_value_03 = gs_upload-vgw03. 
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' 
EXPORTING 
INPUT                = gs_upload-vge04 
IMPORTING 
OUTPUT               = gs_upload-vge04 
EXCEPTIONS 
UNIT_NOT_FOUND       = 1 
OTHERS               = 2. 
lt_oper-std_unit_04  = gs_upload-vge04. 
lt_oper-std_value_04 = gs_upload-vgw04. 
CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' 
EXPORTING 
INPUT                = gs_upload-vge05 
IMPORTING 
OUTPUT               = gs_upload-vge05 
EXCEPTIONS 
UNIT_NOT_FOUND       = 1 
OTHERS               = 2. 
lt_oper-std_unit_05  = gs_upload-vge05. 
lt_oper-std_value_05 = gs_upload-vgw05. 
APPEND lt_oper. 
AT END OF plnal. 
lv_to = lv_tabix. 
CALL FUNCTION 'BAPI_ROUTING_CREATE' 
*       EXPORTING 
*         TESTRUN                      = ' ' 
*         PROFILE                      = 
*         BOMUSAGE                     = ' ' 
*         APPLICATION                  = ' ' 
*       IMPORTING 
*         GROUP                        = 
*         GROUPCOUNTER                 = 
TABLES 
TASK                         = lt_task 
MATERIALTASKALLOCATION       = lt_matnr_alloc 
*         SEQUENCE                     = 
OPERATION                    = lt_oper 
*         SUBOPERATION                 = 
*         REFERENCEOPERATION           = 
*         WORKCENTERREFERENCE          = 
*         COMPONENTALLOCATION          = 
*         PRODUCTIONRESOURCE           = 
*         INSPCHARACTERISTIC           = 
*         TEXTALLOCATION               = 
*         TEXT                         = 
RETURN                       = lt_return. 
REFRESH: lt_task,lt_matnr_alloc,lt_oper. 
CLEAR lv_result. 
LOOP AT lt_return WHERE TYPE = 'E' OR TYPE = 'A'. 
lv_result = 'X'. 
EXIT. 
ENDLOOP. 
IF lv_result EQ 'X'. 
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. 
CALL FUNCTION 'FORMAT_MESSAGE' 
EXPORTING 
ID              = lt_return-ID 
LANG            = SY-LANGU 
NO              = lt_return-number 
V1              = lt_return-message_v1 
V2              = lt_return-message_v2 
V3              = lt_return-message_v3 
V4              = lt_return-message_v4 
IMPORTING 
MSG             = lv_msg 
EXCEPTIONS 
NOT_FOUND       = 1 
OTHERS          = 2. 
CLEAR gs_upload. 
gs_upload-status = icon_led_red. 
MODIFY gt_upload FROM gs_upload TRANSPORTING status WHERE tabix BETWEEN lv_from AND lv_to. 
gs_upload-message = lv_msg. 
MODIFY gt_upload FROM gs_upload INDEX lv_from TRANSPORTING message. 
ELSE. 
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' 
EXPORTING 
WAIT          = 'X'. 
gv_commit = 'X'. 
READ TABLE lt_return WITH KEY TYPE = 'S'. 
CALL FUNCTION 'FORMAT_MESSAGE' 
EXPORTING 
ID              = lt_return-ID 
LANG            = SY-LANGU 
NO              = lt_return-number 
V1              = lt_return-message_v1 
V2              = lt_return-message_v2 
V3              = lt_return-message_v3 
V4              = lt_return-message_v4 
IMPORTING 
MSG             = lv_msg 
EXCEPTIONS 
NOT_FOUND       = 1 
OTHERS          = 2. 
CLEAR gs_upload. 
gs_upload-status = icon_led_green. 
MODIFY gt_upload FROM gs_upload TRANSPORTING status WHERE tabix BETWEEN lv_from AND lv_to. 
gs_upload-message = lv_msg. 
MODIFY gt_upload FROM gs_upload INDEX lv_from TRANSPORTING message. 
ENDIF. 
ENDAT. 
ENDLOOP. 
ENDFORM. 
FORM frm_user_command USING VALUE(pv_ucomm) LIKE sy-ucomm 
pr_selfield TYPE slis_selfield. 
CASE pv_ucomm. 
WHEN 'BUILD'. 
IF gv_flag IS INITIAL. 
IF gv_commit EQ 'X'. 
MESSAGE TEXT-E17 TYPE 'E'. 
EXIT. 
ENDIF. 
PERFORM save_upload_data. 
pr_selfield-refresh    = 'X'. 
SET USER-COMMAND '&OPT'. 
ELSE. 
MESSAGE TEXT-E12 TYPE 'E'. 
EXIT. 
ENDIF. 
WHEN OTHERS. 
ENDCASE. 
ENDFORM. 
FORM frm_pf_status USING pr_extab TYPE slis_t_extab. 
SET PF-STATUS 'STANDARD_UPLOAD' EXCLUDING pr_extab. 
ENDFORM. 
FORM frm_set_fieldcat. 
def_fieldcat 'STATUS'   TEXT-A01 '' '4' '' '' '' ''. 
def_fieldcat 'MESSAGE'  TEXT-A02 '' '20' '' '' '' ''. 
def_fieldcat 'SEQ'      TEXT-A12 '' '3' '' '' '' ''. 
def_fieldcat 'WERKS'    TEXT-A03 '' '4' '' '' '' ''. 
def_fieldcat 'MATNR'    TEXT-A04 '' '18' 'X' '' '' ''. 
def_fieldcat 'MAKTX'    TEXT-A05 '' '' '' '' '' ''. 
def_fieldcat 'PLNAL'    TEXT-A06 '' '2' '' '' '' ''. 
def_fieldcat 'KTEXT'    TEXT-A19 '' '' '' '' '' ''. 
def_fieldcat 'VORNR'    TEXT-A07 '' '4' '' '' '' ''. 
def_fieldcat 'ARBPL'    TEXT-A08 '' '8' '' '' '' ''. 
def_fieldcat 'LTXA1'    TEXT-A09'' '' '' '' '' ''. 
def_fieldcat 'BMSCH'    TEXT-A10 '' '' '' '' '' ''. 
def_fieldcat 'MEINH'    TEXT-A11 '' '3' '' '' '' ''. 
def_fieldcat 'VGW01'    TEXT-A13 '' '' '' '' '' ''. 
def_fieldcat 'VGE01'    TEXT-A14 '' '' '' '' '' ''. 
def_fieldcat 'VGW02'    TEXT-A15 '' '' '' '' '' ''. 
def_fieldcat 'VGE02'    TEXT-A14 '' '' '' '' '' ''. 
def_fieldcat 'VGW03'    TEXT-A16 '' '' '' '' '' ''. 
def_fieldcat 'VGE03'    TEXT-A14 '' '' '' '' '' ''. 
def_fieldcat 'VGW04'    TEXT-A17 '' '' '' '' '' ''. 
def_fieldcat 'VGE04'    TEXT-A14 '' '' '' '' '' ''. 
def_fieldcat 'VGW05'    TEXT-A18 '' '' '' '' '' ''. 
def_fieldcat 'VGE05'    TEXT-A14 '' '' '' '' '' ''. 
ENDFORM. 
FORM frm_set_layout. 
gs_layout-zebra = 'X'. 
gs_layout-colwidth_optimize = 'X'. 
*  gs_layout-box_fieldname = 'SEL'. 
ENDFORM. 
FORM read_excel_to_table. 
DATA: lv_filename TYPE rlgrap-filename, 
lt_excel    TYPE TABLE OF alsmex_tabline, 
ls_excel    LIKE LINE OF lt_excel, 
lv_tabix    TYPE I. 
lv_filename = p_fname. 
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' 
EXPORTING 
filename                = lv_filename 
i_begin_col             = 1 
i_begin_row             = p_sline 
i_end_col               = 256 
i_end_row               = 65535 
TABLES 
intern                  = lt_excel 
EXCEPTIONS 
inconsistent_parameters = 1 
upload_ole              = 2 
OTHERS                  = 3. 
IF sy-subrc <> 0. 
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
ENDIF. 
SORT lt_excel BY row col. 
LOOP AT lt_excel INTO ls_excel. 
CASE ls_excel-col. 
WHEN 1. 
gs_upload-seq             = ls_excel-value. 
WHEN 2. 
gs_upload-werks           = ls_excel-value. 
CONDENSE gs_upload-werks NO-GAPS. 
WHEN 3. 
gs_upload-matnr         = ls_excel-VALUE. 
CONDENSE gs_upload-matnr. 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' 
EXPORTING 
INPUT               = gs_upload-matnr 
IMPORTING 
OUTPUT              = gs_upload-matnr. 
WHEN 4. 
gs_upload-maktx         = ls_excel-value. 
CONDENSE gs_upload-maktx. 
WHEN 5. 
gs_upload-plnal         = ls_excel-value. 
CONDENSE gs_upload-plnal NO-GAPS. 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' 
EXPORTING 
INPUT               = gs_upload-plnal 
IMPORTING 
OUTPUT              = gs_upload-plnal. 
WHEN 6. 
gs_upload-ktext         = ls_excel-value. 
CONDENSE gs_upload-ktext. 
WHEN 7. 
gs_upload-vornr         = ls_excel-value. 
CONDENSE gs_upload-vornr NO-GAPS. 
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' 
EXPORTING 
INPUT               = gs_upload-vornr 
IMPORTING 
OUTPUT              = gs_upload-vornr. 
WHEN 8. 
gs_upload-arbpl         = ls_excel-value. 
CONDENSE gs_upload-arbpl NO-GAPS. 
WHEN 9. 
gs_upload-ltxa1         = ls_excel-value. 
CONDENSE gs_upload-ltxa1. 
WHEN 10. 
gs_upload-bmsch         = ls_excel-value. 
CONDENSE gs_upload-bmsch NO-GAPS. 
WHEN 11. 
gs_upload-meinh         = ls_excel-value. 
CONDENSE gs_upload-meinh NO-GAPS. 
WHEN 12. 
gs_upload-vgw01         = ls_excel-value. 
CONDENSE gs_upload-vgw01 NO-GAPS. 
WHEN 13. 
gs_upload-vge01         = ls_excel-value. 
CONDENSE gs_upload-vge01 NO-GAPS. 
WHEN 14. 
gs_upload-vgw02         = ls_excel-value. 
CONDENSE gs_upload-vgw02 NO-GAPS. 
WHEN 15. 
gs_upload-vge02         = ls_excel-value. 
CONDENSE gs_upload-vge02 NO-GAPS. 
WHEN 16. 
gs_upload-vgw03         = ls_excel-value. 
CONDENSE gs_upload-vgw03 NO-GAPS. 
WHEN 17. 
gs_upload-vge03         = ls_excel-value. 
CONDENSE gs_upload-vge03 NO-GAPS. 
WHEN 18. 
gs_upload-vgw04         = ls_excel-value. 
CONDENSE gs_upload-vgw04 NO-GAPS. 
WHEN 19. 
gs_upload-vge04         = ls_excel-value. 
CONDENSE gs_upload-vge04 NO-GAPS. 
WHEN 20. 
gs_upload-vgw05         = ls_excel-value. 
CONDENSE gs_upload-vgw05 NO-GAPS. 
WHEN 21. 
gs_upload-vge05         = ls_excel-value. 
CONDENSE gs_upload-vge05 NO-GAPS. 
ENDCASE. 
AT END OF row. 
lv_tabix = lv_tabix + 1. 
gs_upload-tabix = lv_tabix. 
APPEND gs_upload TO gt_upload. 
CLEAR gs_upload. 
ENDAT. 
CLEAR ls_excel. 
ENDLOOP. 
ENDFORM. 
FORM check_authority. 
DATA: BEGIN OF lt_werks OCCURS 0, 
werks TYPE werks_d, 
END OF lt_werks. 
DATA: lv_msg TYPE STRING. 
IF gt_upload[] IS INITIAL. 
MESSAGE TEXT-E06 TYPE 'S' DISPLAY LIKE 'E'. 
STOP. 
ENDIF. 
LOOP AT gt_upload INTO gs_upload. 
lt_werks-werks = gs_upload-werks. 
COLLECT lt_werks. 
ENDLOOP. 
LOOP AT lt_werks. 
AUTHORITY-CHECK OBJECT 'C_ROUT' 
ID 'ACTVT' DUMMY 
ID 'PLNTY' DUMMY 
ID 'WERKS' FIELD lt_werks-werks 
ID 'STATU' DUMMY 
ID 'VERWE' DUMMY. 
IF sy-subrc NE 0. 
lv_msg = TEXT-E07 && lt_werks-werks && TEXT-E08. 
MESSAGE lv_msg TYPE 'S' DISPLAY LIKE 'E'. 
STOP. 
ENDIF. 
ENDLOOP. 
ENDFORM. 
FORM initial_data. 
DATA: ls_textfield LIKE smp_dyntxt. 
ls_textfield-text      = TEXT-T02. 
ls_textfield-icon_id   = icon_xls. 
ls_textfield-icon_text = TEXT-T01. 
ls_textfield-quickinfo = TEXT-T02. 
sscrfields-functxt_01  = ls_textfield. 
ENDFORM. 
FORM template_download. 
DATA: ls_key TYPE wwwdatatab, 
lv_filename TYPE STRING, 
lv_path     TYPE STRING, 
lv_fullpath TYPE STRING, 
lv_destinat LIKE rlgrap-filename, 
lv_action   TYPE I, 
lv_rc       TYPE I, 
lv_file_name TYPE string. 
CHECK sy-ucomm EQ 'FC01'. 
lv_file_name = c_default_filename. 
CALL METHOD cl_gui_frontend_services=>file_save_dialog 
EXPORTING 
default_file_name    = lv_file_name 
file_filter          = cl_gui_frontend_services=>filetype_excel 
CHANGING 
filename             = lv_filename 
path                 = lv_path 
fullpath             = lv_fullpath 
user_action          = lv_action 
EXCEPTIONS 
cntl_error           = 1 
error_no_gui         = 2 
not_supported_by_gui = 3 
OTHERS               = 4. 
IF sy-subrc <> 0. 
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
ENDIF. 
CHECK lv_action EQ cl_gui_frontend_services=>action_ok. 
ls_key-relid    = 'MI'. 
ls_key-objid    = 'ZPPC001'. 
lv_destinat     = lv_fullpath. 
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT' 
EXPORTING 
key         = ls_key 
destination = lv_destinat 
IMPORTING 
rc          = lv_rc. 
IF lv_rc EQ 0. 
MESSAGE S398(00) WITH TEXT-S01. 
ELSE. 
MESSAGE E398(00) WITH TEXT-E01. 
ENDIF. 
ENDFORM. 
FORM f4_for_file_name. 
DATA: lv_title  TYPE string, 
lt_file   TYPE filetable, 
ls_file   TYPE LINE OF filetable, 
lv_rc     TYPE i, 
lv_filename TYPE string. 
lv_title = TEXT-B01. 
lv_filename = c_default_filename. 
CALL METHOD cl_gui_frontend_services=>file_open_dialog 
EXPORTING 
window_title            = lv_title 
default_extension       = cl_gui_frontend_services=>filetype_excel 
default_filename        = lv_filename 
file_filter             = cl_gui_frontend_services=>filetype_excel 
initial_directory       = 'C:/' 
multiselection          = space 
CHANGING 
file_table              = lt_file 
rc                      = lv_rc 
EXCEPTIONS 
file_open_dialog_failed = 1 
cntl_error              = 2 
error_no_gui            = 3 
not_supported_by_gui    = 4 
OTHERS                  = 5. 
IF sy-subrc <> 0. 
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
ENDIF. 
CHECK sy-subrc = 0. 
READ TABLE lt_file INTO ls_file INDEX 1. 
p_fname = ls_file-filename. 
ENDFORM.

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/18697.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论