Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with WordDocument generator (.docx)

deepan_v_s
Active Participant
0 Kudos

Hi All,

We are using a Document generator application which basically creates word document.

First it reads the document template (Which is configured in SAP), it check the placeholders and replaces the placeholders with actual values and generates the document.

Now the issue is, Business has requested a small change in the template. The changes were done in the template (in DEV) and tested.

The generated document doesn't replace the placeholders with the actual values. (No program changes were made , only template is changed)

However the same application works fine in Quality and Production (Changes to the template is not transported to these systems)

So it's quite clear that the issue occurs due the change in the word template.

I have debugged it in Dev and Quality, and the reason for the issue is the placeholders are not read from the template (in Dev) and in Quality it is being read and generates the correct document.

Can any please suggest any solution for this issue ?

Note: This was the process which was working fine earlier (Business will request changes to the template and functional will be making the required changes and it has worked in the past).

Recently the system is Upgraded from 4.7 to ECC. And this is the first change to the template since upgrade. This might be the cause as well (SAP has changed something in document generator classes).

Please find the below code which is used to identify the placeholders.

METHOD find_fields .
*-Local Data------------------------------------------------
  CONSTANTS:
        lc_mergefield    TYPE string VALUE 'MERGEFIELD', "#EC NOTEXT
        lc_field         TYPE string VALUE 'fldSimple', "#EC NOTEXT
        lc_field_direct  TYPE string VALUE 'instrText',"#EC NOTEXT
        lc_attribute     TYPE string VALUE 'instr'."#EC NOTEXT


  DATA: lo_iterator      TYPE REF TO if_ixml_node_iterator,
        lo_node          TYPE REF TO if_ixml_node,
        lo_element       TYPE REF TO if_ixml_element,
        l_node_name      TYPE string,
        l_node_ns        TYPE string,
        l_attribute(100) TYPE c,
        ls_result        LIKE LINE OF ct_fields,
        ls_cache         LIKE LINE OF gt_element_cache,
        l_merge          TYPE string,
        l_dummy          TYPE string.

  FIELD-SYMBOLS:
       <ls_cache>   LIKE LINE OF gt_element_cache.

*-Method Implementation-------------------------------------
************************************************************
* Step 1: Iterate over all nodes and look for Fields
************************************************************
  lo_iterator = go_document->create_iterator( ).
  lo_node = lo_iterator->get_next( ).

  WHILE lo_node IS NOT INITIAL.
    l_node_name = lo_node->get_name( ).
    l_node_ns   = lo_node->get_namespace_uri( ).

*   use only simple nodes here
    IF ( l_node_name = lc_field              ) AND
       ( l_node_ns = gc_namespace_wordml_2003 ).

      lo_element ?= lo_node.
      l_attribute = lo_element->get_attribute_ns(
                  name = lc_attribute
                  uri  = gc_namespace_wordml_2003 ).

*     trim the string
      CONDENSE l_attribute.
*     look for something like MERGEFIELD NAME XXXXX
      SPLIT l_attribute
            AT space
            INTO l_merge ls_cache-name l_dummy.

      IF ( l_merge = lc_mergefield ).
        ls_cache-element = lo_element.
*        INSERT ls_cache INTO TABLE gt_element_cache.
        APPEND ls_cache TO gt_element_cache.
      ENDIF.                                      " lv_merge
    ENDIF.                  " l_node_name = lc_field AND ...

    lo_node = lo_iterator->get_next( ).
  ENDWHILE.                         " lo_node IS NOT INITIAL


************************************************************
* Step 2: Add Nodes to result
************************************************************
  SORT gt_element_cache BY name.


  LOOP AT gt_element_cache ASSIGNING <ls_cache>.
    AT NEW name.      ls_result-name = <ls_cache>-name.
      INSERT ls_result INTO TABLE ct_fields.
    ENDAT.                                       " NEW name
  ENDLOOP.                            " AT gt_element_cache


ENDMETHOD.

Many thanks in advance !!!

Regards,

Deepan V Swaminathan.

6 REPLIES 6

Jelena
Active Contributor

I've never heard of "Document generator application" in SAP and Google search for it does not find SAP solutions with such name (except for some functionality in HR). But if this is a standard SAP functionality then this question should be directed to the SAP Support: https://launchpad.support.sap.com/

0 Kudos

Hi Jelena!

I think Deepan talks about Desktop Office Integration (DOI) and it's methods in ABAP. They have their own program which is creating a Word document based on a template (likely situated in SMW0) with help of DOI, that's why he refers to it as "Document generator application".

Have a nice day,

Anton

deepan_v_s
Active Participant
0 Kudos

Hi Anton,

Yeah you are right..It's Document office integration.

Regards,

Deepan Swaminathan.

0 Kudos

Deepan,

Have You tried my suggestion (look under Your question)?

Does the old template from Q-system work correctly?

--

Anton

Sandra_Rossi
Active Contributor

I don't think it's DOI.

I think it's WWI in EH&S (Windows Wordprocessor Integration -> cf http://help.sap.com/saphelp_erp60_sp/helpdata/en/a7/28725e0a6c11d28a220000e829fbbd/frameset.htm ).

Other people want to play?

AntonKozhin
Participant
0 Kudos

Hi Deepan,

First of all, let's check that it has nothing to do with new SAP ECC version. My suggestion is following:

  1. Export Word template from DEV-system to Your local PC as TemplD.
  2. Export Word template from QAS-system to Your local PC as TemplQ.
  3. Import Word template TemplQ (from QAS) to DEV system replacing source template.

As we know, in QAS system Your template is working right (but without recent changes, of course), and if new template works fine in DEV system, then the problem has nothing to do with the Upgrade. Otherwise, if even an old template still doesn't work in DEV system - it could point to the upgrade problems. But I think that Your old template should work correctly in Your DEV system.

Let me know, when You check it. I will try to think over what mistakes could be made during Word template adjustment.