An example of uploading an Excel import

Source: Internet
Author: User

 ReportZTEST_UPEXCEL.data:gt_table TypeTABLE  ofsflight, gs_table like Line of gt_table.DATA: Lt_excelTYPE TABLE  ofZstabline.DATALs_excel like  Line  ofLt_excel.Field-symbols:<fs>.CONSTANTS: Gc_begin_rowTYPEI VALUE1,"Beginning row of Excel fileGc_begin_colTYPEI VALUE1,           "Beginning column of Excel fileGc_end_rowTYPEI VALUE999,           "ending row of Excel fileGc_end_colTYPEI VALUE999."ending column of Excel filePARAMETERS: P_file likeRlgrap-filename."define a variable that holds the path name of the uploaded fileinitialization.at Selection-screen onvalue-request  forP_file."This is only used on this side of the batch.  PERFORMSub_findUSINGP_file.start-of-selection. Pager FUNCTION 'zalsm_excel_to_internal_table'    Exportingfilename=p_file I_begin_col=1"Gc_begin_row 'I_begin_row =1"Gc_begin_colI_end_col =999"Gc_end_rowI_end_row =999"Gc_end_col    TABLESIntern=Lt_excel*EXCEPTIONS*inconsistent_parameters = 1*Upload_ole = 2*OTHERS = 3            . IFSY-SUBRC <>0.*Implement suitable error handling here  ENDIF. LOOP  atLt_excel intoLs_excel. ASSIGN COMPONENTLs_excel-col of STRUCTUREGs_table to <fs>."Assign fields in workspace gs_tab to field symbols, and fields in Workspace gs_tab depend on the columns in the inner table Ls_excel-col    CondenseLs_excel-value."Remove Spaces<fs> = ls_excel-value.                                    At end of row. "If this is the last line, save the workspace gs_tab to the inner table Gt_tab      "Gs_tab-row = Ls_excel-row.      APPENDGs_table togt_table. CLEAR: Gs_table. ENDAT. Endloop. INSERTSflight from TABLEgt_table accepting DUPLICATE KEYS. IFSY-SUBRC =0. COMMIT  Work. MESSAGE 'Maintenance Success'Type'S'. ENDIF.*&---------------------------------------------------------------------**& Form Sub_find*&---------------------------------------------------------------------**text*----------------------------------------------------------------------**-->p_p_file Text*----------------------------------------------------------------------*FORMSub_findUSINGP_p_file.*data:ld_default_extension TYPE STRING VALUE ' CSV '.  DATA: Lt_file_tabTYPEFILETABLE. DATA: Ls_file_lineTYPEfile_table. DATA: LD_RCTYPEI, Lw_titleTYPE STRING, Lw_filterTYPE STRING.*assigning values to variablesLw_title ='Select File'. Lw_filter='Excel file |*.xl;*.xls;*.xlsx|'. Pager METHODCl_gui_frontend_services=>File_open_dialogExportingWindow_title=Lw_title File_filter=Lw_filter initial_directory='c \ ' changing file_table = Lt_file_tab RC = LD_RC EXCEPTIONS file_open_dial og_failed = 1 Cntl_error = 2 Error_no_gui = 3 Not_supported_by_gui = 4 othe  RS = 5.    IF SY-SUBRC <> 0.  MESSAGE ID sy-msgid TYPE sy-msgty number Sy-msgno with Sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.    ELSE.    CHECK LD_RC = 1.    READ TABLE lt_file_tab into Ls_file_line INDEX 1.    CHECK SY-SUBRC = 0.  MOVE Ls_file_line-filename to P_file.  ENDIF.                    "F4_for_filesendform. "Sub_find

An example of uploading an Excel import

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.