MS Office made easy

Some of us have experience with SapScript, SmartForms and PDF based forms. Nevertheless Customers sometime wish to get an MS Office document as soon as it is ‘more familiar’.

We have some options provided by SAP or third party developers. These are:

OLE, DOI both are standard and couple versions of MS Office tools ZWWW as an example or the tool to work with RTF documents.

But let’s compare these technologies:

OLE becomes incredible slow when operating huge data, but you can do everything with your document. But use of OLE makes you hardcode types of documents. So this is a reason why it’s not flexible.

DOI works fine with huge data due to optimization of flushes. For example, you can made OLE document very fast by using queue of OLE commands and common FLUSH. But DOI provides you with this ‘fast option’ from the box. Furthermore you can still operate with OLE objects getting correspondent reference. But where are disadvantages? Well you need to create additional objects to link your GUI-session with document on a frontend such as container. Then you should know how to be with all those interfaces like I_OI_DOCUMENT_PROXY.

ZWWW is a great tool to get almost everything fast and good. You can create a template either at SMW0 or at OAOR transactions. Then you specifies logic of data mapping. This tool works fast. Isn’t it a dream? I guess no. Because this tool operates with special files with VBA-macroses and runs it without user’s authorization. So it’s a potential harm to user’s computer.

Tool to operate RTF document works also fine but you need to create a whole document in you program. So there’s a huge question how to provide user with possibility to influence the document?

Why not to have a tool which separates design and content parts like does SmartForms or PDF-based forms?

We have documents repository (t-code OAOR) and we have web-repository (t-code SMW0). Both have possibility to store MS Office documents and templates.

We have DOI and OLE tools to manipulate document.

We want to separate development and design stages to make documents flexible.

Desired result is when developer creates a data-extraction report which includes simple call of MS Office document template. This template filled with data extracted by rules described simply and placed into the document. So a functional consultant without developer-key can manipulate design of this document at any time.

Imagine you’ve created a report that gets FI document with its positions. It’s very simple: get the BKPF record and correspondent positions from BSEG. Here are two types of data: structure (BKPF single line) and table type (BSEG positions). Then report calls document via some tool and this FI document is represented with some layout. On the other side a consultant can instantly change any parameter of the document: field’s order of described BKPF structure and their presence, column order of table content and their presence. So, while you have the simple report to extract data you can have different results with possibility to change layout even at production system directly.

Source code listed below will let you use a simple code to fill complex documents. Example of use is:

Fields mapping defined by range names (for MS Excel) or bookmarks (for MS Word). For example: ‘BKPF_1’ to output the first field of structure BKPF or ‘BKPF_STBLG’ to output value of field STBLG of structure BKPF. To create column order for BSEG table we should name range like this: ‘BSEG_2_3_BETRG’. This range name will describe filling table with 3 columns of second, third and BETRG fields of table.

Here is my code to get this tool

Class ZCL_BAS_UTILITIES.

Common part:

class ZCL_BAS_UTILITIES definitionpublic finalcreate public .

public section.*”* public components of class ZCL_BAS_UTILITIES*”* do not include other source files here!!!type-pools CNTL .type-pools SBDST .type-pools SLIS .

method PUT_STR_FIELD_INT_BKMRK.* This method will put just one field of a structure* into the bookmarkFIELD-SYMBOLS: <field> type any, <source> type any.LOOP AT it_fields ASSIGNING <field>.ASSIGN COMPONENT <field> OF STRUCTURE is_source to <source>.IF <source> is ASSIGNED.exit. “Here we’ve found soume field from a list of fields at the source structureENDIF.ENDLOOP.CHECK <source> is ASSIGNED. fill_value_by_bookmark( io_bookmark = io_bookmark iv_new_value = <source> ).endmethod.

method PUT_THE_STRUCTURE.* This method will put just one field of a structure* into the named rangeFIELD-SYMBOLS: <field> type any, <source> type any.LOOP AT it_fields ASSIGNING <field>.ASSIGN COMPONENT <field> OF STRUCTURE is_source to <source>.IF <source> is ASSIGNED.exit. “Here we’ve found some field from a list of fields at the source structureENDIF.ENDLOOP.CHECK <source> is ASSIGNED. fill_value_by_range_name( iv_range_name = iv_full_name ir_document = ir_doi iv_new_value = <source> ).endmethod.

method GET_XLS_FIELDS.DATA: lt_ranges TYPE soi_range_list.FIELD-SYMBOLS: <field> TYPE LINE OF soi_range_list, <name> LIKE LINE OF ct_names.

CHECK ir_xls IS BOUND. ir_xls->get_ranges_names( IMPORTING ranges = lt_ranges ).LOOP AT lt_ranges ASSIGNING <field>.APPEND INITIAL LINE TO ct_names ASSIGNING <name>.MOVE-CORRESPONDING <field> TO <name>. “Fill name <name>–kind = ‘RNGE’. “Domain value could be a reason of dumps if other values ranges determined* Will not fill object value due to interface boundsENDLOOP.endmethod.

Hello Chaouki, This document is either MS Excel document with two named ranges (BKPF and BSEG_T are these names) or MS Word document with two bookmarks (BKPF and BSEG_T again). Actualy if you’re creating MS Excel document it’s better to use ABAP2XLSX. (I have some questions to this tool but it’s works for sure) Kindest regards, Alex Guryanov