Uploading Data from Excel File to SAP using The FM 'UPLOAD_XLS_FILE_2_ITAB' and display it using ALV
The Following is the sample program for using the FM 'UPLOAD_XLS_FILE_2_ITAB'.
My Excel format is
REPORT ZEXCEL_UPLOAD_TO_SAP.
**Types For Data to be uploaded
TYPES : BEGIN OF TY_ITAB,
EBELN TYPE EBELN,
EBELP TYPE EBELP,
MENGE TYPE MENGE,
DMBTR TYPE DMBTR,
END OF TY_ITAB.
*&Create a Table Type From Types
TYPES : TITAB TYPE STANDARD TABLE OF TY_ITAB.
*&Create Table and Work Area for Data Processing.
DATA : GT_ITAB TYPE TITAB.
DATA : GS_ITAB TYPE TY_ITAB.
*Selection Screen For Getting Filename From User
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
FIELD_NAME = 'P_FILE'
IMPORTING
FILE_NAME = P_FILE.
START-OF-SELECTION.
CALL FUNCTION 'UPLOAD_XLS_FILE_2_ITAB'
EXPORTING
I_FILENAME = P_FILE
TABLES
E_ITAB = GT_ITAB
EXCEPTIONS
FILE_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
CASE SY-SUBRC.
WHEN 1.
MESSAGE 'Something went wrong in file,Close file and upload again' TYPE 'E'.
WHEN 2.
MESSAGE 'Error in Uploading file,Try again' TYPE 'E'.
ENDCASE.
ENDIF.
*&Reference for CL_SALV_TABLE for Displaying the Output
DATA GR_TABLE TYPE REF TO CL_SALV_TABLE.
CL_SALV_TABLE=>FACTORY(
IMPORTING
R_SALV_TABLE = GR_TABLE
CHANGING
T_TABLE = GT_ITAB ).
GR_TABLE->DISPLAY( ).
The Following is the sample program for using the FM 'UPLOAD_XLS_FILE_2_ITAB'.
My Excel format is
REPORT ZEXCEL_UPLOAD_TO_SAP.
**Types For Data to be uploaded
TYPES : BEGIN OF TY_ITAB,
EBELN TYPE EBELN,
EBELP TYPE EBELP,
MENGE TYPE MENGE,
DMBTR TYPE DMBTR,
END OF TY_ITAB.
*&Create a Table Type From Types
TYPES : TITAB TYPE STANDARD TABLE OF TY_ITAB.
*&Create Table and Work Area for Data Processing.
DATA : GT_ITAB TYPE TITAB.
DATA : GS_ITAB TYPE TY_ITAB.
*Selection Screen For Getting Filename From User
PARAMETERS : P_FILE TYPE RLGRAP-FILENAME.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
FIELD_NAME = 'P_FILE'
IMPORTING
FILE_NAME = P_FILE.
START-OF-SELECTION.
CALL FUNCTION 'UPLOAD_XLS_FILE_2_ITAB'
EXPORTING
I_FILENAME = P_FILE
TABLES
E_ITAB = GT_ITAB
EXCEPTIONS
FILE_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
CASE SY-SUBRC.
WHEN 1.
MESSAGE 'Something went wrong in file,Close file and upload again' TYPE 'E'.
WHEN 2.
MESSAGE 'Error in Uploading file,Try again' TYPE 'E'.
ENDCASE.
ENDIF.
*&Reference for CL_SALV_TABLE for Displaying the Output
DATA GR_TABLE TYPE REF TO CL_SALV_TABLE.
CL_SALV_TABLE=>FACTORY(
IMPORTING
R_SALV_TABLE = GR_TABLE
CHANGING
T_TABLE = GT_ITAB ).
GR_TABLE->DISPLAY( ).
No comments:
Post a Comment