Skip to Content

Issue with WordDocument generator (.docx)

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------------------------------------------------
        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.

       <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( ).

    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


Many thanks in advance !!!


Deepan V Swaminathan.

Add a comment
10|10000 characters needed characters exceeded

  • 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.

Related questions

1 Answer

  • Posted on Oct 17, 2016 at 05:39 PM

    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:

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.