Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Access db upload to SAP internal table table

Dear friends.

i am supposed to develop a program that upload the MS-Access DB table to SAP internal table. I have received the code wich is ok...but i am failed to provide it porper input as i am not receiving n e values in internall tables. please help me to understand this program i am providing you its source code which i received from this forum only...apart from it, is there n e other alternative to upload the data from MS access to SAP . I have Ms Access Data base db2.mdb as per the prgram and db2.mdb has tab (table). please see the code and help me in this regards..thanking you,,,

REPORT ZYSH01.

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(10) ,

F2 TYPE I,

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:\db2.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 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 OTHERS.

I1-F2 = 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.

ENDLOOP.

  • connetion close & destroy

FREE OBJECT con.

FREE OBJECT rec.

Tags:
replied

Hi!

I have the feeling, the table inside of db2.mdb should be named test, but I don't know any details of the OLE connections.

But there might be an easier solution: export the table from access as excel-file (and maybe convert this with Excel into a tab delimited text file). Then a data upload is 'business as usual'.

Regards,

Christian

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question