*&---------------------------------------------------------------------*
*& Report SAPRDEMOWORD97INTEGRATION *
*&---------------------------------------------------------------------*
INCLUDE rdemoword97integrationtop. DATA: factory TYPE REF TO i_oi_document_factory.
DATA: document TYPE REF TO i_oi_document_proxy.
DATA: link_server TYPE REF TO i_oi_link_server.
DATA: bds_instance TYPE REF TO cl_bds_document_set. DATA: retcode TYPE t_oi_ret_string,
document_type(80) VALUE soi_doctype_word97_document,
document_format(80) TYPE c.
DATA: documents TYPE document_list.
DATA: descr TYPE document_descr. DATA: data_table TYPE sbdst_content,
data_size TYPE i, doc_url TYPE t_url,
has_changed TYPE i,
delimiter(1) TYPE c VALUE'/',
data_type(64) TYPE c,
data_subtype(64) TYPE c,
document_mimetype TYPE bapicompon-mimetype. DATA: first_open VALUE '1'. DATA: BEGIN OF point_data,
proposal(40), lastname(30), comment(128),
END OF point_data.
DATA: points LIKE point_data OCCURS 0 WITH HEADER LINE. CLASS c_event_handler DEFINITION. PUBLIC SECTION.
CLASS-METHODS: close_event_handler
FOR EVENT on_close_document OF i_oi_document_proxy
IMPORTING document_proxy has_changed. CLASS-METHODS: custom_event_handler
FOR EVENT on_custom_event OF i_oi_document_proxy
IMPORTING document_proxy event_name param_count
param1 param2 param3. ENDCLASS. CLASS c_event_handler IMPLEMENTATION.
METHOD close_event_handler.
* FOR EVENT on_close_document OF c_oi_container_control
* IMPORTING document_proxy has_changed.
DATA: answer.
* if has_changed eq 1.
PERFORM save_document TABLES data_table
USING 'X' 'X'
CHANGING data_size document_proxy retcode.
open_document = false.
* endif.
ENDMETHOD. METHOD custom_event_handler.
* FOR EVENT on_custom_event OF i_oi_document_proxy
* IMPORTING document_proxy event_name param_count
* param1 param2 param3.
DATA: text(80).
CONCATENATE 'Word:' event_name 'fired with parameter:' param1
INTO text SEPARATED BY space. "#EC NOTEXT
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = 'Word 97 Integration Demo'(002)
txt1 = text
txt2 = space.
ENDMETHOD.
ENDCLASS. *&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
DATA: o1 TYPE REF TO c_event_handler.
CREATE OBJECT o1. SET PF-STATUS 'MAIN0100'.
SET TITLEBAR '001'. retcode = c_oi_errors=>ret_ok. IF bds_instance is initial.
CREATE OBJECT bds_instance.
ENDIF. IF factory is initial.
CALL METHOD c_oi_factory_creator=>get_document_factory
IMPORTING factory = factory
retcode = retcode.
IF retcode ne c_oi_errors=>ret_ok. EXIT. ENDIF. CALL METHOD factory->start_factory
EXPORTING r3_application_name =
'SAP Basis' "#EC NOTEXT
register_on_close_event = 'X'
register_on_custom_event = 'X'
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. CALL METHOD factory->get_link_server
IMPORTING link_server = link_server
retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. CALL METHOD link_server->start_link_server
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. CALL METHOD factory->get_document_proxy
EXPORTING document_type = document_type
IMPORTING document_proxy = document
retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. SET HANDLER c_event_handler=>close_event_handler FOR document.
SET HANDLER c_event_handler=>custom_event_handler FOR document.
* dynpro fields default
template = 'DEMOWORD97TEMPLATE'.
user = 'Ehre'. "#EC NOTEXT
company = 'SAP'. "#EC NOTEXT
macro = 'swap_color'. "#EC NOTEXT
event = 'event2'. "#EC NOTEXT
menubar = 'SAP Menu Bar'. "#EC NOTEXT
menu = 'SAP Menu'. "#EC NOTEXT
menuitem = 'Fire R/3 event'. "#EC NOTEXT
proposal = 'First Proposal'. "#EC NOTEXT
author = 'Ehre'. "#EC NOTEXT
comment = 'This is a comment'. "#EC NOTEXT PERFORM refresh_links. ENDIF. ENDMODULE. " STATUS_0100 OUTPUT *&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CALL METHOD cl_gui_cfw=>dispatch. CASE fcode.
WHEN 'EXIT'. "Zurück
IF not document is initial.
PERFORM save_document TABLES data_table
USING 'X' 'X'
CHANGING data_size document retcode.
FREE document.
ENDIF.
IF not link_server is initial.
CALL METHOD link_server->stop_link_server
IMPORTING retcode = retcode.
FREE link_server.
ENDIF.
IF not factory is initial.
CALL METHOD factory->stop_factory IMPORTING retcode = retcode.
FREE factory.
ENDIF.
IF not bds_instance is initial.
FREE bds_instance.
ENDIF. LEAVE TO SCREEN 0. WHEN 'SELECT'.
IF not document is initial.
PERFORM save_document TABLES data_table
USING 'X' 'X'
CHANGING data_size document retcode.
ENDIF.
IF not factory is initial.
REFRESH documents.
descr-document_name =
'Office Integration Description'(do1).
descr-document_id = 'DEMOWORD97DOC'.
APPEND descr TO documents.
descr-document_name =
'Demo Document'(do2).
descr-document_id = 'DEMOWORD97DOC2'.
APPEND descr TO documents.
descr-document_name =
'Demo Document XP'(do3).
descr-document_id = 'DEMOWORDXPDOC2'.
APPEND descr TO documents. CLEAR doc_url.
PERFORM select_and_load_document
TABLES documents
USING 'Select Document'(sdo)
CHANGING document_type document_format doc_url. IF not doc_url is initial.
CALL METHOD document->open_document
EXPORTING document_url = doc_url
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
* Document shall also be available in ITAB for respective operations:
CALL METHOD document->save_document_to_table
IMPORTING retcode = retcode
CHANGING document_table = data_table
document_size = data_size.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. first_open = false.
open_document = true. CALL METHOD document->execute_macro
EXPORTING macro_string = 'R3UpdateTables' "#EC NOTEXT
IMPORTING retcode = retcode.
ELSE.
MESSAGE e010.
ENDIF.
ENDIF. WHEN 'OPEN'.
IF first_open = true.
first_open = false. REFRESH documents.
descr-document_name =
'Office Integration Description'(do1).
descr-document_id = 'DEMOWORD97DOC'.
APPEND descr TO documents. PERFORM select_and_load_document
TABLES documents
USING 'Select Document'(sdo)
CHANGING document_type document_format doc_url.
CALL METHOD document->open_document
EXPORTING document_url = doc_url
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
* Document shall also be available in ITAB for respective operations:
CALL METHOD document->save_document_to_table
IMPORTING retcode = retcode
CHANGING document_table = data_table
document_size = data_size.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. ELSE.
* open document stored in internal table data_table
DATA: is_closed TYPE i. CALL METHOD document->is_destroyed
IMPORTING ret_value = is_closed. IF is_closed is initial.
CALL METHOD document->close_document
EXPORTING do_save = 'X'
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. CALL METHOD document->save_document_to_table
IMPORTING retcode = retcode
CHANGING document_table = data_table[]
document_size = data_size.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
ENDIF. CALL METHOD document->release_document
IMPORTING retcode = retcode. CALL METHOD document->open_document_from_table
EXPORTING document_table = data_table[]
document_size = data_size
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
ENDIF.
open_document = true.
CALL METHOD document->execute_macro
EXPORTING macro_string = 'R3UpdateTables' "#EC NOTEXT
IMPORTING retcode = retcode. WHEN 'REFRESH'.
IF not link_server is initial.
PERFORM refresh_links.
CALL METHOD document->execute_macro
EXPORTING macro_string = 'R3UpdateTables' "#EC NOTEXT
IMPORTING retcode = retcode.
ELSE.
MESSAGE e004.
ENDIF. WHEN 'SAVEAS'.
CALL METHOD document->save_as
EXPORTING file_name = ''
prompt_user = 'X'
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. WHEN 'CLOSE'.
PERFORM save_document TABLES data_table
USING ' ' 'X'
CHANGING data_size document retcode.
open_document = false. WHEN 'COPYLINK'.
IF not link_server is initial.
PERFORM refresh_links. CALL METHOD link_server->execute_copy_link_dialog
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
ELSE.
MESSAGE e004.
ENDIF. WHEN 'INSTALL'.
DATA: wp_ref TYPE REF TO i_oi_word_processor_document. CHECK not document is initial and open_document = true.
CALL METHOD document->get_wordprocessor_interface
IMPORTING wp_interface = wp_ref
retcode = retcode.
IF retcode eq c_oi_errors=>ret_ok. CLEAR item_url.
CLEAR descr.
descr-document_id = template. PERFORM select_document
CHANGING descr-document_id
document_format
doc_url
document_mimetype.
item_url = doc_url.
CALL METHOD wp_ref->install_template
EXPORTING template_name = template
url = item_url
IMPORTING retcode = retcode.
FREE wp_ref.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
ELSE.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
ENDIF. WHEN 'EXECT'.
CHECK not document is initial and open_document = true.
CALL METHOD document->get_wordprocessor_interface
IMPORTING wp_interface = wp_ref
retcode = retcode.
IF retcode eq c_oi_errors=>ret_ok.
CALL METHOD wp_ref->set_template
EXPORTING template_name = template
IMPORTING retcode = retcode.
FREE wp_ref.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
ELSE.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
ENDIF. WHEN 'EXECS'.
CHECK not document is initial and open_document = true.
* straight ole automation
DATA: document_cntl_handle TYPE cntl_handle.
INCLUDE ole2incl.
DATA: ocharacters TYPE ole2_object,
orange TYPE ole2_object,
oreplacement TYPE ole2_object,
ofind TYPE ole2_object,
ofont TYPE ole2_object. DATA: char_count TYPE i,
char_position TYPE i,
old_search_string LIKE search,
string_found TYPE i,
color_index TYPE i. CALL METHOD document->get_document_handle
IMPORTING handle = document_cntl_handle
retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
IF old_search_string ne search.
* get number of document characters.
GET PROPERTY OF document_cntl_handle-obj
'characters' = ocharacters.
GET PROPERTY OF ocharacters 'count' = char_count.
char_position = 0.
old_search_string = search.
ENDIF.
* set range now
IF char_position >= char_count.
char_position = 0.
ENDIF.
CALL METHOD OF document_cntl_handle-obj 'Range' = orange
EXPORTING #1 = char_position #2 = char_count.
* search now
GET PROPERTY OF orange 'Find' = ofind.
* set property of ofind 'Text' = search.
* set property of ofind 'Forward' = true.
* call method of ofind 'ClearFormatting'.
* IF NOT REPLACE IS INITIAL.
* GET PROPERTY OF OFIND 'Replacement' = OREPLACEMENT.
* SET PROPERTY OF OREPLACEMENT 'Text' = REPLACE.
* CALL METHOD OF OREPLACEMENT 'ClearFormatting'.
* ENDIF.
IF not replace is initial.
* replace
* CALL METHOD OF ofind 'Execute'
* EXPORTING #1 = search "FindText
* #2 = false "MatchCase
* #3 = false "MatchWholeWord
* #4 = false "MatchWildCards
* #5 = false "MatchSoundsLike
* #6 = true "MatchAllWordForms
* #7 = true "Forward
* #8 = '1' "Wrap
* #9 = true
* #91 = replace
* #92 = '2'.
* char_position = 0.
*BEGIN - Japaneese characters get garbled refer note 878178.
DATA: is_available type i. CALL METHOD document->has_wordprocessor_interface
IMPORTING is_available = is_available
retcode = retcode. IF is_available = 1 . CALL METHOD document->get_wordprocessor_interface
IMPORTING wp_interface = wp_ref
retcode = retcode. IF RETCODE EQ C_OI_ERRORS=>RET_OK. CALL METHOD wp_ref->replace
EXPORTING replace_string = replace
search_string = search
pos = 'GLOBAL'
flag = 'ALL'. ENDIF. ENDIF.
*END - Japaneese characters get garbled refer note 878178. ELSE.
*search
CALL METHOD OF ofind 'Execute'
EXPORTING #1 = search "FindText
#2 = false "MatchCase
#3 = false "MatchWholeWord
#4 = false "MatchWildCards
#5 = false "MatchSoundsLike
#6 = true "MatchAllWordForms
#7 = true "Forward
#8 = '1' "Wrap
#9 = true.
GET PROPERTY OF ofind 'Found' = string_found.
IF string_found > 0.
GET PROPERTY OF orange 'Font' = ofont.
GET PROPERTY OF ofont 'ColorIndex' = color_index.
IF color_index ne 6.
color_index = 6.
ELSE.
color_index = 11.
ENDIF.
SET PROPERTY OF ofont 'ColorIndex' = color_index.
ENDIF.
GET PROPERTY OF orange 'End' = char_position.
ENDIF.
* CALL METHOD DOCUMENT->GET_WORDPROCESSOR_INTERFACE
* IMPORTING WP_INTERFACE = WP_REF
* RETCODE = RETCODE.
* IF RETCODE EQ C_OI_ERRORS=>RET_OK.
* IF REPLACE IS INITIAL.
* CALL METHOD WP_REF->SEARCH
* EXPORTING SEARCH_STRING = SEARCH
* POS = '1'
* FLAG = SPACE
* importing RETCODE = RETCODE.
* ELSE.
* CALL METHOD WP_REF->REPLACE
* EXPORTING SEARCH_STRING = SEARCH
* POS = '1'
* FLAG = SPACE
* REPLACE_STRING = REPLACE
* importing RETCODE = RETCODE.
* ENDIF.
* CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE EXPORTING TYPE = 'E'.
* FREE WP_REF.
* ELSE.
* CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE EXPORTING TYPE = 'E'.
* ENDIF. WHEN 'EXECM'.
CHECK not document is initial and open_document = true.
CALL METHOD document->execute_macro
EXPORTING macro_string = macro
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. WHEN 'CHANGE'.
CALL METHOD link_server->add_string_item
EXPORTING item_name = 'user'
item_value = user
IMPORTING retcode = retcode. CALL METHOD link_server->add_string_item
EXPORTING item_name = 'company'
item_value = company
IMPORTING retcode = retcode. WHEN 'ADDMBAR'.
CHECK not document is initial and open_document = true.
CALL METHOD document->add_menu_bar EXPORTING name = menubar
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. WHEN 'ADDMENU'.
CHECK not document is initial and open_document = true.
CALL METHOD document->add_menu_popup
EXPORTING name = menu
menu_bar_name = menubar
insert_before_popup = 1
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. WHEN 'ADDITEM'.
DATA: position(256).
CHECK not document is initial.
CALL METHOD document->add_menu_item EXPORTING
item_name = menuitem
menu_bar_name = menubar
menu_popup_name = menu
insert_before_item = 0
item_macro = event
IMPORTING retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'. * just for straight ole automation
* data: document_cntl_handle type cntl_handle.
* include ole2incl.
* CALL METHOD DOCUMENT->GET_DOCUMENT_HANDLE
* IMPORTING HANDLE = DOCUMENT_CNTL_HANDLE
* RETCODE = RETCODE.
* CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE EXPORTING TYPE = 'E'.
* CALL METHOD OF DOCUMENT_CNTL_HANDLE-OBJ .... ENDCASE. ENDMODULE. " USER_COMMAND_0100 INPUT *---------------------------------------------------------------------*
* FORM REFRESH_LINKS *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM refresh_links.
IF not link_server is initial. CALL METHOD link_server->add_string_item
EXPORTING item_name = 'Project Name' "#EC NOTEXT
item_value = project_name
no_flush = 'X'
IMPORTING retcode = retcode. CALL METHOD link_server->add_string_item
EXPORTING item_name = 'Topic' "#EC NOTEXT
item_value = project_topic
no_flush = 'X'
IMPORTING retcode = retcode. CALL METHOD link_server->add_string_item
EXPORTING item_name = 'Department' "#EC NOTEXT
item_value = department
no_flush = 'X'
IMPORTING retcode = retcode. CALL METHOD link_server->add_string_item
EXPORTING item_name = 'Author' "#EC NOTEXT
item_value = author
no_flush = 'X'
IMPORTING retcode = retcode. CALL METHOD link_server->add_string_item
EXPORTING item_name = 'Distribution List' "#EC NOTEXT
item_value = distr_list
no_flush = 'X'
IMPORTING retcode = retcode. CALL METHOD link_server->add_string_item
EXPORTING item_name = 'User' "#EC NOTEXT
item_value = user
no_flush = 'X'
IMPORTING retcode = retcode. CALL METHOD link_server->add_string_item
EXPORTING item_name = 'Company' "#EC NOTEXT
item_value = company
no_flush = 'X'
IMPORTING retcode = retcode. DATA: int TYPE i VALUE 100.
CALL METHOD link_server->add_string_item
EXPORTING item_name = 'Number' "#EC NOTEXT
item_value = int
no_flush = 'X'
IMPORTING retcode = retcode. DATA: date TYPE d VALUE '19961231'.
CALL METHOD link_server->add_string_item
EXPORTING item_name = 'Date' "#EC NOTEXT
item_value = date
no_flush = ' '
IMPORTING retcode = retcode. REFRESH points.
points-proposal = proposal.
points-lastname = author.
points-comment = comment.
APPEND points.
points-proposal = 'Second Proposal'.
points-lastname = 'Neuendorf'. "#EC NOTEXT
points-comment = '017299'.
APPEND points.
points-proposal = 'Third Proposal'.
points-lastname = 'Kolb'. "#EC NOTEXT
points-comment = '004711'.
APPEND points.
points-proposal = 'Conclusion'.
points-lastname = 'Kretschmer'. "#EC NOTEXT
points-comment = '000001'.
APPEND points. CALL METHOD link_server->add_table_item2
EXPORTING item_name = 'Agenda' "#EC NOTEXT
IMPORTING retcode = retcode
CHANGING data_table = points[]. CLEAR item_url.
CLEAR descr.
descr-document_name = 'RTF Logo'. "#EC NOTEXT
descr-document_id = 'DEMOWORD97RTF1'. "#EC NOTEXT PERFORM select_document
CHANGING descr-document_id
document_format
doc_url
document_mimetype.
item_url = doc_url.
SPLIT document_mimetype AT delimiter INTO data_type data_subtype.
CALL METHOD link_server->add_binary_item
EXPORTING item_name = 'RTF Item' "#EC NOTEXT
table_url = item_url
data_type = soi_type_application
data_subtype = soi_subtype_rtf
IMPORTING retcode = retcode. CLEAR: item_url.
CLEAR descr.
descr-document_name = 'SAP LOGO'.
descr-document_id = 'DEMOWORD97SAPLOGO'. PERFORM select_document
CHANGING descr-document_id
document_format
doc_url
document_mimetype.
item_url = doc_url.
SPLIT document_mimetype AT delimiter INTO data_type data_subtype.
CALL METHOD link_server->add_binary_item
EXPORTING item_name = 'SAPLogo'
item_title = 'SAP Logo' "#EC NOTEXT
table_url = item_url
data_type = soi_type_image
data_subtype = soi_subtype_gif
IMPORTING retcode = retcode. ENDIF.
ENDFORM. *---------------------------------------------------------------------*
* FORM SAVE_DOCUMENT *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> DOC_TABLE *
* --> DO_ASK *
* --> DO_RELEASE *
* --> DOC_SIZE *
* --> DOCUMENT *
* --> TO *
* --> I_OI_DOCUMENT_PROXY *
* --> RETCODE *
*---------------------------------------------------------------------*
FORM save_document TABLES doc_table TYPE table
USING do_ask TYPE c do_release TYPE c
CHANGING doc_size TYPE i
document TYPE REF TO i_oi_document_proxy
retcode TYPE t_oi_ret_string. DATA: is_closed TYPE i, answer TYPE c, has_changed TYPE i. CALL METHOD document->is_destroyed IMPORTING ret_value = is_closed. IF is_closed is initial.
CALL METHOD document->close_document
EXPORTING do_save = 'X'
IMPORTING has_changed = has_changed
retcode = retcode.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
ENDIF. IF not has_changed is initial.
IF not do_ask is initial.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Office Integration Demo'(oid)
text_question = 'Save Document?'(sav)
display_cancel_button = ' '
IMPORTING
answer = answer.
ELSE.
answer = '1'.
ENDIF. IF answer eq '1'.
CALL METHOD document->save_document_to_table
IMPORTING retcode = retcode
CHANGING document_table = doc_table[]
document_size = doc_size.
CALL METHOD c_oi_errors=>show_message EXPORTING type = 'E'.
ENDIF.
ENDIF. IF not do_release is initial.
CALL METHOD document->release_document
IMPORTING retcode = retcode.
ENDIF.
ENDFORM.
*=======================================================================
*=======================================================================
FORM select_document
CHANGING document_id TYPE c
document_format TYPE c
doc_url TYPE t_url
document_mimetype TYPE bapicompon-mimetype. * Tables and WAs:
DATA: doc_signature TYPE sbdst_signature,
wa_doc_signature LIKE LINE OF doc_signature,
doc_components TYPE sbdst_components,
wa_doc_components LIKE LINE OF doc_components,
doc_uris TYPE sbdst_uri,
wa_doc_uris LIKE LINE OF doc_uris.
* IDs:
DATA: doc_classname TYPE sbdst_classname VALUE 'SOFFICEINTEGRATION',
doc_classtype TYPE sbdst_classtype VALUE 'OT',
doc_object_key TYPE sbdst_object_key VALUE 'SOFFICEINTEGRATION',
doc_mimetype LIKE bapicompon-mimetype.
*----------------------------------------------------------------------- CLEAR: wa_doc_signature, wa_doc_components, wa_doc_uris.
REFRESH: doc_signature, doc_components, doc_uris. wa_doc_signature-prop_name = 'DESCRIPTION'.
wa_doc_signature-prop_value = descr-document_id.
APPEND wa_doc_signature TO doc_signature. CALL METHOD bds_instance->get_info
EXPORTING classname = doc_classname
classtype = doc_classtype
object_key = doc_object_key
CHANGING components = doc_components
signature = doc_signature
EXCEPTIONS nothing_found = 1
error_kpro = 2
internal_error = 3
parameter_error = 4
not_authorized = 5
not_allowed = 6.
IF sy-subrc ne 0 and sy-subrc ne 1.
MESSAGE e016.
ENDIF.
IF sy-subrc = 1.
MESSAGE e017.
ENDIF. CALL METHOD bds_instance->get_with_url
EXPORTING classname = doc_classname
classtype = doc_classtype
object_key = doc_object_key
CHANGING uris = doc_uris
signature = doc_signature
EXCEPTIONS nothing_found = 1
error_kpro = 2
internal_error = 3
parameter_error = 4
not_authorized = 5
not_allowed = 6.
IF sy-subrc ne 0 and sy-subrc ne 1.
MESSAGE e016.
ENDIF.
IF sy-subrc = 1.
MESSAGE e017.
ENDIF. READ TABLE doc_components INTO wa_doc_components INDEX 1.
READ TABLE doc_uris INTO wa_doc_uris INDEX 1.
doc_mimetype = wa_doc_components-mimetype.
doc_url = wa_doc_uris-uri. CASE doc_mimetype.
WHEN 'application/x-rtf' OR 'text/rtf'.
document_format = soi_docformat_rtf.
WHEN 'application/x-oleobject'.
document_format = soi_docformat_compound.
WHEN 'text/plain'.
document_format = soi_docformat_text.
WHEN OTHERS.
document_format = soi_docformat_native.
ENDCASE. ENDFORM.
*=======================================================================
*=======================================================================
FORM select_and_load_document
TABLES documents
USING dialog_title TYPE c
CHANGING document_type TYPE c
document_format TYPE c
doc_url TYPE t_url.
* Tables and WAs:
DATA: doc_signature TYPE sbdst_signature,
wa_doc_signature LIKE LINE OF doc_signature,
doc_components TYPE sbdst_components,
wa_doc_components LIKE LINE OF doc_components,
doc_properties TYPE sbdst_properties,
wa_doc_properties LIKE LINE OF doc_properties,
doc_uris TYPE sbdst_uri,
wa_doc_uris LIKE LINE OF doc_uris.
* IDs:
DATA: doc_classname TYPE sbdst_classname VALUE 'SOFFICEINTEGRATION',
doc_classtype TYPE sbdst_classtype VALUE 'OT',
doc_object_key TYPE sbdst_object_key VALUE 'SOFFICEINTEGRATION',
doc_mimetype LIKE bapicompon-mimetype.
*----------------------------------------------------------------------- DATA: field_desc LIKE rsvbfidesc OCCURS 1 WITH HEADER LINE.
DATA: l_nr LIKE sy-tabix. REFRESH field_desc.
field_desc-fieldnum = 1.
field_desc-display = 'X'.
APPEND field_desc. l_nr = 0.
CALL FUNCTION 'RS_VALUES_BOX'
EXPORTING
left_upper_col = 5
left_upper_row = 5
pagesize = 10
title = dialog_title
IMPORTING
linenumber = l_nr
TABLES
field_desc = field_desc
value_tab = documents
EXCEPTIONS
OTHERS = 1. IF sy-subrc eq 0 and l_nr ne 0.
READ TABLE documents INDEX l_nr INTO descr.
IF sy-subrc eq 0.
CLEAR: wa_doc_signature, wa_doc_components, wa_doc_uris.
REFRESH: doc_signature, doc_components, doc_uris. wa_doc_signature-prop_name = 'DESCRIPTION'.
wa_doc_signature-prop_value = descr-document_id.
APPEND wa_doc_signature TO doc_signature. CALL METHOD bds_instance->get_info
EXPORTING classname = doc_classname
classtype = doc_classtype
object_key = doc_object_key
CHANGING components = doc_components
signature = doc_signature
EXCEPTIONS nothing_found = 1
error_kpro = 2
internal_error = 3
parameter_error = 4
not_authorized = 5
not_allowed = 6.
IF sy-subrc ne 0 and sy-subrc ne 1.
MESSAGE e016.
ENDIF.
IF sy-subrc = 1.
MESSAGE e017.
ENDIF. CALL METHOD bds_instance->get_with_url
EXPORTING classname = doc_classname
classtype = doc_classtype
object_key = doc_object_key
CHANGING uris = doc_uris
signature = doc_signature
EXCEPTIONS nothing_found = 1
error_kpro = 2
internal_error = 3
parameter_error = 4
not_authorized = 5
not_allowed = 6.
IF sy-subrc ne 0 and sy-subrc ne 1.
MESSAGE e016.
ENDIF.
IF sy-subrc = 1.
MESSAGE e017.
ENDIF. READ TABLE doc_components INTO wa_doc_components INDEX 1.
READ TABLE doc_uris INTO wa_doc_uris INDEX 1.
doc_mimetype = wa_doc_components-mimetype.
document_mimetype = doc_mimetype.
doc_url = wa_doc_uris-uri. CASE doc_mimetype.
WHEN 'application/x-rtf' OR 'text/rtf'.
document_format = soi_docformat_rtf.
WHEN 'application/x-oleobject'.
document_format = soi_docformat_compound.
WHEN 'text/plain'.
document_format = soi_docformat_text.
WHEN OTHERS.
document_format = soi_docformat_native.
ENDCASE. ENDIF.
ENDIF. ENDFORM.
*=======================================================================
*----------------------------------------------------------------------*
* INCLUDE RDEMOWORD97INTEGRATIONTOP *
*----------------------------------------------------------------------*
REPORT SAPRDEMOWORD97INTEGRATION MESSAGE-ID DEMOOFFICEINTEGRATIO. CONSTANTS: TRUE VALUE 1, FALSE VALUE 0. TYPES: BEGIN OF DOCUMENT_DESCR,
DOCUMENT_NAME(40), DOCUMENT_ID(64),
END OF DOCUMENT_DESCR. TYPES: DOCUMENT_LIST TYPE DOCUMENT_DESCR OCCURS 0. TYPES: T_URL LIKE BAPIURI-URI. * dynpro 100 fields:
DATA: TEMPLATE(30),SEARCH(19), USER(19), COMPANY(19),
MACRO(19), MENU(19), MENUITEM(19),MENUBAR(19), EVENT(19).
DATA: REPLACE LIKE SEARCH. DATA: CURRENTMENUBAR LIKE MENUBAR, CURRENTMENU LIKE MENU,
OPEN_DOCUMENT(1).
DATA: ITEM_URL TYPE T_URL. DATA: PROJECT_NAME(80) VALUE 'Office Integration', "#EC NOTEXT
PROJECT_TOPIC(80) VALUE 'Word97 Integration', "#EC NOTEXT
DEPARTMENT(40) VALUE 'SAP AG', "#EC NOTEXT
AUTHOR(30) VALUE 'Ehre', "#EC NOTEXT
DISTR_LIST(30) VALUE 'SAP01',
PROPOSAL(40), COMMENT(128). SET SCREEN 100. TYPE-POOLS: SBDST. INCLUDE OFFICEINTEGRATIONINCLUDE. DATA: FCODE LIKE SY-UCOMM.
*----------------------------------------------------------------------*
* INCLUDE OFFICEINTEGRATIONINCLUDE *
*----------------------------------------------------------------------* TYPE-POOLS: SOI.
TYPE-POOLS: CNDP. CLASS C_OI_ERRORS DEFINITION LOAD.
CLASS CL_GUI_CFW DEFINITION LOAD. INCLUDE OFFICEINTEGRATIONINTERFACES.
INCLUDE OFFICEINTEGRATIONOLECREATOR.
INCLUDE OFFICEINTEGRATIONOLECLASSESIMP.
*----------------------------------------------------------------------*
* INCLUDE OFFICEINTEGRATIONINTERFACES *
*----------------------------------------------------------------------* TYPES: T_OI_RET_STRING TYPE SOI_RET_STRING,
T_OI_CUSTOM_PARAM TYPE SOI_CUSTOM_PARAM.
TYPES: T_OI_MESSAGE_PARAM(50) TYPE C.
TYPES: T_OI_PROXY_ERROR_CODE TYPE I. TYPES: T_OI_FIELDS_TABLE TYPE STANDARD TABLE OF RFC_FIELDS.
TYPES: T_OI_PROPERTIES_TABLE TYPE STANDARD TABLE OF DPPROPS. CLASS CL_GUI_CFW DEFINITION LOAD. INTERFACE I_OI_DOCUMENT_FACTORY.
CONSTANTS:
DOCUMENT_FORMAT_COMPOUND(3) TYPE C VALUE 'OLE',
DOCUMENT_FORMAT_NATIVE(6) TYPE C VALUE 'NATIVE',
DOCUMENT_FORMAT_RTF(3) TYPE C VALUE 'RTF',
DOCUMENT_FORMAT_TEXT(4) TYPE C VALUE 'TEXT'. METHODS: START_FACTORY
IMPORTING R3_APPLICATION_NAME TYPE C
VALUE(REP_ID) TYPE SY-REPID DEFAULT SY-REPID
VALUE(DYNPRO_NR) TYPE SY-DYNNR
DEFAULT SY-DYNNR
REGISTER_ON_CLOSE_EVENT TYPE C DEFAULT ' '
REGISTER_ON_CUSTOM_EVENT TYPE C DEFAULT ' '
VALUE(NO_FLUSH) TYPE C DEFAULT ' '
EXPORTING RETCODE TYPE SOI_RET_STRING
ERROR TYPE REF TO I_OI_ERROR. METHODS: STOP_FACTORY
IMPORTING EXIT_CONTROL_MANAGER TYPE C DEFAULT ' '
VALUE(NO_FLUSH) TYPE C DEFAULT ' '
EXPORTING RETCODE TYPE SOI_RET_STRING
ERROR TYPE REF TO I_OI_ERROR. METHODS: LINK_FACTORY
IMPORTING VALUE(REP_ID) TYPE SY-REPID
VALUE(DYNPRO_NR) TYPE SY-DYNNR
VALUE(NO_FLUSH) TYPE C DEFAULT ' '
EXPORTING RETCODE TYPE SOI_RET_STRING
ERROR TYPE REF TO I_OI_ERROR. METHODS: GET_DOCUMENT_PROXY
IMPORTING DOCUMENT_TYPE TYPE C
DOCUMENT_FORMAT TYPE C DEFAULT 'NATIVE'
REGISTER_CONTAINER TYPE C DEFAULT ' '
VALUE(NO_FLUSH) TYPE C DEFAULT ' '
EXPORTING DOCUMENT_PROXY TYPE REF TO I_OI_DOCUMENT_PROXY
RETCODE TYPE SOI_RET_STRING
ERROR TYPE REF TO I_OI_ERROR. METHODS: GET_LINK_SERVER
IMPORTING SERVER_TYPE TYPE C DEFAULT ' '
VALUE(NO_FLUSH) TYPE C DEFAULT ' '
EXPORTING LINK_SERVER TYPE REF TO I_OI_LINK_SERVER
RETCODE TYPE SOI_RET_STRING
ERROR TYPE REF TO I_OI_ERROR. METHODS: GET_TABLE_COLLECTION
IMPORTING VALUE(NO_FLUSH) TYPE C DEFAULT ' '
EXPORTING TABLE_COLLECTION TYPE
REF TO I_OI_TABLE_COLLECTION
RETCODE TYPE SOI_RET_STRING
ERROR TYPE REF TO I_OI_ERROR. METHODS: GET_REGISTERED_DOC_TYPES
IMPORTING INTERFACE_TYPE TYPE C DEFAULT ' '
VALUE(NO_FLUSH) TYPE C DEFAULT ' '
EXPORTING DESCR_LIST TYPE SOI_DOCUMENT_TYPE_DESCR_LIST
RETCODE TYPE SOI_RET_STRING
ERROR TYPE REF TO I_OI_ERROR. METHODS: CHECK_REGISTERED_DOC_TYPES
IMPORTING VALUE(NO_FLUSH) TYPE C DEFAULT ' '
EXPORTING ERROR TYPE REF TO I_OI_ERROR
CHANGING DESCR_LIST TYPE SOI_DOCUMENT_TYPE_DESCR_LIST
RETCODE TYPE SOI_RET_STRING.
ENDINTERFACE.
*----------------------------------------------------------------------*

