cancel
Showing results for 
Search instead for 
Did you mean: 

How to print a word document directly from ABAP?

Former Member
0 Kudos

Hello,

I want to send word documents to printer. I found a FM CV150_PRINT_DOC but I could not find out how to run it.

Thanks,

Didem GUNDOGDU

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

Hi Didem.

To open a document you can use the following method:

CALL METHOD document->open_document

EXPORTING document_url = p_fname

IMPORTING retcode = retcode.

Where p_fname stands for the filename on your fileserver (use 'FILE://' + <directory name> + '/' + <name of the file> for local files).

Regards,

John.

ssimsekler
Active Contributor
0 Kudos

Hi Didem

Here is an example code utilizing OLE2.

REPORT print_via_ole_example .

INCLUDE ole2incl .

DATA: gs_word TYPE ole2_object ,

gs_documents TYPE ole2_object ,

gs_newdoc TYPE ole2_object ,

gs_actdoc TYPE ole2_object .

START-OF-SELECTION .

CREATE OBJECT gs_word 'WORD.APPLICATION'.

SET PROPERTY OF gs_word 'Visible' = '0' .

CALL METHOD OF gs_word 'Documents' = gs_documents.

CALL METHOD OF gs_documents 'Open' = gs_newdoc

EXPORTING #1 = 'D:\my_doc.doc' .

CALL METHOD OF gs_word 'ActiveDocument' = gs_actdoc .

CALL METHOD OF gs_actdoc 'PrintOut' .

CALL METHOD OF gs_word 'Quit' .

END-OF-SELECTION.

FREE: gs_word, gs_actdoc, gs_documents, gs_newdoc .

Hope this helps...

*--Serdar

Former Member
0 Kudos

Thank you Serdar,

It works.

Best Regards,

Didem GUNDOGDU

Former Member
0 Kudos

Iam using the same CV150_PRINT_DOC function module.But Iam getting the following error .

Can you please send me the code to print the DMS document.

Thank You,

Suresh

Former Member
0 Kudos

Iam using the same CV150_PRINT_DOC function module.But Iam getting the following error .

" Error while setting data in data provider object".

Can you please send me the code to print the DMS document.

Thank You,

Suresh

Answers (7)

Answers (7)

Former Member
0 Kudos

HI All,

I have a requirement to print a MS Word document linked to Material Master through the SAP DMS.

I have tried using the FM CV150_print_doc, but I m not clear with the value passed to the mandatory import parameter "URL". Kindly throw some light on the value to be passed for this parameter.

I have also tried using OLE2 objects but call to the method "OPEN" ends with an error (SY-SUBRC 2).

Kindly let me know how to go about it.

Thanks in advance.

Regards,

Niharika.

Former Member
0 Kudos

Hi,

Perhaps you can help me.

I have a document stored in SAP DMS, typically this would not be a MS document, but a PDF or a TIFF.

What I want to do is print the document but have some sort of identification on it to say that it is a draft.

I have read a lot about the watermark options, but this seems to be viable for sapscripts and smartforms and not for DMS Documents.

Essentially, I would want to intercept the spool, add the image or text to it that identifies is as being a draft, and then print that.

Any suggestions?

Thanks

Former Member
0 Kudos

Hi Didem,

First of all, the requirement is not clear. What exactly do you want? Do you want to print a word document, which is stored in SAP Document Management System or you just want to print a document using ABAP code, which is stored on your local machine ?

CV150_PRINT_DOC can only be used when the word document is stored in SAP DMS. You must have a Document Info Record created in SAP for it.

If you want to print a word document from your PC, you may think of using office integration. You may open the document as an OLE object and print using method PRINT_DOCUMENT of I_OI_DOCUMENT_PROXY.

Regards,

Pranav.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I have been successful in achieving this using OLE. Program will open the document, print it, then close the document automatically. If you are interested, I can write a sample for you.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi Rich,

Could you plz send me the sample code ? (at vinod.doshi@watsonpharm.co.in )

my requirement is as below.

There are some analytical tests carried out at the time of Good Receipt.

Depending upon the mateiral, different tests are carried out.

I want to pass the GR no, Inspection Lot no and some other info to predetermined MS word documents. I need to pass this info on every page.

So my printed document will be a combination of this info (GR no , inspection lot no, batch no etc) & predefined ms word format of around 30-40 pages.

This information will be unique for material.

Many thanks for your kind help in advance.

null

Former Member
0 Kudos

Hi,

Can you send me the sample program which you created which print the documents automatically.I have this requirement to print a bunch of documents all together and i am not being very lucky with this.Please do send it to me at vinaymari@yahoo.com

Thanks,

Vinay.M

Former Member
0 Kudos

Hi Rich,

I need the sample code... but my requirement is to print a word document stored in BDS without opening it!

Can yo help..

Thanks!

apo_tsap
Discoverer
0 Kudos

Hi Rich,

Can you please write write a sample for me?

Thanks!

Former Member
0 Kudos

Hello Didem,

You can find some examples using transaction SE83 (Reuse Library): SAP Basis -> Controls -> Desktop Office Integration.

Hope this helps,

John.

Former Member
0 Kudos

Hello,

I have another question. I could not get the idea of addressing the documents. I mean, when I debug the examples, I found out that the content of the documents are carried out to the internal tables. But where do we define the directory and the name of the files?

Best Regards,

Didem

ps: I think the best way is to use ws_execute, but unfortunately printers we use are not MS DOS compatible. I could not print anything from the command prompt.

Former Member
0 Kudos

Hi,

If your functionality allows you to open the doc first and then print it from there, then you can use the FM 'WS_EXECUTE'/ 'GUI_EXEC' to open the file (you should pass the full path of the winword.exe file/WORD prg name and your file path to this FM), and then print it from there

Deepak Charanyan

Former Member
0 Kudos

Hi Didem,

Take a look at the SAP Help for Desktop Integration (BC-CI) working with documents. It's quiet easy to open a document (e.q. Word document) and to print the document.

Regards,

John.

Former Member
0 Kudos

Thanks John,

I have started to look at it, but do you know any source that I can find examples on that topic?

Regards,

Didem