Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182411
Active Participant

What's this all about?

This blog is about my experience in using the Microsoft Word Integration within the Web UI Client Framework. Primarily I use it for own documentation purposes thus I do not want to maintain lots of Word documents on my own storage any more.

In short there are three steps you have to take when using Word templates:

- create the template (Web UI application)

- create data provisioning (by implementing the later mentioned enhancement spot)

- add the function to call your Word template

The target

The business case is to print individual text-heavy letters with less dynamic Content (documents with a lot of dynamic Content (e.g. tables) should be implemented using Adobe Interactive Forms By Adobe).

Development Environment

You can start the development Environment by using the UI Component Workbench and testing the UI component  CRM_OI_TEMPLDSG.

language to English. But you can see this as an exercise to improve your German skills (but you do not receive an certificate :-(). The following screen appears:

type (Objekttyp). This is the classic object type introduced a long time ago with the SAP Business Workflow environment (transaction code SWO1) type delivers the data needed for our Word template. Beside the other self explananing select-options it's important to know that you can administrate different types of templates:

  • Microsoft Office Word ("new" XML based documents, e.g. docx)
  • Microsoft Word (old doc Format)
  • Adobe XML form

The object-type is the base for processing the Microsoft Word templates as the coding of the SAP Standard processing class CL_CRM_OI_T_TEMPLATES_IMPL references this within the method OPEN_DOCUMENT().

You receive a list of all templates available by applying the selection-criteria:

There you can find the functionality to create, edit, copy and delete templates.

Creating a new Word template

Just press the "New"-Button and the following Screen appears:

After filling the gaps it's time to design the layout, this is the next step to proceed. So I thought using the button "start designer" (Designer starten) is the way to do so. But if you press this button Microsoft Word is being opened in an read-only mode - so you cannot modify the document (maybe another feature). You can find this in the following screenshot with the German word "Schreibgeschützt" (this means read-only):

So this is not the way we can edit our new template. Close the Microsoft Word application and you will see the "New" View again. Have a look at the radiobutton "use macros" (Makros verwenden). It seems to be a "feature" that the option to edit the template only is available when "use macros" is set to active.

Now the option for downloading (Button called "Herunterladen") the template appears so we can edit this document locally on our client by using Microsoft Word:

Using merge-fields

Adding dynamic fields to the Word template is very easy. During editing your document just use the "Add Field" function and choose "merge field". Please consider appropiate naming conventions in order to avoid confusing implementations with an outlook on the maintainance in the future.

All these merge-fields have to be accessed and filled within your BadI implementation (method GET_VALUES()).

After you have finished editing the document just use the "upload functionality" (here called "Hochladen", in the screenshot before).

Data provisioning

Now we have a closer look at the data provisioning layer. Therefore it's essential to know the Enhancement-Spot CRM_OFFICE_INT_ENHANCEMENT. This BadI is called before the document is being opened. Thus we need an implementation of this EH-Spot.

The relevant Interface is called IF_EX_CRM_OFFICE_TEMP_BADI. It provides three methods:

Method nameDescription
GET_ATTRIBUTESDefinition of all available field-symbols (placeholders, fields) for use within the Word templates
GET_VALUES

Provide data to the fields

  • Parameter CT_VALUES
    • the most important parameter: you have to fill this key-value-pair with the IDs of your placeholders defined within in your template and fill the values which replace the placeholders
GET_DESC_NAMESnot used, yet

Go to transaction SE18 and open the mentioned enhancement spot and create a new enhancement implementation:

You have to define the implementation's name and assign a composite enhancement-implementation if desired. At least you have to define the class' name. It might be a good approach to copy the pre-delivered sample class:

After creating a new implementation class you first have to focus on the Method GET_ATTRIBUTES().field" in your template.

An implementation could look like this for the example above (merge-field names):


APPEND INITIAL LINE TO ct_attributes[] ASSIGNING <lf_attribute>.
<lf_attribute>-name = |FIRST_NAME|.
<lf_attribute>-description = space.
UNASSIGN <lf_attribute>.
APPEND INITIAL LINE TO ct_attributes[] ASSIGNING <lf_attribute>.
<lf_attribute>-Name = |LAST_NAME|.
<lf_attribute>-description = space.

The next step is to supply the attributes with values. This happens within the method GET_VALUES() which could look like this:


LOOP AT ct_values[] ASSIGNING <lf_value>. "CT_VALUES will be supplied with all the attributes added to ct_attributes[]
CASE <lf_value>-name.
WHEN 'FIRST_NAME'.
<lf_value>-value = lv_first_name. "imagine lv_first_name contains the matching attribute from BOL-model
WHEN 'LAST_NAME'.
...
ENDCASE.
ENDLOOP.

It's recommended to implement the data provisioning logic (access to BOL-model) in a separate class in order to not overload the BadI implementation and be more flexible in the future. Maybe you've got many documents so it's better to practice "separation of concern".

Transport Management


Please keep in mind that Word templates are not connected to transport management automatically. For this you can use the report CRM_KW_TEMPLATE_TRANSPORT or use the SPRO -> CRM -> Basic functions -> Content mgmt. -> Transport template

3 Comments
Labels in this area