屏幕以及字段定义
DATA: go_container TYPE REF TO cl_gui_custom_container.
DATA: lv_subrc TYPE i,
gv_action TYPE int4,
lt_filetab TYPE filetable,
ls_filetab TYPE file_table.
DATA: gv_exit TYPE flag .
DATA: lt_input TYPE TABLE OF alsmex_tabline,
lt_matnr TYPE zqm_t_aut_check, "需要显示的结构
lt_output TYPE zqm_t_aut_check,"需要显示的结构
ls_matnr TYPE zqm_aut_check,"需要显示的结构
lv_filename TYPE char256,
lt_ranges TYPE soi_range_list,
ls_ranges TYPE soi_range_item,
lt_soi TYPE soi_generic_table,
ls_soi LIKE LINE OF lt_soi,
lv_return TYPE soi_ret_string,
lv_runid TYPE int4 VALUE 1,
lv_vorname(30) TYPE c,
lv_nachname(30) TYPE c,
lv_counter TYPE i,
lv_cnt TYPE i,
gv_file_param_columns TYPE i VALUE 9,
gv_file_param_rows TYPE i VALUE 1746,
gt_fcat1 TYPE lvc_t_fcat,
gs_fcat TYPE lvc_s_fcat,
gs_layout TYPE lvc_s_layo.
DATA:
go_error TYPE REF TO i_oi_error,
go_control TYPE REF TO i_oi_container_control,
go_document TYPE REF TO i_oi_document_proxy,
go_spreadsheet TYPE REF TO i_oi_spreadsheet.
**Selection screen with file name input--------------------------屏幕输入----------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-t02.
PARAMETERS: p_file TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-t01.
PARAMETERS:
iv_vkorg TYPE vkorg,
iv_vtweg TYPE vtweg,
iv_spart TYPE spart,
iv_auart TYPE auart,
iv_kunnr TYPE kunnr,
iv_werks TYPE werks_d.
SELECTION-SCREEN END OF BLOCK b2.
*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
PERFORM init.
*----------------------------------------------------------------------*
* *Open file selection
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM file_open .
*Upload process after selection
START-OF-SELECTION.
PERFORM upload_excel_file.
PERFORM get_data.
IF lt_OUTPUT IS NOT INITIAL.
PERFORM show_alv.
ELSE.
MESSAGE text-t03 TYPE 'S' DISPLAY LIKE 'E'..
* LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0.
ENDIF.
END-OF-SELECTION.*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
PERFORM init.
*----------------------------------------------------------------------*
* *Open file selection
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM file_open .
*Upload process after selection
START-OF-SELECTION.
PERFORM upload_excel_file.
PERFORM get_data.
IF lt_OUTPUT IS NOT INITIAL.
PERFORM show_alv.
ELSE.
MESSAGE text-t03 TYPE 'S' DISPLAY LIKE 'E'..
* LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0.
ENDIF.
END-OF-SELECTION.
PERFORM init.
FORM init .
CLASS c_oi_errors DEFINITION LOAD.
* Create Instance control for container
c_oi_container_control_creator=>get_container_control(
IMPORTING
control = go_control " Container-Control
error = go_error " Fehler-Objekt
).
IF go_error->has_failed IS NOT INITIAL.
go_error->raise_message(
EXPORTING
type = 'E' " Message-Typ ('A','E','W','I','S')
EXCEPTIONS
message_raised = 1
flush_failed = 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.
ENDIF.
* Create generic container linked to container in screen 100
CREATE OBJECT go_container
EXPORTING
container_name = 'CONTAINER'
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
"Error
ENDIF.
* Establish connection to GUI Control
go_control->init_control(
EXPORTING
r3_application_name = 'Excel Document Container'
inplace_enabled = 'X'
parent = go_container
IMPORTING
error = go_error
).
IF go_error->has_failed IS NOT INITIAL.
go_error->raise_message(
EXPORTING
type = 'E' " Message-Typ ('A','E','W','I','S')
EXCEPTIONS
message_raised = 1
flush_failed = 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.
ENDIF.
* Create Document Proxy
go_control->get_document_proxy(
EXPORTING
document_type = soi_doctype_excel_sheet
IMPORTING
document_proxy = go_document
error = go_error
).
IF go_error->has_failed IS NOT INITIAL.
go_error->raise_message(
EXPORTING
type = 'E' " Message-Typ ('A','E','W','I','S')
EXCEPTIONS
message_raised = 1
flush_failed = 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.
ENDIF.
ENDFORM.
PERFORM file_open .
* &1 - Windows title
* &2 - Filename chosen
cl_gui_frontend_services=>file_open_dialog(
EXPORTING
window_title = 'UploadData'
* default_filename = 'C:\test.txt'
initial_directory = 'C:\'
file_filter = 'Excel(*.XLS,*.XLSX)|*.XLS;*.XLSX' "'Excel(*.XLS)|*.XLS'
CHANGING
file_table = lt_filetab
rc = lv_subrc
user_action = gv_action
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5
).
IF lv_subrc IS INITIAL.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE:/ 'Nothing uploaded.'.
EXIT.
ENDIF.
READ TABLE lt_filetab INTO ls_filetab INDEX 1.
CHECK sy-subrc EQ 0.
p_file = ls_filetab-filename.
PERFORM upload_excel_file.
FORM upload_excel_file .
IF p_file IS INITIAL.
gv_exit = 'X'.
RETURN.
ENDIF.
CONCATENATE 'FILE://' p_file INTO lv_filename.
CALL METHOD go_document->open_document(
EXPORTING
* open_inplace = 'X'
document_title = 'Excel'
document_url = lv_filename
no_flush = ''
IMPORTING
error = go_error
).
IF go_error->has_failed IS NOT INITIAL.
go_error->raise_message(
EXPORTING
type = 'E'
).
ENDIF.
go_document->get_spreadsheet_interface(
EXPORTING no_flush = ''
IMPORTING sheet_interface = go_spreadsheet
error = go_error
).
go_spreadsheet->set_selection(
EXPORTING
left = '1'
top = '2'
rows = gv_file_param_rows
columns = gv_file_param_columns
* no_flush = ' '
IMPORTING
error = go_error
).
IF go_error->has_failed IS NOT INITIAL.
go_error->raise_message(
EXPORTING
type = 'E'
).
ENDIF.
go_spreadsheet->insert_range(
EXPORTING name = 'Test'
rows = gv_file_param_rows
columns = gv_file_param_columns
no_flush = ''
IMPORTING error = go_error
).
ls_ranges-name = 'Test'.
ls_ranges-rows = gv_file_param_rows.
ls_ranges-columns = gv_file_param_columns.
APPEND ls_ranges TO lt_ranges.
go_spreadsheet->get_ranges_data(
IMPORTING
contents = lt_soi "Contents of the tables
error = go_error "errors
retcode = lv_return "text of the error
CHANGING
ranges = lt_ranges "Specified ranges
).
IF go_error->has_failed IS NOT INITIAL.
go_error->raise_message(
EXPORTING
type = 'E'
).
ENDIF.
IF lv_return <> 'OK'.
RETURN.
ENDIF.
CALL METHOD go_document->close_document.
CALL METHOD go_document->release_document.
CLEAR: ls_matnr,lv_cnt,lv_counter.
lv_cnt = 1.
lv_counter = 1.
LOOP AT lt_soi INTO ls_soi.
IF ls_soi-row = lv_cnt AND ls_soi-column = lv_counter.
IF lv_counter = 1.
ls_matnr-matnr = ls_soi-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = ls_matnr-matnr
IMPORTING
output = ls_matnr-matnr.
lv_counter = 3.
ELSEIF lv_counter = 3.
ls_matnr-req_qty = ls_soi-value.
APPEND ls_matnr TO lt_matnr.
lv_counter = 1.
lv_cnt = lv_cnt + 1.
ENDIF.
IF ls_matnr-matnr IS INITIAL.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
PERFORM get_data.
*----------------------------------------------------------------------*
FORM get_data .
DATA: lo_qm TYPE REF TO zcl_qm_returnable_verifier.
TRY.
CREATE OBJECT lo_qm
EXPORTING
it_materials = lt_matnr
iv_vkorg = iv_vkorg
iv_vtweg = iv_vtweg
iv_spart = iv_spart
iv_auart = iv_auart
iv_kunnr = iv_kunnr
iv_werks = iv_werks.
ENDTRY.
lo_qm->start_process(
IMPORTING
et_materials = lt_output
).
ENDFORM.
PERFORM show_alv.
FORM show_alv .
PERFORM build_fieldcat.
PERFORM build_layout.
* PERFORM build_events.
PERFORM build_alv.
ENDFORM.
PERFORM build_fieldcat.
FORM build_fieldcat .
DEFINE %%append_fieldcat .
CLEAR gs_fcat .
gs_fcat-col_pos = &3."LINE
gs_fcat-fieldname = &1."DISPLAY FIELD
* gs_fcat-outputlen = &2." outputlen
gs_fcat-scrtext_m = &2. "middle key word
* gs_fcat-key = &4."SET KEY
APPEND gs_fcat TO gt_fcat1.
END-OF-DEFINITION.
%%append_fieldcat:
'MATNR' 'Material Number' '1',
'REQ_QTY' 'Quantity' '2',
'SALES_UNIT' 'Sales Unit' '3',
'MTART' 'Material Type' '4',
..............................
ENDFORM.
PERFORM build_layout.
FORM build_layout .
gs_layout-cwidth_opt = 'X'.
gs_layout-zebra = 'X'.
* gs_layout2-sel_mode = 'A'.
* gs_layout-box_fname = 'SEL'.
* gs_layout2-detail_initial_lines = 'X'.
* gs_layout2-window_titlebar =
* gs_layout2-confirmation_prompt = 'X'.
gs_layout-stylefname = 'field_style'.
* gs_layout2-edit = 'X'.
ENDFORM.
PERFORM build_alv.
FORM build_alv .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'FRM_SET_STATUS'
i_callback_user_command = 'FRM_USER_COMMAND'
* I_GRID_SETTINGS =
is_layout_lvc = gs_layout
* IT_FIELDCAT_LVC = gt_fieldcat1
it_fieldcat_lvc = gt_fcat1[]
* it_excluding = lt_extab
i_save = 'A'
* IS_VARIANT =
* IT_EVENTS = gt_events
* IT_EVENT_EXIT =
TABLES
t_outtab = lt_output
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
FORM frm_set_status USING pt_extab TYPE slis_t_extab.
SET PF-STATUS 'Z_STATUS'.
ENDFORM.
FORM frm_user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
DATA: gv_grid TYPE REF TO cl_gui_alv_grid.
DATA: lt_lines TYPE int4.
" GET BUTTON
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = gv_grid.
CALL METHOD gv_grid->check_changed_data.
"REFRSH
rs_selfield-refresh = 'X'.
ENDFORM. "ALV_USER_COMMAND
复制标准GUI
2.1.1 输入事物代码SE41;
2.1.2 输入标准的SAPLKKBL程序;
然后从用户接口->复制->状态进入,填写目标程序复制
或者从这里进入复制
最后激活。