CRM and CX Blogs by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
cancel
Showing results for 
Search instead for 
Did you mean: 
JerryWang
Advisor
Advisor
0 Kudos

In this example, it is described how the data in xml stream with table structure is merged into word template:



The word looks like below after merge:



You should have gone through Understand how the word template is merged with xml data stream - part 1 - Simple structure before you start with table merge.

You could find the template and xml data file used in this example from attachment.

Merge step1 cl_crm_oi_docx_helper=>replace_vars_uuid_with_path


The same as the step in simple structure merge.



Merge step2 add necessary namespace to every node in xml


The same as the step in simple structure merge.



Merge step3 cl_crm_oi_docx_transform_rt=>transform


the formatted template source( uuid replaced with complete path ) and formatted xml data source( n0 namespace added ) are passed into this method.

step3.1 cl_crm_oi_docx_transform_rt=>indicate_tree


The xml node is further enriched with attribute Loopcount and Path, which are especially used for render data with table structure.


See how the xml source looks like after method call:




  • New attribute Path is added for each node.

  • Loopcount: total number of nodes which have the same name as current node

  • Loopid: index of current node


step3.2 cl_crm_oi_docx_transform_rt=>update_payload_from_addinsch




This method will create a new attribute sapvartype with value "T" for those node in xml source with table structure:


step3.3 recursively call cl_crm_oi_docx_transform_rt=>process_node_cc




We identify the current node ( n0:Z_JENS_GET_MORE_COMPLEXResponse/n0:ET_ORDER/ ) is a table node by querying attribute sapvartype with value "T":



And we know from the attribute Loopcount added in step 3.1 that currently there are two Item nodes in xml, which means we need to dynamically generate two new rows in the word template to display the table data contained in xml. We can achieve this by cloning the existing row in the word template which contains the mapping information.



the cloning is done in this method:





Have a look at the word template source code after method call:



w:sdt node for table header display:



w:tr ( the first cloned node 😞



w:tr ( the second cloned node 😞



Now the placeholder for table data display is available in word template source. A recursive call is made with iv_node_intable = X to fill cloned table row in word template with table data in xml data file.


The left stuff is the same as the step for simple structure:


1. get the dom element node which is to be filled by each table structure field in xml data file:



2. call set_content_control_value to set the value 0005012366 of node OBJECT_ID in xml data file to the dom element node from the first cloned table row ( lv_loopid_tr = @1 ).



Open the final merged word document:



You should find from document source code that all table row fields whose data are filled from xml data file have a new attribute saprtvalue with value X.