Video:
Code:
*&———————————————————————*
*& Report ZPR_UPLOAD_EXCEL
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT ZPR_UPLOAD_EXCEL.
DATA IT_EXCEL LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA WA_EXCEL LIKE LINE OF IT_EXCEL.
TYPES:
BEGIN OF TY_DATA,
MATNR LIKE IT_EXCEL-VALUE,
MAKTX LIKE IT_EXCEL-VALUE,
MEINS LIKE IT_EXCEL-VALUE,
END OF TY_DATA.
DATA IT_DATA TYPE STANDARD TABLE OF TY_DATA.
DATA WA_DATA LIKE LINE OF IT_DATA.
FIELD-SYMBOLS <FS_DATA> LIKE LINE OF IT_DATA.
FIELD-SYMBOLS <FS> TYPE ANY.
DATA GV_FILENAME TYPE IBIPPARMS-PATH.
DATA GV_COM TYPE I.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME.
PARAMETERS: P_BCOL TYPE I DEFAULT 1.
PARAMETERS: P_BROW TYPE I DEFAULT 2.
PARAMETERS: P_ECOL TYPE I DEFAULT 3.
PARAMETERS: P_EROW TYPE I DEFAULT 1000.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION ‘F4_FILENAME’
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ‘PATH’
IMPORTING
FILE_NAME = GV_FILENAME.
P_FILE = GV_FILENAME.
END-OF-SELECTION.
CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE’
EXPORTING
FILENAME = P_FILE
I_BEGIN_COL = P_BCOL
I_BEGIN_ROW = P_BROW
I_END_COL = P_ECOL
I_END_ROW = P_EROW
TABLES
INTERN = IT_EXCEL
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
SORT IT_EXCEL BY ROW COL.
LOOP AT IT_EXCEL INTO WA_EXCEL.
AT NEW ROW.
APPEND INITIAL LINE TO IT_DATA ASSIGNING <FS_DATA>.
GV_COM = 1.
ENDAT.
ASSIGN COMPONENT GV_COM OF STRUCTURE <FS_DATA> TO <FS>.
<FS> = WA_EXCEL-VALUE.
GV_COM = GV_COM + 1.
ENDLOOP.
LOOP AT IT_DATA ASSIGNING <FS_DATA>.
WRITE: / <FS_DATA>-MATNR, ‘ – ‘, <FS_DATA>-MAKTX, ‘ – ‘, <FS_DATA>-MEINS.
ENDLOOP.