SAP ABAP Tutorial, How to Upload Excel File to Internal Table and Display it in ALV Format. Welcome to SAP ABAP Interview Questions.
Uploading Excel File to Internal Table & Display it in ALV Report
www.sapabapiq.com presenting one ABAP tutorial on how to upload excel file to internal table and display it in ALV format. This tutorial consist SAP ABAP source code to upload excel file to internal table and then display excel data in ALV report. We hope this article will help you to assist in uploading excel file to internal table and display in ALV. Please refer this post to complete source code.
Code to Upload Excel File to Internal Table & Display in ALV
The following ABAP source code consists of below features to upload excel file into internal table and display it in alv format. We suggest you to copy the source code to abap editor and debug to understand the functionality of the program.
SAP ABAP Programming code consists of below functionality:
1) Uploaded Data (Rows and Columns ) from Excel Sheet into an internal table
2) Update Data into DB table.
3) Updated Records Display into ALV format
4) Status Information along with each row(Inserted/Deleted/Updated) in ALV display.
Source code begins here:
**
**
**
**
*D
ata Declaration
**
**
**
**
**
**
**
**
Tables: Z82426_GL_MAP.
DATA
:PROGNAME
LIKE
SY-REPID,
DYNNUM
LIKE
SY-DYNNR.
Data: FilePath
TYPE
LOCALFILE.
DATA
: IT_TAB
TYPE
standard
TABLE
OF ALSMEX_TABLINE,
wa_tab type ALSMEX_TABLINE.
********A
LV data declarations************
DATA
: GD_REPID
LIKE
SY-REPID.
"Exists
TYPE-POOLS: SLIS. "
ALV Declarations
DATA
: FIELDCATALOG
TYPE
SLIS_T_FIELDCAT_ALV
WITH
HEADER
LINE
,
GD_LAYOUT
TYPE
SLIS_LAYOUT_ALV.
**
**
*****************
For GL Mapping
**
**
**
**
**
**
**
**
**
**
**
**
DATA
: Tmp_GLMAP_DATA type standard table of Z82426_GL_MAP,
t_GLMAP type standard table of Z82426_GL_MAP,
wa_GLMAP_DATA Type Z82426_GL_MAP.
TYPES
: BEGIN OF str_GLMAP_DATA,
L_GL_ACC
TYPE
Z82426_GL_MAP-L_GL_ACC,
DESC_LGL
TYPE
Z82426_GL_MAP-DESC_LGL,
B_UNIT
TYPE
Z82426_GL_MAP-B_UNIT,
SAKNR
TYPE
Z82426_GL_MAP-SAKNR,
DEL_IND(1)
TYPE
C
,
MSG(50)
TYPE
C
,
END OF str_GLMAP_DATA.
data: t_GLMAP_DATA
TYPE
STANDARD
TABLE
OF str_GLMAP_DATA,
wa_GLMAP
TYPE
str_GLMAP_DATA.
**
**
**
**
***************E
ND Declaration
**
**
**
**
**
**
**
**
FORM
EXCEL_UPLOAD_LGL_ACC_DATA .
REFRESH
IT_TAB.
CLEAR
IT_TAB.
CALL
FUNCTION
'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = FILEPATH
i_begin_col = 1
i_begin_row = 3
i_end_col = 5
i_end_row = 9
tables
intern = IT_TAB
*
EXCEPTIONS
*
INCONSISTENT_PARAMETERS = 1
*
UPLOAD_OLE = 2
*
OTHERS
= 3
.
IF
sy-subrc <> 0.
*
MESSAGE
ID SY-MSGID
TYPE
SY-MSGTY NUMBER SY-MSGNO
*
WITH
SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF
.
SORT
IT_TAB
BY
ROW COL.
CLEAR
wa_GLMAP.
CLEAR
wa_tab.
IF
IT_TAB[]
IS
NOT
INITIAL
.
LOOP
AT
IT_TAB into wa_tab .
CASE
wa_tab-COL.
WHEN
'0001'
.
wa_GLMAP-L_GL_ACC = wa_tab-VALUE.
WHEN
'0002'
.
wa_GLMAP-DESC_LGL = wa_tab-VALUE.
WHEN
'0003'
.
wa_GLMAP-B_UNIT = wa_tab-VALUE.
WHEN
'0004'
.
wa_GLMAP-SAKNR = wa_tab-VALUE.
WHEN
'0005'
.
wa_GLMAP-DEL_IND = wa_tab-VALUE.
ENDCASE
.
AT
END OF ROW.
APPEND
wa_GLMAP
TO
t_GLMAP_DATA.
CLEAR
wa_GLMAP.
ENDAT
.
ENDLOOP
.
ELSE
.
LEAVE
LIST-PROCESSING
.
ENDIF
.
IF
t_GLMAP_DATA
IS
NOT
INITIAL
.
LOOP
AT
t_GLMAP_DATA
INTO
wa_GLMAP.
CLEAR
wa_GLMAP_DATA.
SELECT
SINGLE
*
FROM
Z82426_GL_MAP
INTO
wa_GLMAP_DATA
WHERE
L_GL_ACC = wa_GLMAP-L_GL_ACC.
IF
SY-SUBRC = 0.
IF
wa_GLMAP-DEL_IND =
'X'
.
DELETE
FROM
Z82426_GL_MAP
WHERE
L_GL_ACC = wa_GLMAP-L_GL_ACC.
wa_GLMAP-MSG =
'Record Deleted successfully'
.
ELSE
.
UPDATE
Z82426_GL_MAP
SET
DESC_LGL = wa_GLMAP-DESC_LGL
B_UNIT = wa_GLMAP-B_UNIT
SAKNR = wa_GLMAP-SAKNR
WHERE
L_GL_ACC = wa_GLMAP-L_GL_ACC.
wa_GLMAP-MSG =
'Record Updated sucessfully'
.
ENDIF
.
ELSE
.
IF
wa_GLMAP-DEL_IND =
'X'
.
wa_GLMAP-MSG =
'Record Not Found'
.
ELSE
.
wa_GLMAP_DATA-L_GL_ACC = wa_GLMAP-L_GL_ACC.
wa_GLMAP_DATA-DESC_LGL = wa_GLMAP-DESC_LGL.
wa_GLMAP_DATA-B_UNIT = wa_GLMAP-B_UNIT.
wa_GLMAP_DATA-SAKNR = wa_GLMAP-SAKNR.
INSERT
INTO
Z82426_GL_MAP VALUES wa_GLMAP_DATA.
wa_GLMAP-MSG =
'Record Inserted successfully'
.
ENDIF
.
ENDIF
.
MODIFY
t_GLMAP_DATA
FROM
wa_GLMAP.
ENDLOOP
.
**
**
**
**
**
*U
se this line only if you are using Dialog programming
**
**
**
**
**
LEAVE
TO
LIST-PROCESSING
AND
RETURN
TO
SCREEN
0.
SET
PF-STATUS
'Z82426_PF_9010'
excluding app_but_tab.
SET
TITLEBAR
'Z82426_TITLE'
.
**
**
**
**
**
***************
**
*E
nds
*
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
**
REFRESH
FIELDCATALOG.
CLEAR
FIELDCATALOG.
FIELDCATALOG-FIELDNAME =
'L_GL_ACC'
.
FIELDCATALOG-SELTEXT_M =
'Legacy GL Acc'
.
FIELDCATALOG-COL_POS = 1.
APPEND
FIELDCATALOG.
CLEAR
FIELDCATALOG.
FIELDCATALOG-FIELDNAME =
'DESC_LGL'
.
FIELDCATALOG-SELTEXT_M =
'Legacy GL Desc'
.
FIELDCATALOG-COL_POS = 2.
APPEND
FIELDCATALOG.
CLEAR
FIELDCATALOG.
FIELDCATALOG-FIELDNAME =
'B_UNIT'
.
FIELDCATALOG-SELTEXT_M =
'Business Unit'
.
FIELDCATALOG-COL_POS = 3.
APPEND
FIELDCATALOG.
CLEAR
FIELDCATALOG.
FIELDCATALOG-FIELDNAME =
'SAKNR'
.
FIELDCATALOG-SELTEXT_M =
'SAP GL Acc'
.
FIELDCATALOG-COL_POS = 4.
APPEND
FIELDCATALOG.
CLEAR
FIELDCATALOG.
FIELDCATALOG-FIELDNAME =
'DEL_IND'
.
FIELDCATALOG-SELTEXT_M =
'Deletion Indicator'
.
FIELDCATALOG-COL_POS = 5.
APPEND
FIELDCATALOG.
CLEAR
FIELDCATALOG.
FIELDCATALOG-FIELDNAME =
'MSG'
.
FIELDCATALOG-SELTEXT_M =
'Result Message'
.
FIELDCATALOG-COL_POS = 6.
APPEND
FIELDCATALOG.
CLEAR
FIELDCATALOG.
CALL
FUNCTION
'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
*
i_callback_top_of_page =
' '
*
I_CALLBACK_PF_STATUS_SET =
' '
*
I_CALLBACK_USER_COMMAND =
' '
*
i_grid_title =
' '
IS_LAYOUT = GD_LAYOUT
IT_FIELDCAT = FIELDCATALOG[]
TABLES
T_OUTTAB = t_GLMAP_DATA
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS
= 2.
IF
SY-SUBRC
NE
0.
WRITE
:/ SY-SUBRC.
ENDIF
.
ENDIF
.
ENDFORM
.
******************************* End of Code *****************************
"You found the information helpful and want to say thanks? Your donation is enough to inspire us to do more. Thanks a bunch!"
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.