report z_introspector_excel_demo. *----------------------------------------------------------------------* * CLASS lcl_introspector_demo DEFINITION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_introspector_demo definition. public section. types: begin of ty_flight_list_incl, flightdate type s_date, airportfr type s_fromairp, cityfrom type s_from_cit, airportto type s_toairp, cityto type s_to_city, deptime type s_dep_time, arrtime type s_arr_time, arrdate type s_arrdate, price type s_price_2, curr type s_currcode, curr_iso type s_curr_iso, end of ty_flight_list_incl. types: begin of ty_flight_list, airlineid type s_carr_id, airline type s_carrname, airline_text type tline_t, connectid type s_conn_id. include type ty_flight_list_incl. types: end of ty_flight_list. types: ty_flight_list_t type standard table of ty_flight_list. class-methods: main importing im_from type sairport im_to type sairport im_airline type s_carr_id im_columns type string im_folder type string im_file type string im_use_tstamp type abap_bool im_use_header_record type abap_bool im_point_header_to_ddic type abap_bool im_format_time type abap_bool im_format_date type abap_bool im_author type string im_sheet_name type string im_freeze_header type abap_bool. methods: load_data importing im_from type sairport im_to type sairport im_airline type s_carr_id, load_table_introspection importing im_columns type string optional im_use_header_record type abap_bool default abap_true im_point_header_to_ddic type abap_bool default abap_true im_format_time type abap_bool default abap_true im_format_date type abap_bool default abap_true im_author type string optional im_sheet_name type string optional im_freeze_header type abap_bool default abap_true im_header_color type zcl_bc_table_introspector=>ty_color optional im_string_cell_width type i optional im_points_factor type i optional, download importing im_folder type string im_file type string im_use_tstamp type abap_bool, display. private section. data: table_introspector type ref to zcl_bc_table_introspector, flight_list type ty_flight_list_t. endclass. "lcl_introspector_demo DEFINITION *----------------------------------------------------------------------* * CLASS lcl_introspector_demo IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* class lcl_introspector_demo implementation. method main. *-- local variables data: lo_introspector_demo type ref to lcl_introspector_demo. constants: lc_string_cell_width type i value 40, lc_points_factor type i value 7. create object lo_introspector_demo. call method lo_introspector_demo->load_data( exporting im_from = im_from im_to = im_to im_airline = im_airline ). call method lo_introspector_demo->load_table_introspection( exporting im_columns = im_columns im_use_header_record = im_use_header_record im_point_header_to_ddic = im_point_header_to_ddic im_format_time = im_format_time im_format_date = im_format_date im_author = im_author im_sheet_name = im_sheet_name im_freeze_header = im_freeze_header im_header_color = zcl_bc_table_introspector=>e_color-standard im_string_cell_width = lc_string_cell_width im_points_factor = lc_points_factor ). call method lo_introspector_demo->download( exporting im_folder = im_folder im_file = im_file im_use_tstamp = im_use_tstamp ). call method lo_introspector_demo->display( ). endmethod. "main method load_data. *-- internal table defintion data: lt_flight_list_src type standard table of bapisfldat. *-- structure defintion data: ls_from_airport type bapisfldst, ls_to_airport type bapisfldst, ls_header type thead. *-- field symbols field-symbols: like line of lt_flight_list_src, like line of flight_list. *-- populate airport structures ls_from_airport-airportid = im_from. ls_to_airport-airportid = im_to. *-- use standard BAPI to load flight data call function 'BAPI_FLIGHT_GETLIST' exporting destination_from = ls_from_airport destination_to = ls_to_airport airline = im_airline tables flight_list = lt_flight_list_src. *-- prepare text object metadata ls_header-tdobject = 'ZCARRIER'. ls_header-tdid = 'ZLTX'. ls_header-tdspras = sy-langu. *-- transfer source flight list and text object to destination flight list loop at lt_flight_list_src assigning . append initial line to flight_list assigning . move-corresponding to . ls_header-tdname = -airlineid. call function 'READ_TEXT' exporting id = ls_header-tdid language = ls_header-tdspras name = ls_header-tdname object = ls_header-tdobject tables lines = -airline_text exceptions id = 1 language = 2 name = 3 not_found = 4 object = 5 reference_check = 6 wrong_access_to_archive = 7 others = 8. endloop. endmethod. "load_data method load_table_introspection. *-- load introspection from internal table try. call method zcl_bc_table_introspector=>factory_using_table exporting im_table = flight_list im_columns = im_columns im_use_header_record = im_use_header_record im_point_header_to_ddic = im_point_header_to_ddic im_format_time = im_format_time im_format_date = im_format_date im_author = im_author im_sheet_name = im_sheet_name im_freeze_header = im_freeze_header im_header_color = im_header_color im_string_cell_width = im_string_cell_width im_points_factor = im_points_factor importing ex_table_introspector = table_introspector. catch zcx_bc_table_introspector. endtry. endmethod. "load_table_introspection method download. *-- type definition types: ty_xml_t type zcl_bc_table_introspector=>ty_xml_t. *-- internal table defintion data: lt_xml_payload type ty_xml_t. *-- local variables data: lv_file type string, lv_name_part type string, lv_extension_part type string, lv_match_count type i, lv_tstamp type timestamp, lv_date type d, lv_time type t. move: im_file to lv_file. *-- prepare absolute path if im_use_tstamp eq abap_true. get time stamp field lv_tstamp. convert time stamp lv_tstamp time zone sy-zonlo into date lv_date time lv_time. if lv_file ns '.'. concatenate lv_file '_' lv_date into lv_file. else. find first occurrence of regex '^(.*)(\.[^.]*)$' in lv_file submatches lv_name_part lv_extension_part. concatenate lv_name_part '_' lv_date lv_time lv_extension_part into lv_file. endif. endif. find first occurrence of regex '^.*\\$' in im_folder match count lv_match_count. if lv_match_count ne 1. concatenate im_folder '\' lv_file into lv_file. else. concatenate im_folder lv_file into lv_file. endif. *-- load xml payload try. call method table_introspector->get_xml_rendition( importing ex_xml_table = lt_xml_payload ). catch zcx_bc_table_introspector. endtry. *-- download to local file call method cl_gui_frontend_services=>gui_download exporting filename = lv_file filetype = 'BIN' append = ' ' changing data_tab = lt_xml_payload exceptions file_write_error = 1 no_batch = 2 gui_refuse_filetransfer = 3 invalid_type = 4 no_authority = 5 unknown_error = 6 header_not_allowed = 7 separator_not_allowed = 8 filesize_not_allowed = 9 header_too_long = 10 dp_error_create = 11 dp_error_send = 12 dp_error_write = 13 unknown_dp_error = 14 access_denied = 15 dp_out_of_memory = 16 disk_full = 17 dp_timeout = 18 file_not_found = 19 dataprovider_exception = 20 control_flush_error = 21 not_supported_by_gui = 22 error_no_gui = 23 others = 24. endmethod. "download method display. *-- local variables data: lo_alv type ref to cl_salv_table. *-- load table payload try. table_introspector->get_alv_rendition( importing ex_alv_table = lo_alv ). catch zcx_bc_table_introspector. endtry. *-- display alv try. call method lo_alv->display( ). catch cx_salv_msg. endtry. endmethod. "display endclass. "lcl_introspector_demo IMPLEMENTATION *-- selection screen selection-screen begin of block blk_main with frame title text-s01. parameters: p_from type sairport matchcode object h_sairport, p_to type sairport matchcode object h_sairport, p_airlin type s_carr_id. selection-screen end of block blk_main. selection-screen begin of block blk_options with frame title text-s02. parameters: p_cols type string default 'airlineid airline airline_text connectid flightdate airportfr cityfrom airporto cityto price' no-display, p_path type string lower case obligatory default 'c:\temp', p_file1 type string lower case obligatory default 'flight_list.xml' , p_author type string lower case, p_sheet type string lower case, p_tstamp as checkbox default 'X', p_header as checkbox default 'X', p_ddic as checkbox default 'X', p_fmtime as checkbox default 'X', p_fmdate as checkbox default 'X', p_freeze as checkbox default 'X'. selection-screen end of block blk_options. *-- start of selection start-of-selection. lcl_introspector_demo=>main( exporting im_from = p_from im_to = p_to im_airline = p_airlin im_columns = p_cols im_folder = p_path im_file = p_file1 im_use_tstamp = p_tstamp im_use_header_record = p_header im_point_header_to_ddic = p_ddic im_format_time = p_fmtime im_format_date = p_fmdate im_author = p_author im_sheet_name = p_sheet im_freeze_header = p_freeze ).