Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member217925
Active Participant
42,923


Last month, i published my abstraction class to manage Word OLE link. It can generate complete (and complex) word document, but it is a little slow for big tables.

OLE is an old technology... DOCX is an XML file extension... Enough to change my mind about word file generation. Exit OLE, welcome XML :smile:

I updated my abstraction class to generate DOCX file from ABAP directly, without any OLE usage. I know there are actually some projects that want to do that (abap2docx for example). But i think theses projects are too complex to use, or not yet usable in the true life.

With my class, it never be easier to generate DOCX. You never have to use or understand XML.

Here is the code of the "hello word" program.



The class is simple, but can manage complex documents !

Here is the feature list :

  • Empty document creation or with use of template (docx, dotx, docm, dotm)

  • Write text with or without style (character style and/or paragraph style)

  • Option to manualy apply bold, underline, italic, strike, subscript, superscript, small caps, font name & size, font color, highlight color, letter spacing

  • Management of alignment, indent, spacing before/after paragraph

  • Break line, page, section, continuous section

  • Write table with or without style (and option to define cell format : bold, color...)

  • Write Header / footer

  • Write end note / foot note

  • Write comments

  • Write numbered label (figure, table...)

  • Write table of labels (figures, tables...)

  • Choose portrait/landscape, manage page border

  • Add images

  • Add canvas

  • Insert table of content (toc)

  • Add and manage document properties

  • Create and insert custom fields

  • Style creation (character/paragraph)

  • Manage files in SAP Web Repository for template/image (SAPWR, access with transaction SMW0)


In the download file, you will find a test program that contain the class CL_WORD and a demo of how to use it. You will find also some images and 1 template. Theses files are used by the test program, but are not necessary for the class itself.

And there is a direct download link (remember that you will need SAPLINK to install .slnk file) :

Download link : https://www.mediafire.com/folder/if3ljcnesme7y/ABAP

A use case of the class can be found in ZAUTODOC : Automatic generation of technical BW documentation

 

Feel free to comment here :smile:




My others blogpost :

LISTCUBE replacement : a new way to display data

ZAL11 : a replacement for AL11

ZTOAD - Open SQL editor

Abstraction class to generate MSWORD with SAP using OLE

ZAUTODOC : Automatic generation of technical BW documentation

86 Comments
rainer_hbenthal
Active Contributor
0 Likes

Hi,

sounds great.

ABAP2XLSX is fine you don't know anything about XML :smile: Unfortunetly ABAP2DOCX seems to be in hibernation...

As all your other projects are really great I will give it a try for sure!

Former Member
0 Likes

Many thanks for ZTOAD. Simply an awesome tool to use.

Quick question! I have downloaded this utility but it has a file ZTEST_DOC.slnk. How to load it in SAP?

Thanks,

former_member217925
Active Participant
0 Likes

Thank you :smile:

Hope you could find it usefull

former_member217925
Active Participant
0 Likes

Thank you Ahmed, i like it too :grin:

For .slnk, just use saplink, it is same as .nugg but with only 1 object inside (a little smaller and a little faster for me to generate)

Former Member
0 Likes

I just did. But it says

Start import of nugget

Nothing below that. Please find attached.

Former Member
0 Likes

Another thing. When I choose Display Nugget. It says Empty Nugget.

former_member217925
Active Participant
0 Likes

yes, its not a nugget but a slinkee file. Dont you have a second tab for slinkee files in your version of saplink ?

Former Member
0 Likes

Oops! My bad. Truly an honest mistake. I just ignored that tab.

Former Member
0 Likes

Done.

former_member217925
Active Participant
0 Likes

it take many years before I use it :wink:

0 Likes

Another great piece of code.. thank you!!!

hardyp180
SAP Mentor
SAP Mentor
0 Likes

This is fantastic.

