Skip to Content
-2
Oct 17, 2016 at 03:02 PM

Issue with WordDocument generator (.docx)

153 Views Last edit Oct 17, 2016 at 03:54 PM 2 rev

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.