Skip to end of metadata
Go to start of metadata

Following code snippet can be used to upload excel and generate uploaded data status results in a simple ALV List Display, which has the following features:

  • Uploaded Data (Rows and Columns ) from Excel Sheet into an internal table
  • Update Data into DB table.
  • Updated Records Display into alv format 
  • Status Information along with each row(Inserted/Deleted/Updated)  in alv display.

    Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
    *********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 Mappin************************
     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.
    

1 Comment

  1. Only one drawback......you PC should have Microsoft Excel installed.

    Or else, it will return sy-subrc = 2.