Do you see this as a possible replacement for SMARTFORMS/SAPSCRIPT in some cases? You would create a word template with your logo and the general format and then use SAP to dynamically fill the business data?

Cheersy Cheers

Paul

PS ABAP2XLS is used in real life at my company, but I have wrapped around it several helper classes to make it easy for our developers to use.

former_member217925
Active Participant
0 Likes

Hello,

My remark about real life usage concern only DOCX generation :smile:

If abap2docx was as wonderfull as abap2xls, my tool never be born :wink:

regarding your question about smartform/sapscript replacement. If the user requirement is to have DOCX file, yes i think you can replace smartforms. Create the word template with all header/footer, and all styles you need. You could also insert all image you will need.

Remember that actual class drop existing document content, so you have to write all pages in program. But if required, it is very easy to change the class to add an option to keep actual text content of the template. (edit : Done for the next release)

For example, if you have only individual fields to fill, you can create a complete docx into word, replace all variable part with word custom fields. And with the class you just have to define custom fields value :smile:

hardyp180
SAP Mentor
SAP Mentor
0 Likes

Hello again,

I have been talking to my boss about this, and he says it would be lovely if we could generate a word document out of SAP using ABAP and then email it as a PDF so the target could not change it.

If I was doing a similar thing in ABAP2XLS then I would programmatically make the worksheets all password protected, with a 32 digit randomly generated GUID. That would set it in concrete for all time.

In word there is also a setting to make the document read only, so that would be the way forward.

Do you think there is a way to generate the word document so that it becomes a PDF, or is setting the read-only flag the solution?

Cheersy Cheers

Paul

former_member217925
Active Participant
0 Likes

Hello,

With word, you could lock the template in "read only" with password protection to unlock.

Then simply use the locked template with my class: all generated documents will be locked in read only with the same password to unlock.

Note that it is not a strong protection, but do you search a military level lock ? :wink:

Or you could probably transform DOCX to PDF with external program, but you also have to protect your PDF because unprotected PDF could be modified easily :smile:

Former Member
0 Likes

Hi Paul,

May you please elaborate on your helper class? (What exactly does it do?)

Wouldn't it be useful to enrich the original project with it?

Former Member
0 Likes

Hello Sébastien,

I´m very interested in your development.

How can I have a look into the abap code of your abstraction class if I don´t have SAPLINK?

Many thanks in advance!

Helena

former_member217925
Active Participant
0 Likes

To have a look, you can simply open it in a text editor. Special char is escaped, but i think you can "read" the code.

But to import in sap, i've only created the saplink version. What's your problem with saplink ? :smile:

EDIT : For next release i will try to add a simple text version as the program contain only abap code (no text, no screen...)

Former Member
0 Likes

Hello,

I don´t work now in the IT and don´t have authorisation.

Thanks!

Helena

hardyp180
SAP Mentor
SAP Mentor
0 Likes

When the ABAP2XLSX project was on the SCN code exchange I found it really easy to contribute, and I was right up there on the leader board of active contributors.

I have to say I am struggling with the environment where the project is hosted now, as I think other people are - because I think the project has totally stalled since it moved. I could be looking in the wrong place but there does not seem to have been any activity for months.

In any event I have a helper class where I store the code that does not change between different ALV reports. I call a method of the helper to change the ALV object into an ABAP2XLSX object, then the program at hand makes application specific changes, and then another method of the helper sends the modified EXCEL object as an email.

There is more detail on this in chapter 11 of my good old book. Moreover, if you got to the SAP Press Website and look up my book you can download the associated materials for free, and their you will find class ZCL_EXCEL_EMAILER and some of it's friends, which are my helper classes. Looking at the code I just noticed it still has a BREAK HARDYP in it, oh well, too late now.

The code has lots of comments but they say WHY things are done, not how, as the ABAP2XLS methods are so well named it is obvious what they do i.e. you don't have to think too hard what a method call like WORKSHEET->FREEZE_PANES does.

