Skip to Content
1
Dec 13, 2017 at 01:39 PM

How to create WORD template (add SAP OLE Link to document)?

1532 Views Last edit Dec 13, 2017 at 03:28 PM 3 rev

Hello everyone!


After quite deep searching I've reached a wall and cannot move any further :(

I know coding procedure on how to initialize DOI. Then how to add mapping for links in template, load template in RAW data and open the document with changed values. But..

Problem: How to prepare such WORD document template? Document is quite complicated and I have it already localy but without variables (SAP OLE Links, attached screen from MS WORD from SAP Demo template). So the best option would be to input in specific places localy and then upload template and save it as ITAB to RAW in SAP DB table.

SAP demo template: here

If someone would seek for procedure on how to use RAW template, change variables in it and open doc here it is (shorten version):

FORM doi_initialize  
   USING    p_cust_cont_name
   CHANGING po_control   TYPE REF TO i_oi_container_control
            po_document  TYPE REF TO i_oi_document_proxy
            po_link_server   TYPE REF TO i_oi_link_server
           po_gui_cust_container TYPE REF TO cl_gui_custom_container.

DATA: l_retcode TYPE soi_ret_string.

    CREATE OBJECT po_gui_cust_container
      EXPORTING
        container_name   = p_cust_cont_name.

    CALL METHOD c_oi_container_control_creator=>get_container_control
      IMPORTING
        control = po_control
        retcode = l_retcode.

    CALL METHOD po_control->init_control
      EXPORTING
        r3_application_name = 'File export'(010)
        inplace_enabled     = 'X'
        parent              = po_gui_cust_container
      IMPORTING
        retcode             = l_retcode.

  CALL METHOD po_control->get_document_proxy
    EXPORTING
      document_type   = soi_doctype_word_document "'Word.Document'
      document_format = soi_docformat_compound "'OLE'
    IMPORTING
      document_proxy  = po_document
      retcode         = l_retcode.

  CALL METHOD po_control->get_link_server
    IMPORTING
      link_server = po_link_server
      retcode     = l_retcode.
 
 CALL METHOD po_link_server->start_link_server [...]
ENDFORM.       " DOI_INITIALIZE


FORM export_values2word 
   USING  p_blart
          po_link_server TYPE REF TO i_oi_link_server
          ps_flds_value TYPE zfm_res_add_data_mswordole_trg.

  DATA: l_retcode TYPE soi_ret_string.
**************variable 1 in WORD

  CALL METHOD po_link_server->add_string_item
  EXPORTING
    item_name  = 'Z_var1'
    item_value = lv_char "some char values
  IMPORTING
    retcode    = l_retcode

ENDFORM.           " WRITE_TEXT_TO_DB

FORM doi_open_document
   USING  ps_all_data_hdr TYPE zfm_res_add_data_msword2_src
          po_document TYPE REF TO i_oi_document_proxy.

  DATA: l_docsize TYPE i.
  DATA: ls_raw TYPE raw255.
  DATA: lt_raw TYPE STANDARD TABLE OF raw255.
  DATA: ls_doc_tmpl TYPE zfm_add_doc_tmpl.
  DATA: lt_doc_tmpl TYPE STANDARD TABLE OF zfm_add_doc_tmpl.
  DATA: l_template_versi(2) TYPE c.
  DATA: l_retcode TYPE soi_ret_string.

"[....] read RAW of template from DB to lt_raw and l_docsize

  CALL METHOD po_document->open_document_from_table
    EXPORTING
      document_size    = l_docsize
      document_table   = lt_raw
      no_flush         = ' '
      open_inplace     = 'X'
    IMPORTING
       retcode          = l_retcode.
ENDFORM. 

Attachments

beztytułu.png (10.8 kB)