‎2008 Jun 10 8:53 AM
HELLO ,
I want to migrate date from excel file to SAP using SHDB tcode. can anybody guide me how to do that.....what input i have to give when field contents......from file or from recording?
Where to mention name of file from which we have to take data?
‎2008 Jun 11 12:05 AM
Get the Excel Data into a internal table using cl_gui_frontend_services=>gui_upload and then write a logic accordingly to upload data into database tables using Batchinput , Transaction..etc..
‎2008 Jun 11 5:58 AM
hi ,
you first do the recording using SHDB. Then slect the recording and click on the button Program which asks whether to transfer from the recording or to create from a file. select any option and this creates program.
now you have to add the FM to upload the data from flat file to internal table. you can use the following code for that. Now replace the values with the workarea values.
we have a function module : ALSM_EXCEL_TO_INTERNAL_TABLE .
Apart from this we have other function modules like
TEXT_CONVERT_XLS_TO_SAP
The FM takes the column and row limits as parameters . This FM reads data from EXCEL file and put in an internal table of format ROWPOS COLPOS VALUE.
SO again by looping the same internal table and extracting the values using the CASE.
Please find the sample code.
REPORT ZEXCEL_ITAB .
TYPES : BEGIN OF TY_ITAB ,
V1 TYPE C,
V2(10) TYPE C,
V3(10) TYPE C,
V4(10) TYPE C,
END OF TY_ITAB.
DATA : ITAB TYPE TABLE OF TY_ITAB,
WITAB TYPE TY_ITAB.
DATA:JTAB TYPE TABLE OF ALSMEX_TABLINE ,
WJTAB TYPE ALSMEX_TABLINE .
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = 'D:\Documents and Settings\hzb14v.APAC\Desktop\Book1.xls'
I_BEGIN_COL = 1
I_BEGIN_ROW = 1
I_END_COL = 4
I_END_ROW = 3
TABLES
INTERN = JTAB.
LOOP AT JTAB INTO WJTAB.
CASE WJTAB-COL.
WHEN '0001'.
MOVE: WJTAB-VALUE TO WITAB-V1.
WHEN '0002'.
MOVE: WJTAB-VALUE TO WITAB-V2.
WHEN '0003'.
MOVE: WJTAB-VALUE TO WITAB-V3.
WHEN '0004'.
MOVE: WJTAB-VALUE TO WITAB-V4.
ENDCASE.
AT END OF ROW.
APPEND WITAB TO ITAB.
CLEAR WITAB.
ENDAT.
CLEAR WJTAB.
ENDLOOP.
Reward points if helpful.
Thanks and Regards