I asked my editor why SAP Press let people download supplementary material for their books for free, and she said having some sort of secret code you get with each book was just too much extra effort for no real benefit. In fact when people download such things they are often so intrigued by the content (code) they end up buying the book anyway.

Cheersy Cheers

Paul

Former Member
0 Likes

Hi,

First, I would like to thank you for the book and sharing the code.

Actually I do own the book (the massive hard-copy version), but I'm ashamed to tell I didn't have a chance to read it carefully yet.

However, from the community point-of-view, I think that it would be useful to include these helper classes in the project itself.

Why don't you feel comfortable with gitHub?

There is even a Git client for ABAP project - abapGit, which should make the life easier, but I haven't tried it myself yet.

rainer_hbenthal
Active Contributor
0 Likes

Will there be a separate class? I guess this would be more reuseable....

And sad to say that, but the generated docs file cant be opened with Word 2010

rainer_hbenthal
Active Contributor
0 Likes

Paul Hardy wrote:




I have to say I am struggling with the environment where the project is hosted now, as I think other people are - because I think the project has totally stalled since it moved. I could be looking in the wrong place but there does not seem to have been any activity for months.



Paul


Unfortunatly that true. I expanded ABAP2XLSX to have more options to graphics. Unfortunetly the conversation was hard with Ivan and replies took weeks. So finally I gave up to recontribute my extensions back to everyone

achim_pellen
Associate
Associate
0 Likes

Hi Sébastien,

sorry but I cannot open the generated DOC file in MS WORD 2013.

It says that WORD cannot open the file because some parts are missing or invalid.

Could you check that please?

Thx a lot

Achim

former_member217925
Active Participant
0 Likes

Hello,

Have you chaanged the path of image/template to appropriates ones on your computer ?

I think the generated word file dont use the template :wink:

If everything is ok in the demo program and there is the error, could you please expend the word error popup and write me the exact error message please ? And also send me the generated word file ?

former_member217925
Active Participant
0 Likes

Hello,

Have you changed the path of image/template to appropriates ones on your computer ?

I think the generated word file dont use the template :wink:

If everything is ok in the demo program and there is the error, could you please expend the word error popup and write me the exact error message please ? And also send me the generated word file ?

former_member217925
Active Participant
0 Likes

About the separate class:

For a customer development, i always use separated class (SE24).

But for tools i share with other people, i find it more simple to use an include SE38. Easier to read, only 1 object to transfer...

You could easily recreate a class if you require it, but which usage require SE24 class instead of embedded one ? (just remove "demo" code and you could use the class as an "include" in any program)

In next release i will separate demo code and class code.

hardyp180
SAP Mentor
SAP Mentor
0 Likes

I have been playing with your Word generation class and - as I said before - it is fantastic, you are to be congratulated, especially for sharing it with the world.

In this brave "new" OO world SAP do not like us having INCLUDE files, so I am going to generate a Z class out of the local class.

As always I am then going to mess around with it like nobodies business.

However, as with ABAP2XLS no doubt when I start to use this there will be some new business requirements to overcome which will involve expanding the functionality.

Since I do have a handle on XML, just like I waffled on about in my book, it is not the end of the world to add extra things, as I demonstrated using ABAP2XLS.

If I end up doing the same thing here, I will update this blog to let the SCN world know what the new requirement was, and how I solved it.

Cheersy Cheers

Paul

achim_pellen
Associate
Associate
0 Likes

Hi Sébastien,

you're right it's because of the missing images/template.

It's working now.

Thx a lot!

Achim

former_member217925
Active Participant
0 Likes

good ! thank you for the feedback :smile:

former_member217925
Active Participant
0 Likes

thanks a lot Paul.

About external class, i'm not closed but i've no idea on how to add documentation. I know that i can create doc object on the class, but it will not be exported with saplink, exept if i add another plugin. I'm tiedous with adding lot of plugins on saplink...

