Have modified the upload program to make it similar to the recent download program.
*&---------------------------------------------------------------------**& Report ZUPLOAD*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*REPORT ZUPLOAD MESSAGE-ID zx_message.*----------------------------------------------------------------------** CLASS upload DEFINITION*----------------------------------------------------------------------***----------------------------------------------------------------------*CLASS upload DEFINITION.PUBLIC SECTION.CLASS-METHODS open_file.METHODS start.METHODS end.METHODS free_log.METHODS display_output.METHODS display_log.PRIVATE SECTION.CONSTANTS c_max_ranges TYPE i VALUE 100.CONSTANTS c_seperator TYPE abap_char1 VALUE cl_abap_char_utilities=>horizontal_tab.DATA upload_file_tab TYPE REF TO data.DATA upload_file_row TYPE REF TO data.DATA t_tab_file TYPE TABLE OF string.DATA o_struc_type TYPE REF TO cl_abap_structdescr.DATA s_log TYPE bal_s_log.DATA log_handle TYPE balloghndl.DATA t_log_handle TYPE bal_t_logh.DATA o_ccont_display TYPE REF TO cl_gui_custom_container.DATA o_ccont_log TYPE REF TO cl_gui_custom_container.DATA dummy.DATA t_filecontent TYPE string_table.METHODS convert_file2struc IMPORTING i_header TYPE booleani_separator TYPE c.METHODS create_table_and_row.METHODS read_file IMPORTING i_file TYPE string.METHODS open_log.METHODS add_msg.ENDCLASS. "upload DEFINITION
DATA o_upload TYPE REF TO upload.DATA s_t001 TYPE t001.*--------------------------------------------------------------------** File LocationSELECTION-SCREEN BEGIN OF BLOCK file WITH FRAME TITLE text-f01.PARAMETERS:p_file TYPE rlgrap-filename OBLIGATORY,p_header AS CHECKBOX DEFAULT abap_true.SELECTION-SCREEN END OF BLOCK file.*--------------------------------------------------------------------** Material selectionSELECTION-SCREEN BEGIN OF BLOCK bukrs WITH FRAME TITLE text-001.*--- company optionsSELECT-OPTIONS s_bukrs FOR s_t001-bukrs.SELECTION-SCREEN END OF BLOCK bukrs.*--------------------------------------------------------------------** DefaultsSELECTION-SCREEN BEGIN OF BLOCK intr WITH FRAME TITLE text-t03.PARAMETERS:p_struc TYPE strukname DEFAULT 'T001'.SELECTION-SCREEN END OF BLOCK intr.*--------------------------------------------------------------------** F4AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.upload=>open_file( ).*--------------------------------------------------------------------*START-OF-SELECTION.CREATE OBJECT o_upload.o_upload->start( ).*--------------------------------------------------------------------*END-OF-SELECTION.o_upload->end( ).CALL SCREEN 0100.*----------------------------------------------------------------------** CLASS upload IMPLEMENTATION*----------------------------------------------------------------------***----------------------------------------------------------------------*CLASS upload IMPLEMENTATION.METHOD open_file.DATA:l_t_file_table TYPE TABLE OF file_table,l_s_file_table TYPE file_table.DATA l_subrc TYPE i.CALL METHOD cl_gui_frontend_services=>file_open_dialogCHANGINGfile_table = l_t_file_tablerc = l_subrcEXCEPTIONSfile_open_dialog_failed = 1cntl_error = 2error_no_gui = 3not_supported_by_gui = 4OTHERS = 5.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.READ TABLE l_t_file_table INTO l_s_file_table INDEX 1.p_file = l_s_file_table-filename.ENDMETHOD. "open_file
METHOD start.DATA l_file TYPE string.l_file = p_file.open_log( ).create_table_and_row( ).read_file( i_file = l_file ).convert_file2struc( i_header = p_headeri_separator = c_seperator ).ENDMETHOD. "start
METHOD create_table_and_row.DATA l_type TYPE string.DATA lo_type TYPE REF TO cl_abap_typedescr.DATA lo_tabletype TYPE REF TO cl_abap_tabledescr.l_type = p_struc.CALL METHOD cl_abap_structdescr=>describe_by_nameEXPORTINGp_name = l_typeRECEIVINGp_descr_ref = lo_typeEXCEPTIONStype_not_found = 1OTHERS = 2.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.o_struc_type ?= lo_type.CREATE DATA upload_file_row TYPE HANDLE o_struc_type.TRY.CALL METHOD cl_abap_tabledescr=>createEXPORTINGp_line_type = o_struc_type* P_TABLE_KIND = TABLEKIND_STD* P_UNIQUE = ABAP_FALSE* P_KEY =* P_KEY_KIND = KEYDEFKIND_DEFAULTRECEIVINGp_result = lo_tabletype.CATCH cx_sy_table_creation .ENDTRY.CREATE DATA upload_file_tab TYPE HANDLE lo_tabletype.* Structure mapped successfullyMESSAGE s181 INTO dummy.add_msg( ).ENDMETHOD. "create_table_and_row
METHOD convert_file2struc.DATA:l_struc TYPE REF TO data,l_o_datadescr TYPE REF TO cl_abap_datadescr,l_o_tabledescr TYPE REF TO cl_abap_tabledescr,l_t_fields TYPE string_table,l_s_fields TYPE string.FIELD-SYMBOLS:<l_filecontent> TYPE ANY,<l_field> TYPE ANY,<l_row> TYPE ANY,<l_struc_content> TYPE table.ASSIGN upload_file_row->* TO <l_row>.ASSIGN upload_file_tab->* TO <l_struc_content>.LOOP AT t_filecontent ASSIGNING <l_filecontent>.IF i_separator IS INITIAL. " File is same as structure<l_row> = <l_filecontent>.ELSE.*---split based on the separatorSPLIT <l_filecontent> AT i_separator INTO TABLE l_t_fields.LOOP AT l_t_fields INTO l_s_fields.ASSIGN COMPONENT sy-tabix OF STRUCTURE <l_row> TO <l_field>.<l_field> = l_s_fields.ENDLOOP.ENDIF.APPEND <l_row> TO <l_struc_content>.ENDLOOP.ENDMETHOD. "convert_file2struc
METHOD end.ENDMETHOD. "end
METHOD open_log.* create a logs_log-extnumber = 'Application Log in Subscreen'(001).CALL FUNCTION 'BAL_LOG_CREATE'EXPORTINGi_s_log = s_logIMPORTINGe_log_handle = log_handleEXCEPTIONSOTHERS = 1.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.INSERT log_handle INTO TABLE t_log_handle.* Log opened successfullyMESSAGE s180 INTO dummy.add_msg( ).ENDMETHOD. "open_log
METHOD add_msg.DATA:l_s_msg TYPE bal_s_msg.* define data of message for Application Logl_s_msg-msgty = sy-msgty.l_s_msg-msgid = sy-msgid.l_s_msg-msgno = sy-msgno.l_s_msg-msgv1 = sy-msgv1.l_s_msg-msgv2 = sy-msgv2.l_s_msg-msgv3 = sy-msgv3.l_s_msg-msgv4 = sy-msgv4.* add this message to log fileCALL FUNCTION 'BAL_LOG_MSG_ADD'EXPORTINGi_log_handle = log_handlei_s_msg = l_s_msgEXCEPTIONSOTHERS = 1.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.ENDMETHOD. "add_msg
METHOD free_log.* free all data (this must NOT be forgotten !)CALL FUNCTION 'BAL_DSP_OUTPUT_FREE'EXCEPTIONSOTHERS = 1.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.ENDMETHOD. "free_log
METHOD display_output.DATA:l_r_table TYPE REF TO cl_salv_table,* l_r_event_handler TYPE REF TO l_cl_event_handler,l_r_events TYPE REF TO cl_salv_events_table,l_t_salv_t_int4_column TYPE salv_t_int4_column,l_s_salv_t_int4_column TYPE LINE OF salv_t_int4_column.FIELD-SYMBOLS <l_upload_file_tab> TYPE table.ASSIGN upload_file_tab->* TO <l_upload_file_tab>.*--------------------------------------------------------------------*IF o_ccont_display IS INITIAL.* Create holder containerCREATE OBJECT o_ccont_displayEXPORTING* PARENT =container_name = 'CCONTROL_0101'* STYLE =* LIFETIME = lifetime_default* REPID =* DYNNR =* NO_AUTODEF_PROGID_DYNNR =EXCEPTIONScntl_error = 1cntl_system_error = 2create_error = 3lifetime_error = 4lifetime_dynpro_dynpro_link = 5OTHERS = 6.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.*--------------------------------------------------------------------** Create AVL tableTRY.cl_salv_table=>factory(EXPORTINGr_container = o_ccont_displayIMPORTINGr_salv_table = l_r_tableCHANGINGt_table = <l_upload_file_tab> ).CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.*--------------------------------------------------------------------** FunctionsDATA:lr_functions TYPE REF TO cl_salv_functions_list.lr_functions = l_r_table->get_functions( ).* lr_functions->set_aggregation_total( abap_true ).lr_functions->set_default( abap_true ).* ColumnsDATA:lr_columns TYPE REF TO cl_salv_columns_table,lr_column TYPE REF TO cl_salv_column.lr_columns = l_r_table->get_columns( ).lr_columns->set_optimize( abap_true ).TRY.CALL METHOD lr_columns->set_exception_columnEXPORTINGvalue = 'TRAFFIC_LIGHT'group = '2'condensed = if_salv_c_bool_sap=>false.CATCH cx_salv_data_error .ENDTRY.TRY.CALL METHOD lr_columns->set_cell_type_columnEXPORTINGvalue = 'CELL_TYPE'.CATCH cx_salv_data_error .ENDTRY.l_r_table->display( ).ENDIF.ENDMETHOD. "get_e1maktm
METHOD display_log.DATA:l_r_table TYPE REF TO cl_salv_table,* l_r_event_handler TYPE REF TO l_cl_event_handler,l_r_events TYPE REF TO cl_salv_events_table,l_t_salv_t_int4_column TYPE salv_t_int4_column,l_s_salv_t_int4_column TYPE LINE OF salv_t_int4_column.DATA ls_display_profile TYPE bal_s_prof.DATA l_control_handle TYPE balcnthndl.FIELD-SYMBOLS <l_upload_file_tab> TYPE table.*--------------------------------------------------------------------** Create holder containerIF o_ccont_log IS INITIAL.CREATE OBJECT o_ccont_logEXPORTING* PARENT =container_name = 'CCONTROL_0102'* STYLE =* LIFETIME = lifetime_default* REPID =* DYNNR =* NO_AUTODEF_PROGID_DYNNR =EXCEPTIONScntl_error = 1cntl_system_error = 2create_error = 3lifetime_error = 4lifetime_dynpro_dynpro_link = 5OTHERS = 6.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.* get a display profile which describes how to display messagesCALL FUNCTION 'BAL_DSP_PROFILE_NO_TREE_GET'IMPORTINGe_s_display_profile = ls_display_profile.ls_display_profile-no_toolbar = 'X'.*--------------------------------------------------------------------** create control to display dataCALL FUNCTION 'BAL_CNTL_CREATE'EXPORTINGi_container = o_ccont_logi_s_display_profile = ls_display_profilei_t_log_handle = t_log_handleIMPORTINGe_control_handle = l_control_handleEXCEPTIONSOTHERS = 1.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.ENDIF.ENDMETHOD. "display_log
METHOD read_file.CALL METHOD cl_gui_frontend_services=>gui_uploadEXPORTINGfilename = i_file* has_field_separator = 'X'CHANGINGdata_tab = t_filecontentEXCEPTIONSfile_open_error = 1file_read_error = 2no_batch = 3gui_refuse_filetransfer = 4invalid_type = 5no_authority = 6unknown_error = 7bad_data_format = 8header_not_allowed = 9separator_not_allowed = 10header_too_long = 11unknown_dp_error = 12access_denied = 13dp_out_of_memory = 14disk_full = 15dp_timeout = 16not_supported_by_gui = 17error_no_gui = 18OTHERS = 19.IF sy-subrc <> 0.MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgnoWITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.ENDIF.ENDMETHOD. "read_file
ENDCLASS. "upload IMPLEMENTATION
*&---------------------------------------------------------------------**& Module status_0100 OUTPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE status_0100 OUTPUT.* set status and titleSET PF-STATUS 'STATUS'.SET TITLEBAR 'TITLE'.* flush data to frontendCALL METHOD cl_gui_cfw=>flush.ENDMODULE. " status_0100 OUTPUT
*&SPWIZARD: FUNCTION CODES FOR TABSTRIP 'TAB_STRIP'CONSTANTS: BEGIN OF c_tab_strip,tab1 LIKE sy-ucomm VALUE 'TAB_STRIP_FC1',tab2 LIKE sy-ucomm VALUE 'TAB_STRIP_FC2',END OF c_tab_strip.*&SPWIZARD: DATA FOR TABSTRIP 'TAB_STRIP'CONTROLS: tab_strip TYPE TABSTRIP.DATA: BEGIN OF g_tab_strip,subscreen LIKE sy-dynnr,prog LIKE sy-repid VALUE 'Zupload',pressed_tab LIKE sy-ucomm VALUE c_tab_strip-tab1,END OF g_tab_strip.DATA: ok_code LIKE sy-ucomm.*&SPWIZARD: OUTPUT MODULE FOR TS 'TAB_STRIP'. DO NOT CHANGE THIS LINE!*&SPWIZARD: SETS ACTIVE TABMODULE tab_strip_active_tab_set OUTPUT.tab_strip-activetab = g_tab_strip-pressed_tab.CASE g_tab_strip-pressed_tab.WHEN c_tab_strip-tab1.g_tab_strip-subscreen = '0101'.WHEN c_tab_strip-tab2.g_tab_strip-subscreen = '0102'.WHEN OTHERS.*&SPWIZARD: DO NOTHINGENDCASE.ENDMODULE. "TAB_STRIP_ACTIVE_TAB_SET OUTPUT
*&SPWIZARD: INPUT MODULE FOR TS 'TAB_STRIP'. DO NOT CHANGE THIS LINE!*&SPWIZARD: GETS ACTIVE TABMODULE tab_strip_active_tab_get INPUT.ok_code = sy-ucomm.CASE ok_code.WHEN c_tab_strip-tab1.g_tab_strip-pressed_tab = c_tab_strip-tab1.WHEN c_tab_strip-tab2.g_tab_strip-pressed_tab = c_tab_strip-tab2.WHEN OTHERS.*&SPWIZARD: DO NOTHINGENDCASE.ENDMODULE. "TAB_STRIP_ACTIVE_TAB_GET INPUT
*&---------------------------------------------------------------------**& Module user_command_0100 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_0100 INPUT.CASE ok_code.* leave this screenWHEN 'ABBR' OR 'BACK' OR 'BEEN'.LEAVE TO SCREEN 0.WHEN OTHERS.ENDCASE.* Delete log profileo_upload->free_log( ).* call dispatch method of control framworkCALL METHOD cl_gui_cfw=>dispatch.ENDMODULE. " user_command_0100 INPUT
*&---------------------------------------------------------------------**& Module display_output OUTPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE display_output OUTPUT.o_upload->display_output( ).ENDMODULE. " display_output OUTPUT
*&---------------------------------------------------------------------**& Module display_log OUTPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE display_log OUTPUT.o_upload->display_log( ).ENDMODULE. " display_log OUTPUT
No comments:
Post a Comment