SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Upload Data From MS Access Into an Internal Table



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Wed Feb 25, 2009 1:43 pm    Post subject: Upload Data From MS Access Into an Internal Table Reply with quote

Code:
*———————————————————————*
* Report Name : YGECICI
*———————————————————————*
* Author : Amit Khari
* Location :ABAPcode site
* Date / Time : 05 may 2007
* Subject : Upload Data From MS Accsess Into an Internal Table
*———————————————————————*
REPORT ygecici MESSAGE-ID 00 NO STANDARD PAGE HEADING
LINE-SIZE 200
LINE-COUNT 65.

INCLUDE ole2incl.

DATA: con TYPE ole2_object,
rec TYPE ole2_object.

DATA sql(1023).

DATA: BEGIN OF spl OCCURS 0,
val(1023),
END OF spl.

DATA: BEGIN OF i1 OCCURS 0,
f1 TYPE i ,
f2(10),
f3(10),
END OF i1.

IF con-header IS INITIAL OR con-handle = -1.
  CREATE OBJECT con 'adodb.connection'.
  IF NOT sy-subrc = 0.
    EXIT.
  ENDIF.

  CREATE OBJECT rec 'adodb.recordset'.
  IF NOT sy-subrc = 0.
    EXIT.
  ENDIF.

ENDIF.

* MDB Connetion Infomations ….
CONCATENATE 'provider=' '"microsoft.jet.oledb.4.0"' ';'
INTO sql.
CONCATENATE sql 'password=' '''' ';'
INTO sql.
CONCATENATE sql 'user id=’ '"admin"' ';'
INTO sql.
CONCATENATE sql 'data source=' '"c:\mm.mdb"' ';'
INTO sql.
CONCATENATE sql 'mode=' '"share deny none"'
INTO sql.

* MDB Connection …
CALL METHOD OF con 'open'
EXPORTING #1 = sql.
*

* Query (Insert) Statement …
sql = 'insert into [test] values('.
CONCATENATE sql '"a"' ',' '"1"' ')' INTO sql.

* Query Run …
CALL METHOD OF rec 'open'
EXPORTING #1 = sql
#2 = con
#3 = '1'.

* Query (Select) Statement …
sql = 'select * from [test]'.

* Query Run …
CALL METHOD OF rec 'open'
EXPORTING #1 = sql
#2 = con
#3 = '1'.

* Selecting MDB Record Into SAP Internal Table …
DO.
  CALL METHOD OF rec 'getstring' = sql
  EXPORTING #1 = '2' "do not modify!
  #2 = 1 "do not modify!
  #3 = '|' "do not modify!
  #4 = '|'. "do not modify!

  IF sy-subrc EQ 0.
    REFRESH spl. CLEAR spl.
    SPLIT sql AT '|' INTO TABLE spl.
    LOOP AT spl.
      CASE sy-tabix.
        WHEN 1.
          i1-f1 = spl-val.
        WHEN 2.
          i1-f2 = spl-val.
        WHEN OTHERS.
          i1-f3 = spl-val.
      ENDCASE.
    ENDLOOP.
    APPEND i1. CLEAR i1.
  ELSE.
    EXIT.
  ENDIF.

ENDDO.

* Result Writing …
LOOP AT i1.
  WRITE: AT /1(10) i1-f1,
         AT (10) i1-f2, AT (20) i1-f3.
ENDLOOP.

* Connetion Close & Destroy
FREE OBJECT con.
FREE OBJECT rec.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.