*&---------------------------------------------------------------------* *& Report ZBW_P_AG_LOADIXLS *& *&---------------------------------------------------------------------* *&Created by: Artyom Grabarov *&Version: 1.0 *&---------------------------------------------------------------------* *&Comments: *&Программа для загрузки таблицы соответствия реквизитов перевозки и статей доходов *& *&---------------------------------------------------------------------* report zbw_p_ag_loadixls. include zbw_p_ag_loadixls_log. include zbw_p_ag_loadixls_data. * Initialization event. * Create Instance control for container call method c_oi_container_control_creator=>get_container_control importing control = o_control error = o_error. call method o_error->raise_message exporting type = 'E'. * Create generic container linked to container in screen 100 create object obj_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. * Establish connection to GUI Control call method o_control->init_control exporting r3_application_name = 'Excel Document Container' inplace_enabled = 'X' parent = obj_container importing error = o_error. call method o_error->raise_message exporting type = 'E'. * Create Document Proxy call method o_control->get_document_proxy exporting document_type = soi_doctype_excel_sheet importing document_proxy = o_document error = o_error. call method o_error->raise_message exporting type = 'E'. * Start-of-selection. * Call dialog to navigate to file call method cl_gui_frontend_services=>file_open_dialog exporting default_extension = '.xls' file_filter = '*.xls' initial_directory = 'C:\' changing file_table = t_files rc = v_rcode user_action = v_action exceptions file_open_dialog_failed = 1 cntl_error = 2 error_no_gui = 3 others = 4. * Only continue if User hasn't cancelled * Determine filename to open Excel document read table t_files index 1 into s_files. else. * Open Spreadsheet in SAPWORKDIR call method o_document->open_document exporting open_inplace = 'X' document_title = 'Excel' document_url = v_doc_name no_flush = '' importing error = o_error. call method o_error->raise_message exporting type = 'E'. * Open Spreadsheet interface call method o_document->get_spreadsheet_interface exporting no_flush = '' importing sheet_interface = o_spreadsheet error = o_error. call method o_error->raise_message exporting type = 'E'. * Set selection for 1000 rows call method o_spreadsheet->set_selection exporting top = 1 left = 1 rows = '7900' columns = '25'. * Define Range in spreadsheet call method o_spreadsheet->insert_range exporting name = 'Test' rows = '7900' columns = '25' no_flush = '' importing error = o_error. call method o_error->raise_message exporting type = 'E'. s_ranges-name = 'Test'. s_ranges-rows = '7900'. s_ranges-columns = '25'. * Get data call method o_spreadsheet->get_ranges_data exporting all = '' no_flush = '' importing contents = t_data error = o_error changing call method o_error->raise_message exporting type = 'E'. * Close document * Close the document call method o_document->close_document exporting do_save = '' no_flush = '' importing has_changed = v_changed error = o_error. call method o_error->raise_message exporting type = 'E'. * Clear Document Resources call method o_document->release_document exporting no_flush = '' importing error = o_error. call method o_error->raise_message exporting type = 'E'. * Clear table of file names o_control. * Process the data before write in to bd table at new row. APPEND i_data. CLEAR i_data. "i_data-Z_INC_ARTICLE_ID = s_data-VALUE. i_data-Z_REVENUES_GROUP = s_data-VALUE. "i_data-Z_INCOME_SUB1 = s_data-VALUE. "i_data-Z_INCOME_SUB2 = s_data-VALUE. " i_data-Z_INCOME_ITEM = s_data-VALUE. SELECT SINGLE /BIC/TEXT_AN1 /BIC/TEXT_AN2 /BIC/TEXT_AN3 /BIC/TEXT_AN4 FROM /BI0/MPROFIT_CTR BYPASSING BUFFER INTO (temp_txt_string1, temp_txt_string2, temp_txt_string3, temp_txt_string4) WHERE PROFIT_CTR = i_data-Z_REVENUES_GROUP and DATETO >= sy-datum AND OBJVERS eq 'A' AND CO_AREA EQ '1'. CONCATENATE temp_txt_string1 temp_txt_string2 temp_txt_string3 temp_txt_string4 into i_data-Z_INCOME_ITEM. i_data-Z_MZHS = 'X'. i_data-Z_PV = 'X'. i_data-Z_PK = 'X'. i_data-Z_LT = 'X'. i_data-Z_GKR = 'X'. i_data-Z_MESSAGE_CODE = s_data-VALUE. i_data-Z_PAYMENT_CODE = s_data-VALUE. i_data-Z_PAYER_CODE = s_data-VALUE. i_data-Z_SIGN_CORRECT = s_data-VALUE. i_data-Z_PLACE_AND_FORM = s_data-VALUE. i_data-Z_TYPE_OF_MSG = s_data-VALUE. i_data-Z_PROPERTY_SIGN = s_data-VALUE. i_data-Z_SIGN_OF_IT = s_data-VALUE. i_data-Z_SIGN_OF_V_OR_C = s_data-VALUE. i_data-Z_KIND_OF_WAGON = s_data-VALUE. i_data-Z_SHIPPING_CODE = s_data-VALUE. i_data-Z_CARCO_CODE = s_data-VALUE. i_data-Z_EMPTY_COL = s_data-VALUE. i_data-Z_TARIFF_COMP_ID = s_data-VALUE. i_data-Z_TARIFF_COMP_SU = s_data-VALUE. " write:(10) s_data-value. * записываем данные в БД ELSE. WRITE 'Ошибка при записи данных в таблицу. Обратитесь к ABAP разработчику для решения данной проблемы'.
*&---------------------------------------------------------------------* *& Include ZBW_P_AG_LOADIXLS_DATA *&---------------------------------------------------------------------* * Define Screen Container o_control type ref to i_oi_container_control, o_document type ref to i_oi_document_proxy, o_spreadsheet type ref to i_oi_spreadsheet. * Data declarations. s_files type file_table, v_doc_name type char256, v_changed type int4, v_rcode type int4, t_ranges type soi_range_list, s_ranges type soi_range_item, t_data type soi_generic_table, s_data type soi_generic_item, i_data TYPE TABLE OF ZBW_TABL_CORRTAB WITH HEADER LINE, " ZBW_TABL_CORRTAB this is table BD for write data v_action type int4. temp_txt_string2 TYPE string, temp_txt_string3 TYPE string, temp_txt_string4 TYPE string.
Include zbw_p_ag_loadixls_log содержит только лог изменений и не нужен для функционирования программы.