CLASS C_OI_OLE_CONTROL_CREATOR DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: GET_OLE_CONTAINER_CONTROL
EXPORTING CONTROL TYPE REF TO I_OI_OLE_CONTAINER_CONTROL
RETCODE TYPE SOI_RET_STRING
ERROR TYPE REF TO I_OI_ERROR.
ENDCLASS. CLASS C_OI_FACTORY_CREATOR DEFINITION.
PUBLIC SECTION.
CONSTANTS:
FACTORY_TYPE_OLE(3) TYPE C VALUE 'OLE',
FACTORY_TYPE_PORTABLE(8) TYPE C VALUE 'PORTABLE'. CLASS-METHODS: GET_DOCUMENT_FACTORY
IMPORTING FACTORY_TYPE TYPE C DEFAULT 'PORTABLE'
EXPORTING FACTORY TYPE REF TO I_OI_DOCUMENT_FACTORY
RETCODE TYPE SOI_RET_STRING
ERROR TYPE REF TO I_OI_ERROR.
ENDCLASS. CLASS C_OI_OLE_DOCUMENT_FACTORY DEFINITION.
PUBLIC SECTION.
INTERFACES: I_OI_DOCUMENT_FACTORY. PRIVATE SECTION.
DATA: CONTAINER_CONTROL TYPE REF TO I_OI_OLE_CONTAINER_CONTROL.
ENDCLASS.
*----------------------------------------------------------------------*
* INCLUDE OFFICEINTEGRATIONIMPL *
*----------------------------------------------------------------------* CLASS c_oi_factory_creator IMPLEMENTATION.
METHOD get_document_factory.
* IMPORTING factory_type TYPE c
* EXPORTING factory TYPE REF TO i_oi_document_factory
* retcode TYPE c.
DATA: olefactoryobj TYPE REF TO c_oi_ole_document_factory.
DATA: has_activex,has_javabean. * DATA: WINSYS TYPE OLELOAD-WINSYS.
* determine window system
* CALL FUNCTION 'WS_QUERY'
* EXPORTING QUERY = 'WS'
* IMPORTING RETURN = WINSYS.
* CASE WINSYS.
* WHEN 'WN32'.
* CREATE OBJECT OLEFACTORYOBJ.
* FACTORY = OLEFACTORYOBJ.
* RETCODE = C_OI_ERRORS=>RET_OK.
* WHEN 'JAVA'.
* CREATE OBJECT OLEFACTORYOBJ.
* FACTORY = OLEFACTORYOBJ.
* RETCODE = C_OI_ERRORS=>RET_OK.
* WHEN 'PLAT'.
* CREATE OBJECT OLEFACTORYOBJ.
* FACTORY = OLEFACTORYOBJ.
* RETCODE = C_OI_ERRORS=>RET_OK.
* WHEN OTHERS.
* RETCODE = C_OI_ERRORS=>RET_ERROR.
* ENDCASE. CALL FUNCTION 'GUI_HAS_ACTIVEX'
IMPORTING
return = has_activex. CALL FUNCTION 'GUI_HAS_JAVABEANS'
IMPORTING
return = has_javabean. IF ( NOT has_activex IS INITIAL ) OR
( NOT has_javabean IS INITIAL ).
CREATE OBJECT olefactoryobj.
factory = olefactoryobj.
retcode = c_oi_errors=>ret_ok.
ELSE.
retcode = c_oi_errors=>ret_error.
ENDIF. CALL METHOD c_oi_errors=>create_error_for_retcode
EXPORTING retcode = retcode
no_flush = ' '
IMPORTING error = error.
ENDMETHOD.
ENDCLASS. CLASS c_oi_ole_control_creator IMPLEMENTATION.
METHOD get_ole_container_control.
* EXPORTING control TYPE REF TO i_oi_container_control
* retcode TYPE t_oi_ret_string.
DATA: l_control TYPE REF TO i_oi_container_control. CALL METHOD c_oi_container_control_creator=>get_container_control
IMPORTING control = l_control
retcode = retcode
error = error.
control ?= l_control. ENDMETHOD.
ENDCLASS. CLASS c_oi_ole_document_factory IMPLEMENTATION.
METHOD i_oi_document_factory~start_factory.
* IMPORTING r3_application_name TYPE c
* value(rep_id) type sy-repid default sy-repid
* value(dynpro_nr) type sy-dynnr
* default sy-dynnr
* register_on_close_event type c default ' '
* register_on_custom_event type c default ' '
* RETURNING value(retcode) TYPE c.
IF container_control IS INITIAL.
CALL METHOD c_oi_ole_control_creator=>get_ole_container_control
IMPORTING control = container_control
retcode = retcode.
IF retcode EQ c_oi_errors=>ret_ok.
CALL METHOD container_control->init_control
EXPORTING r3_application_name = r3_application_name
inplace_mode = 0
rep_id = rep_id
shell_style = cl_gui_control=>ws_child
dynpro_nr = dynpro_nr
parent = cl_gui_container=>default_screen
register_on_close_event = register_on_close_event
register_on_custom_event =
register_on_custom_event
no_flush = no_flush
IMPORTING retcode = retcode
error = error.
ELSE.
CALL METHOD c_oi_errors=>create_error_for_retcode
EXPORTING retcode = retcode
no_flush = no_flush
IMPORTING error = error.
ENDIF.
ELSE. " already created
retcode = c_oi_errors=>ret_ok.
CALL METHOD c_oi_errors=>create_error_for_retcode
EXPORTING retcode = retcode
no_flush = no_flush
IMPORTING error = error.
ENDIF.
ENDMETHOD. METHOD i_oi_document_factory~stop_factory.
* IMPORTING exit_control_manager TYPE c DEFAULT 'X'
* RETURNING value(retcode) TYPE c.
IF NOT container_control IS INITIAL.
CALL METHOD container_control->destroy_control
EXPORTING no_flush = no_flush
IMPORTING retcode = retcode
error = error.
ELSE. " already destroyed
retcode = c_oi_errors=>ret_ok.
CALL METHOD c_oi_errors=>create_error_for_retcode
EXPORTING retcode = retcode
no_flush = no_flush
IMPORTING error = error.
ENDIF.
ENDMETHOD. METHOD i_oi_document_factory~link_factory.
* IMPORTING value(rep_id) LIKE sy-repid
* value(dynpro_nr) LIKE sy-dynnr
* RETURNING value(retcode) TYPE t_oi_ret_string.
IF NOT container_control IS INITIAL.
CALL METHOD container_control->link_control
EXPORTING rep_id = rep_id
dynpro_nr = dynpro_nr
no_flush = no_flush
IMPORTING retcode = retcode
error = error.
ELSE.
retcode = c_oi_errors=>ret_object_not_initialized.
CALL METHOD c_oi_errors=>create_error_for_retcode
EXPORTING retcode = retcode
no_flush = no_flush
IMPORTING error = error.
ENDIF.
ENDMETHOD. METHOD i_oi_document_factory~get_document_proxy.
* IMPORTING document_type TYPE c
* EXPORTING document_proxy TYPE
* REF TO i_oi_document_proxy
* retcode TYPE c.
IF NOT container_control IS INITIAL.
CALL METHOD container_control->get_document_proxy
EXPORTING document_type = document_type
document_format = document_format
register_container = register_container
no_flush = no_flush
IMPORTING document_proxy = document_proxy
retcode = retcode
error = error.
ELSE.
retcode = c_oi_errors=>ret_object_not_initialized.
CALL METHOD c_oi_errors=>create_error_for_retcode
EXPORTING retcode = retcode
no_flush = no_flush
IMPORTING error = error.
ENDIF.
ENDMETHOD. METHOD i_oi_document_factory~get_link_server.
* IMPORTING server_type TYPE c DEFAULT ' '
* EXPORTING link_server TYPE REF TO i_oi_link_server
* retcode TYPE t_oi_ret_string.
IF NOT container_control IS INITIAL.
CALL METHOD container_control->get_link_server
EXPORTING server_type = server_type
no_flush = no_flush
IMPORTING link_server = link_server
retcode = retcode
error = error.
ELSE.
retcode = c_oi_errors=>ret_object_not_initialized.
CALL METHOD c_oi_errors=>create_error_for_retcode
EXPORTING retcode = retcode
no_flush = no_flush
IMPORTING error = error.
ENDIF.
ENDMETHOD. METHOD i_oi_document_factory~get_table_collection.
* EXPORTING table_collection TYPE
* REF TO i_oi_table_collection
* retcode TYPE t_oi_ret_string.
IF NOT container_control IS INITIAL.
CALL METHOD container_control->get_table_collection
EXPORTING no_flush = no_flush
IMPORTING table_collection = table_collection
retcode = retcode
error = error.
ELSE.
retcode = c_oi_errors=>ret_object_not_initialized.
CALL METHOD c_oi_errors=>create_error_for_retcode
EXPORTING retcode = retcode
no_flush = no_flush
IMPORTING error = error.
ENDIF.
ENDMETHOD. METHOD i_oi_document_factory~get_registered_doc_types.
* IMPORTING interface_type TYPE c DEFAULT ' '
* EXPORTING descr_list TYPE t_oi_interface_descr_list
* retcode TYPE t_oi_ret_string.
IF NOT container_control IS INITIAL.
CALL METHOD container_control->get_registered_doc_types
EXPORTING interface_type = interface_type
no_flush = no_flush
IMPORTING descr_list = descr_list
retcode = retcode
error = error.
ELSE.
retcode = c_oi_errors=>ret_object_not_initialized.
CALL METHOD c_oi_errors=>create_error_for_retcode
EXPORTING retcode = retcode
no_flush = no_flush
IMPORTING error = error.
ENDIF.
ENDMETHOD. METHOD i_oi_document_factory~check_registered_doc_types.
* CHANGING descr_list TYPE t_oi_interface_descr_list
* retcode TYPE t_oi_ret_string.
IF NOT container_control IS INITIAL.
CALL METHOD container_control->check_registered_doc_types
EXPORTING no_flush = no_flush
IMPORTING error = error
CHANGING descr_list = descr_list
retcode = retcode.
ELSE.
retcode = c_oi_errors=>ret_object_not_initialized.
CALL METHOD c_oi_errors=>create_error_for_retcode
EXPORTING retcode = retcode
no_flush = no_flush
IMPORTING error = error.
ENDIF.
ENDMETHOD.
ENDCLASS.
***INCLUDE OLE2INCL.
TYPE-POOLS OLE2 .

