|
文件: |
db1.rar(例程所用Access数据库) |
大小: |
6KB |
下载: |
下载 | |
REPORT Z_BARRY_TEST_MDB2.
INCLUDE ole2incl.
CONSTANTS: provider(40) VALUE 'Provider=Microsoft.Jet.OLEDB.4.0',
security(40) VALUE 'Persist Security Info=False',
datasource(30) VALUE 'Data Source=D:\db1.mdb'.
DATA: o_conn TYPE ole2_object,
o_recordset TYPE ole2_object,
o_field TYPE ole2_object.
DATA: con_str(128) ,sql_str(400).
DATA: BEGIN OF ty_itab OCCURS 0,
mandt LIKE t001-mandt ,
bukrs LIKE t001-bukrs ,
butxt LIKE t001-butxt ,
END OF ty_itab.
DATA: itab LIKE TABLE OF ty_itab WITH HEADER LINE.
START-OF-SELECTION.
PERFORM oledb_open.
PERFORM sql_select.
PERFORM sql_update.
PERFORM sql_close.
*&---------------------------------------------------------------------*
*& Form oledb_open
*&---------------------------------------------------------------------*
FORM oledb_open.
CONCATENATE provider ';' security ';' datasource INTO con_str.
CREATE OBJECT o_conn 'ADODB.Connection'.
SET PROPERTY OF o_conn 'Provider' = provider.
SET PROPERTY OF o_conn 'ConnectionString' = con_str.
CALL METHOD OF o_conn 'Open'.
ENDFORM. "OLEDB_open
*&---------------------------------------------------------------------*
*& Form sql_select
*&---------------------------------------------------------------------*
FORM sql_select .
DATA: rs_eof TYPE i.
sql_str = 'select mandt, bukrs,butxt from TEST_ZTEST'.
CALL METHOD OF o_conn 'Execute' = o_recordset
EXPORTING
#1 = sql_str.
GET PROPERTY OF o_recordset 'EOF' = rs_eof.
REFRESH itab.
WHILE rs_eof NE 1.
CALL METHOD OF o_recordset 'fields' = o_field
EXPORTING
#1 = 0.
GET PROPERTY OF o_field 'Value' = itab-mandt.
CALL METHOD OF o_recordset 'fields' = o_field
EXPORTING
#1 = 1.
GET PROPERTY OF o_field 'Value' = itab-bukrs.
CALL METHOD OF o_recordset 'fields' = o_field
EXPORTING
#1 = 2.
GET PROPERTY OF o_field 'Value' = itab-butxt.
APPEND itab.
CALL METHOD OF o_recordset 'MoveNext'.
GET PROPERTY OF o_recordset 'EOF' = rs_eof.
ENDWHILE.
LOOP AT itab.
WRITE: / itab-mandt,itab-bukrs,itab-butxt.
ENDLOOP.
ENDFORM. "sql_select
*&---------------------------------------------------------------------*
*& Form sql_update
*&---------------------------------------------------------------------*
FORM sql_update .
CONCATENATE 'update TEST_ZTEST set butxt=' '''' 'SAP AG' ''''
' where bukrs=' '''' '2005' '''' INTO sql_str.
CALL METHOD OF o_conn 'Execute' = o_recordset
EXPORTING
#1 = sql_str.
ENDFORM. "sql_update
*&---------------------------------------------------------------------*
*& Form sql_close
*&---------------------------------------------------------------------*
FORM sql_close.
CALL METHOD OF o_recordset 'Close'.
CALL METHOD OF o_conn 'Close'.
FREE OBJECT o_recordset.
FREE OBJECT o_conn.
ENDFORM. "sql_close
阅读(7178) | 评论(20) | 转发(0) |