Actually, with the include class, all documentation is easily included (and you can see there is a lot of documentation in my class :wink: ). It's also easy to read to find the appropriate class

If someone have a clean solution, i could change my mind and package an external class...

About the specific requirements, before thinking of code, i suggest you to always think about word class. You can do a lot of things with class (embed in your template).

The 2 known missing functions are : bullets and footnote.

Footnote is easy to add and will probably be in next release.

bullets are not so hard to add, but will be a pain to use. In the xml, for each bullet you have to firstly declare a new bullet group with a lot of parameters...

So, easy to do for a dev who need, but hard to reuse by someone else. That why i've not added for the moment.

i will be happy to read your enhancements :smile:

UweFetzer_se38
Active Contributor
0 Likes

Looks really promissing. Would be great if you can create a Github project (with a separate class).

I've added this page to ABAP Open Source projects (feel free to modify the document as soon as you have a real project home :wink: )

former_member217925
Active Participant
0 Likes

My project home is on my blog, but in french :shock:

About github... not very nice for sap objects, except if you use the abapgit client which is in "alpha" release. So, not for the moment :wink:

I didnt know the link you gave us. Could i edit to add my others projects ?

ZAL11, ZTOAD are used by lot of people, ZLISTCUBE a little less ^^

UweFetzer_se38
Active Contributor
0 Likes

