Thursday, January 23, 2014

How to Upload Excel File to Internal Table & Display it in ALV

how-to-upload-excel-file-to-internal-table-in-abap
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:



*********Data 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. 


********ALV 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.

***********************END 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.


***********Use 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'.


****************************Ends*****************************************


  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.

Categories

ABAP (1) ABAP Interview Questions (112) ABAP Open SQL Statements (1) ABAP Syntax Rules (6) ABAP WORKBENCH (2) ABAP-Interview-Questions (52) ALE IDOC (6) ALE IDOC Interview Questions (6) ale-idoc (6) ALE-IDOC-Interview-Questions (19) ALV Interview Questions (5) ALV-Interview-Questions (22) BADI (2) BAPI (1) BAPI Interview Questions (1) BAPI-Interview-Questions (14) BDC (6) BDC Interview Questions (6) BDC-Interview-Questions (9) big data (2) big data interview questions (1) Classical Reports Interview Question (3) Classical-Reports-Interview-Questions (22) Conditional Statements (1) Cross Applications (3) Cross-Applications (14) Data Dictionary (22) Data Type Questins (1) Data types (1) Data-Dictionary (48) Data-Type-Questins (6) Dialog programming (5) Dialog Programming Interview Questions (4) Dialog-Programming (30) DOMAIN Interview Questions (1) Domain-Interview-Questions (8) Function Module (2) hadoop (2) hadoop interview questions (2) hdfs (1) IDoc Tutorials (6) Interactive Report Interview Questions (4) Interactive-Reports-Interview-Questions (22) Internal Tables (1) interview questions (1) Lock Object Interview Questions (1) Lock-Objects-Interview-Questions (10) Logical Database (1) Modularization Interview Questions (4) Modularization-Interview-Questions (25) Module Pool Programming (5) Module-Pool-Programming (39) modules in sap (1) Object Oriented ABAP (19) Object Oriented ABAP Interview Questions (15) object-oriented-abap (2) Object-Oriented-ABAP-Interview-Questions (34) OOABAP (9) Reports (14) Reports Interview Questions (9) Reports-Interview-Questions (19) RFC (1) RFC Interview Questions (1) RFC-Interview-Questions (14) RICEF (1) RICEF Objects (1) SAP (4) SAP ABAP (4) SAP ABAP Interview Questions (42) SAP ABAP Introduction (46) SAP ABAP Message Types (2) SAP BADI Interview Questions (2) SAP Basics (71) SAP Books (2) SAP Certification (1) SAP CONSULTANTS (5) SAP CRM (1) SAP ENHANCEMENTS (3) SAP EXITS (2) SAP EXITS ( SAP ENHANCEMENTS ) Interview Questions (1) SAP Free Books (1) SAP HR (2) SAP Lock Object (1) sap modules (2) SAP Open SQL Statements (1) SAP R/3 Architecture (4) SAP Search help (1) SAP Smartforms (1) SAP Smartforms Interview Questions (2) SAP Tables (5) SAP Tcodes (10) SAP Views (1) SAP Webdynpro ABAP (12) SAP Work Processors (2) SAP Workflow (3) SAP-BADI-Interview-Questions (11) SAP-Enhancements (39) SAP-Exits (39) SAP-Exits-Enhancements-Interview Questions (3) SAP-HANA (1) SAP-HANA-Interview-Questions (1) SAP-Smartforms-Interview-Questions (2) SAP-Workflow (3) Scripts (3) Scripts Interview Questions (2) Scripts-Interview-Questions (32) Search Help Interview Questions (1) Search-Help-Interview-Questions (9) Smartforms (1) Table Maintenance Generator (1) Table-Maintenance-Generator (4) Tables in SAP (2) Tables Interview Questions (3) Tables-Interview-Questions (3) Type Group Interview Questions (1) Type-Group-Interview-Questions (7) Variable Declaration (1) Views Interview Questions (1) Views-Interview-Questions (5) Webdynpro (12) what is big data (1)

Protected Blog

 
This blog is not affiliated to SAP AG |SAP is trademark of SAP AG |The information collected from various sources use information with your own risk.