最新文章

  1. app上架流程的整理
  2. [ActionScript 3.0] 分页排版
  3. Tomcat6.0 管理器配置
  4. JS中的_proto_(2)
  5. LeetCode() Ugly Number II 背下来!
  6. 利用sourcemap来调试sass
  7. C#编写的多生产者多消费者同步问题
  8. Windows 7 无线网络故障
  9. SpannableString的一个奇怪的问题
  10. centos 添加epel、remi仓库和ELRepo仓库
  11. 枚举for/in
  12. HTNL5新增标签
  13. cp复制文件到多个目录下及强制覆盖
  14. Entity Framework Core Like 查询揭秘
  15. 201521123065《java程序设计》第10周学习总结
  16. NYOJ 1248 海岛争霸(Dijkstra变形——最短路径最大权值)
  17. vue.js实战——.native修饰符
  18. 2018-2019-2 20165316 《网络对抗技术》 Exp6 信息搜集与漏洞扫描
  19. 解决VS Code使用code runner开发Python乱码问题
  20. What's the difference between ConcurrentHashMap and Collections.synchronizedMap(Map)?

热门文章

  1. 邮件任务-springboot
  2. STL空间分配器源码分析(三)pool_allocator
  3. Abp 实现通过手机号注册用户
  4. 论文翻译:2018_LSTM剪枝_Learning intrinsic sparse structures within long short-term memory
  5. 几个i的幂的累加公式1^2+2^2+3^2 2~5
  6. python @符号用法的简单理解
  7. 关于visualvm无法监控本地java进程
  8. 关于 background-image 渐变gradient()那些事!
  9. WorkCount
  10. [AcWing 796] 子矩阵的和