Yes, you can edit and add your other projects (that's the purpose of the document).

Regarding Github: have a look at the other Github projects. We are using Github also for project management and ticket handling. If you want others to contribute to your project you simply need such functions.

former_member217925
Active Participant
0 Likes

The main purpose of my post is to share my code, not to search beta tester or debugger, even if i will always happy if someone find a bug, enhance my code or ask a feature 😉

Actually when people find a bug or enhance or have feature request, they simply reply to the blog post.

I tried github for a php project. It take me lot of time and the feedback was not greater than when i use simple blog post, but im sure git is a better solution for big project with many contributors

former_member217925
Active Participant
0 Likes

Hello,

I just released v1.1.

Class is now in a separate "include".

Demo program has been renamed ZDEMO_DOCX.

A TXT file is included in the zip package with CL_WORD in plain text

Changelog :

  • Add option to keep loaded template content
  • Add get_zip_file method
  • Add write_note method
  • Add write_comment method
  • Add image insertion in table
  • Add xml insertion in table for complex cell content
  • Add option on write_text to insert label number
  • Add option on write_line to get XML instead of buffer into doc
  • Add option to save zip file on server
  • Add options on method write_toc. Now you can write a toc of specific label(for ex.: figure)
  • Fix bug when template path is invalid
  • Fix dump when reuse an image
former_member217925
Active Participant
0 Likes

Hello, you can take new version 1.1 which contain a txt file with class content

former_member217925
Active Participant
0 Likes

Hello,

You can take the new 1.1 version where the class is in a separate include file.

Florian
SAP Champion
SAP Champion
0 Likes

hi Sébastian,

I do not know what kind of release you are running. Maybe you can use ABAP-Doc, that would end in no extra-plugin or anything else.

Drumroll.. and it will generate a lovely documentation for all those "SE24"-Users with a proper release :lol:

Have a look here: ABAP Doc

~Florian

former_member217925
Active Participant
0 Likes

Hello Florian,

dont it work only on eclipse ?

Florian
SAP Champion
SAP Champion
0 Likes

Hi Sébastien,

have to check on that. I get back to you.

~Florian

hardyp180
SAP Mentor
SAP Mentor
0 Likes

Mr.Sebastien,

If it is all right with you, I would like to briefly mention your invention in my next book, in the same way I mentioned ABAP2XLSX and Ivan Femia in the last one.

I would like to send you an email to discuss this. If you were to "follow" me on SCN (I have just "followed" you) then I can send you a direct message via SCN.

In addition the ZCL_WORD INCLUDE is just an INCLUDE containing one local class, as I understand it. Is there a reason this not just a Z class, that would achieve the exact same thing, would it not?

These days the "official" position at SAP is not to use (re-usable) INCLUDES at all,. There is no blanket rule that fits all situations, but I have found that 99% of the time I can replace a re-usable INCLUDE with a Z class of some sort.

To go into a more detailed example - I had an INCLUDE which contained about a dozen FORM routines all to do with ALV. I changed that into a Z class with all the FORM routines as methods of that class.

At first glance that seems pointless, what did I achieve by doing that apart from doing the "right" thing, an argument I consider specious at best.

This way though I get rid of the problem whereby I remove the risk of adding something into the INCLUDE which might cause a syntax error in one of the many programs that contain that INCLUDE. I could add a FORM routine to the INCLUDE with the same name as the one of the programs that uses it.

Cheersy Cheers

Paul

former_member217925
Active Participant
0 Likes

Hi Paul,

Just clicked on "follow" :smile:

About Z class : as previously discussed in this post, i'm open. There are many reason why i share an include :

- easier to share (1 object contain all the stuff)

- less footprint (after saplink import, the "activation" list is smaller, easy for you to check what have been imported, to avoid problem...)

- easier for documentation (all method docs are embbed in the include, no need another saplink plugin)

The main reason is for documentation. i'm tiedous to require a saplink plugin to install the tool...

Former Member
0 Likes

Hi Sébastien,

The way you have implemented this functionality is really neat and indeed commendable.

I understand that the methodology you have followed is what MSDN specifies as well to manipulate OOXML documents. ( https://msdn.microsoft.com/en-us/library/aa982683(v=office.12).aspx )

Never thought anyone could have implemented it so smoothly in ABAP. Neat.

I was checking this on one of our systems and find that the Paragraph styles does not get set to the text fragment. (The style in question is "Title" which is present and not complicated to refer to as well... right?).

the  "word/styles.xml" that is generated does not have any style information when we create the form using  cl_docx_form=>create_form( ) in your constructor.

Most probably this would be an issue with our landscape. Ever faced this issue before?

I have not tried with templates yet.

Thanks and Regards,

David

former_member217925
Active Participant
0 Likes

Hi David,

Thank you for your feedback :smile:

No issue on your landscape. When you create a document "from scratch" there is no style embbed. If you want 1 style, you have to define it before.

This is the first reason why I added the "create from template" function :wink:

You could simply open word, save an empty docx, and use it as a Template for program (even if it's better to create a proper dotx Template, it will work with the docx)

Former Member
0 Likes

That makes sense and it works. Thanks Sébastien

Former Member
0 Likes

Sounds great, I'll give it a try. Is it free to use at a company or are there any restrictions for productive commercial use? I may suggest using your class at work, and this will be the first question they ask...

Thanks,

Wolfgang

former_member217925
Active Participant
0 Likes

Hello It is the same for all code i share here or on my blog :

- You can install and use

- You can modify and rename. If you think your modifications can be usefull to others, feel free to share your modifications here

- You can sell my code to customers. I just ask you to not lie to your customer about the owner of the code (dont try to say it's your code).

- As the program does not contain any malicious code, you are responsible of all damages done by the code. Before use, you can check and review the source to be sure :wink:

Former Member
0 Likes

Thank you for the fast response. I will certainly give due credit, and I'm excited to try it later today... Three cheers to your project and to ABAP2XLSX (by Ivan). Both are very useful. Users love Office documents.

Wolfgang

Former Member
0 Likes

I gave it a try and found several incompatibilities with ECC6. I was able to copy and adjust missing parts to the point where I got a clean compile. I can generate text, but the graphics (or something else) seem to cause a corrupt document. Still looking into that. If you connect, we can talk about details and a few suggestions, then you can choose what to incorporate in your solution.

Hope to talk to you soon.

Wolfgang