0% found this document useful (0 votes)
48 views

Data Begin of Occurs Type Type Type End of Data Type Occurs With Header Line Parameters Type at Selection-Screen On Value-Request For Call Function

This document contains code for uploading data from an Excel file into an internal table and downloading data from an internal table to an Excel file. It defines internal tables to hold employee data from Excel and for export to Excel. On upload, it reads the Excel file into an internal table and parses the data into fields. On download, it selects employee data from the database, structures it in an internal table for Excel, and calls a function to export the data to a new Excel file.

Uploaded by

Raj Ankit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Data Begin of Occurs Type Type Type End of Data Type Occurs With Header Line Parameters Type at Selection-Screen On Value-Request For Call Function

This document contains code for uploading data from an Excel file into an internal table and downloading data from an internal table to an Excel file. It defines internal tables to hold employee data from Excel and for export to Excel. On upload, it reads the Excel file into an internal table and parses the data into fields. On download, it selects employee data from the database, structures it in an internal table for Excel, and calls a function to export the data to a new Excel file.

Uploaded by

Raj Ankit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

*&---------------------------------------------------------------------* *& Report ZAN_EXCEL_UPLOAD *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZAN_EXCEL_UPLOAD.

DATA: BEGIN OF it_emp OCCURS 0, emp_id type ZAN_EMPLOYEE-emp_id, emp_name TYPE zan_employee-emp_name, emp_add TYPE zan_employee-emp_add, END OF it_emp. DATA: it_excel TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE. PARAMETERS: p_file TYPE rlgrap-filename. AT SELECTION-SCREEN on VALUE-REQUEST FOR p_file. CALL FUNCTION 'F4_FILENAME' * EXPORTING * PROGRAM_NAME = SYST-CPROG * DYNPRO_NUMBER = SYST-DYNNR * FIELD_NAME = ' ' IMPORTING FILE_NAME = p_file . START-OF-SELECTION. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING FILENAME = p_file I_BEGIN_COL = 1 I_BEGIN_ROW = 1 I_END_COL = 3 I_END_ROW = 65300 TABLES INTERN = it_excel EXCEPTIONS INCONSISTENT_PARAMETERS = 1 UPLOAD_OLE = 2 OTHERS = 3 . IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF.

PERFORM upload_internal_table. end-of-SELECTION. LOOP AT IT_EMP. WRITE:/ IT_EMP-EMP_ID, IT_EMP-EMP_NAME, IT_EMP-EMP_ADD. ENDLOOP. FORM UPLOAD_INTERNAL_TABLE. LOOP AT it_excel. if it_excel-col = '0001'. it_emp-emp_id = it_excel-value. ELSEIF it_excel-col = '0002'. it_emp-emp_name = it_excel-value. ELSEIF it_excel-col = '0003'. it_emp-emp_add = it_excel-value. APPEND IT_EMP. CLEAR IT_EMP. ENDIF. ENDLOOP.

ENDFORM.

//excel download////

*&---------------------------------------------------------------------* *& Report ZAN_EXCEL_DOWNLOAD *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZAN_EXCEL_DOWNLOAD. DATA: BEGIN OF IT_EMP OCCURS 0, EMP_ID TYPE ZAN_EMPLOYEE-EMP_ID, EMP_NAME TYPE ZAN_EMPLOYEE-EMP_NAME,

EMP_ADD TYPE ZAN_EMPLOYEE-EMP_ADD, END OF IT_EMP. DATA: BEGIN OF IT_EXCEL OCCURS 0, CELL1(20) TYPE C, CELL2(20) TYPE C, CELL3(20) TYPE C, END OF IT_EXCEL. DATA: V_FILE TYPE STRING. PARAMETERS: P_FILE TYPE RLGRAP-FILENAME. AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE. CALL FUNCTION 'F4_FILENAME' * EXPORTING * PROGRAM_NAME = SYST-CPROG * DYNPRO_NUMBER = SYST-DYNNR * FIELD_NAME = ' ' IMPORTING FILE_NAME = P_FILE. START-OF-SELECTION. V_FILE = P_FILE. SELECT EMP_ID EMP_ADD EMP_NAME FROM ZAN_EMPLOYEE INTO CORRESPONDING FIELDS OF TABLE IT_EMP. IT_EXCEL-CELL1 = 'EMPLOYEE ID'. IT_EXCEL-CELL2 = 'EMPLOYEE NAME'. IT_EXCEL-CELL3 = 'EMPLOYEE ADDRESS'. APPEND IT_EXCEL. CLEAR IT_EXCEL. LOOP AT IT_EMP. IT_EXCEL-CELL1 = IT_EMP-EMP_ID. IT_EXCEL-CELL2 = IT_EMP-EMP_NAME. IT_EXCEL-CELL3 = IT_EMP-EMP_ADD. APPEND IT_EXCEL. CLEAR: IT_EMP,IT_EXCEL. ENDLOOP. CALL FUNCTION 'RH_START_EXCEL_WITH_DATA' EXPORTING DATA_FILENAME = V_FILE DATA_PATH_FLAG = ' ' * DATA_ENVIRONMENT = DATA_TABLE = IT_EXCEL[] * MACRO_FILENAME =

MACRO_PATH_FLAG = 'E' MACRO_ENVIRONMENT = WAIT = ' ' * DELETE_FILE = 'X' * CODEPAGE = EXCEPTIONS NO_BATCH = 1 EXCEL_NOT_INSTALLED = 2 INTERNAL_ERROR = 3 CANCELLED = 4 DOWNLOAD_ERROR = 5 NO_AUTHORITY = 6 FILE_NOT_DELETED = 7 OTHERS = 8. IF SY-SUBRC = 0. MESSAGE 'DATA DOENLOADED' TYPE 'S'. ELSE. MESSAGE'FAILED TRANSACTION' TYPE 'E'. ENDIF. * END-OF-SELECTION. LOOP AT IT_EMP. WRITE:/ IT_EMP-EMP_ID, IT_EMP-EMP_NAME, IT_EMP-EMP_ADD. ENDLOOP.

You might also like