Code: Alles auswählen.
REPORT ZCOM4ABAP01 line-size 300 .
types: begin of itabtype,
customer_ID(5) type n,
company_name(40) type c,
contact_name(30) type c,
contact_title(30) type c,
address(60) type c,
city(15) type c,
region(15) type c,
postal_code(10) type c,
country(15) type c,
phone(24) type c,
fax(24) type c,
end of itabtype.
data: service_dest type rfcdes-rfcdest VALUE 'COM01',
worker_dest type rfcdes-rfcdest,
class_id(64) type c value 'Northwind.Customers',
interface_id(64) type c value '_Customers',
type_library(64) type c value 'Northwind',
oid type int4,
customers type standard table of itabtype with header line.
call function 'BEGIN_COM_SESSION'
exporting service_dest = service_dest
importing worker_dest = worker_dest
exceptions connect_to_com_service_failed = 1
connect_to_com_worker_failed = 2
others = 3.
call function 'create_com_instance' destination worker_dest
exporting clsid = class_id
iid = interface_id
typelib = type_library
importing instid = oid.
call function 'com_invoke' destination worker_dest
exporting %instid = oid
%method = 'SET_ConnString'
%value = 'DSN=Northwind'
exceptions others = 1.
if sy-subrc ne 0.
write: / 'Error setting Connection string'.
endif.
call function 'com_invoke' destination worker_dest
exporting %instid = oid
%method = 'GetCustomers'
tables %return = customers
exceptions others = 1.
if sy-subrc ne 0.
write: / 'Error retrieving customer list'.
endif.
loop at customers.
write: / customers-customer_id,
customers-company_name,
customers-contact_title,
customers-contact_name,
customers-address,
customers-city,
customers-region,
customers-postal_code,
customers-country,
customers-phone,
customers-fax.
endloop.
call function 'delete_com_instance' destination worker_dest
exporting instid = oid
exceptions others = 1.
if sy-subrc ne 0.
write: / ' Could not destroy instance'.
endif.
call function 'END_COM_SESSION'
exporting destination = worker_dest
exceptions others = 1.
if sy-subrc ne 0.
write: / 'Could not destroy session'.
endif.