Posted: Thu Nov 08, 2007 11:03 am Post subject: Upload from DBF format
Code:
REPORT z_load_dbf_file.
INCLUDE ole2incl.
*&---------------------------------------------------------------------*
*& Form load_dbf_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM load_dbf_file TABLES input_table
USING value(t_filename) LIKE rlgrap-filename.
DATA: application TYPE ole2_object,
workbooks TYPE ole2_object,
fworkbook TYPE ole2_object,
fsheets TYPE ole2_object,
fsheet TYPE ole2_object,
dsheet TYPE ole2_object,
frange TYPE ole2_object,
frow TYPE ole2_object.
DATA: return,
filename(128) TYPE c,
l_filename TYPE string.
* Filename conversion
MOVE t_filename TO filename.
TRANSLATE t_filename TO UPPER CASE.
REPLACE '.DBF' WITH '.DAT' INTO t_filename.
IF sy-subrc NE 0.
* error - filename extension is not DBF "TODO
MESSAGE w899(f5) WITH 'Error - filename extension is not DBF'.
EXIT.
ENDIF.
* check file existence
CALL FUNCTION 'WS_QUERY'
EXPORTING
filename = filename
query = 'FE'
IMPORTING
return = return
EXCEPTIONS
inv_query = 1
no_batch = 2
frontend_error = 3
OTHERS = 4.
IF ( sy-subrc NE 0 ) OR ( return EQ 0 ).
* error - file does not exist "TODO
MESSAGE w899(f5) WITH 'Error - file does not exist'.
EXIT.
ENDIF.
***** Working through OLE (MS Excel) *****
* OLE initialization
CREATE OBJECT dsheet 'Excel.Sheet'.
IF sy-subrc NE 0.
* error - OLE initialization of MS Excel "TODO
MESSAGE e899(f5) WITH 'Error - OLE initialization of MS Excel'.
EXIT.
ENDIF.
* supress messages from MS Excel
CALL METHOD OF dsheet 'Application' = application.
SET PROPERTY OF application 'DisplayAlerts' = 0.
* opening DBF-file
CALL METHOD OF application 'Workbooks' = workbooks.
CALL METHOD OF workbooks 'Open' EXPORTING #1 = filename
#2 = 0
#3 = 1.
* remove header line from DBF data
GET PROPERTY OF application 'ActiveWorkbook' = fworkbook.
CALL METHOD OF fworkbook 'Sheets' = fsheets.
CALL METHOD OF fsheets 'Item' = fsheet EXPORTING #1 = 1.
GET PROPERTY OF fsheet 'Rows' = frange.
CALL METHOD OF frange 'Item' = frow EXPORTING #1 = 1.
CALL METHOD OF frow 'Delete'.
* save as DAT file
CALL METHOD OF fworkbook 'SaveAs' EXPORTING #1 = t_filename
#2 = 20.
* close the book without saving
CALL METHOD OF fworkbook 'Close' EXPORTING #1 = 0.
FREE OBJECT dsheet.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.