05-27-2011 4:30 AM
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...
05-27-2011 5: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.
05-27-2011 5:40 AM
I said... without saving file on presentation server or application server...
05-27-2011 5:47 AM
05-27-2011 6:34 AM
05-27-2011 8:32 AM
Don't throw in the towel prematurely, search for "ABAP OLE Automation", many examples available.
Thomas
05-27-2011 8: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