Skip to Content

Data From Excel to SAP

From excel user want to save data in SAP directly from EXCEL , without saving file on presentation server or application server... which they are currently doing for peoplesoft...

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on May 27, 2011 at 04:15 AM

    Here's the sample code:

    FORM browse_file .
    
      CONSTANTS : lc_window TYPE string VALUE 'Select file to upload', "#EC
                  lc_extn   TYPE string VALUE 'XLS',            "#EC
                  lc_dir    TYPE string VALUE 'D:\'.            "#EC
    
      DATA : i_files  TYPE filetable ,
             ls_file  TYPE file_table,
             lv_subrc TYPE i         ,
             lv_user  TYPE i         ,
             lv_def   TYPE string .
    
      lv_def = p_file .
    
      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        EXPORTING
          window_title            = lc_window
          default_extension       = lc_extn
          default_filename        = lv_def
          initial_directory       = lc_dir
        CHANGING
          file_table              = i_files
          rc                      = lv_subrc
          user_action             = lv_user
        EXCEPTIONS
          file_open_dialog_failed = 1
          cntl_error              = 2
          error_no_gui            = 3
          not_supported_by_gui    = 4
          OTHERS                  = 5.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    
      CHECK lv_user IS INITIAL .
      CHECK i_files IS NOT INITIAL .
      READ TABLE i_files INTO ls_file INDEX 1.
      p_file = ls_file-filename.
    
    ENDFORM .                    "browse_file
    
    *&---------------------------------------------------------------------*
    *&      Form  check_file_exist
    *&---------------------------------------------------------------------*
    
    FORM check_file_exist .
    
      DATA : lv_result TYPE abap_bool .
    
      g_name = p_file .
    
      CALL METHOD cl_gui_frontend_services=>file_exist
        EXPORTING
          file                 = g_name
        RECEIVING
          result               = lv_result
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          wrong_parameter      = 3
          not_supported_by_gui = 4
          OTHERS               = 5.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    
      IF lv_result = abap_false .
        MESSAGE e128 WITH g_name.         "File does not exist
      ENDIF.
    
    ENDFORM .                    "check_file_exist
    
    
    *&---------------------------------------------------------------------*
    *&      Form  upload_data
    *&---------------------------------------------------------------------*
    
    FORM upload_data  .
    
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
          text = text-022. "Uploading Excel File ...
    
      g_file = p_file .
    
      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
        EXPORTING
          filename                = g_file
          i_begin_col             = g_begin_col
          i_begin_row             = g_begin_row
          i_end_col               = g_end_col
          i_end_row               = g_end_row
        TABLES
          intern                  = g_t_raw
        EXCEPTIONS
          inconsistent_parameters = 1
          upload_ole              = 2
          OTHERS                  = 3.
    
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE 'I'
                NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        LEAVE LIST-PROCESSING .
      ENDIF.
    
      SORT g_t_raw BY row col.
    
      LOOP AT g_t_raw INTO g_wa_raw .
        CASE g_wa_raw-col.
    
          WHEN 1 .
            MOVE    g_wa_raw-value TO g_wa_datatab-date.
          WHEN 2.
            MOVE    g_wa_raw-value TO g_wa_datatab-time.
          WHEN 3.
            MOVE    g_wa_raw-value TO g_wa_datatab-locid.
          WHEN 4.
            MOVE    g_wa_raw-value TO g_wa_datatab-matnr.
          WHEN 5.
            MOVE    g_wa_raw-value TO g_wa_datatab-valtyp.
          WHEN 6.
            MOVE    g_wa_raw-value TO g_wa_datatab-rduom.
          WHEN 7.
            MOVE    g_wa_raw-value TO g_wa_datatab-phy_inv.
            APPEND  g_wa_datatab   TO g_t_datatab.
            CLEAR : g_wa_datatab.
          WHEN OTHERS.
    
        ENDCASE.
        CLEAR g_wa_raw.
      ENDLOOP.
    ENDFORM.                    "upload_data

    You can validate the data and then update it to the Database table.

    Hope this helps you.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 27, 2011 at 07:24 AM

    Hi anurodht,

    maybe a DCOM approach can help you.

    Some tips:

    - on your Excel application, you should write some VisualBasic_for_Applications (VBA) that log on to SAP and calls an RFC function module

    - on SAP, develop a Z function module (as RFC) that does all the "hard work", i.e. loading the data into SAP

    Kind regards,

    Alvaro

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.