Skip to Content
author's profile photo Former Member
Former Member

Smartforms generating Word documents

Hello SAP experts,

My client is asking for print a smartform in word format, but i'm having some trouble to make it work.

I found this piece of code in the forum, but i don't know how to handle it.

report zars no standard page heading

line-size 170

line-count 65(4).

include ole2incl .

data: v_word type ole2_object ,

v_documents type ole2_object ,

v_newdoc type ole2_object ,

v_actdoc type ole2_object .

start-of-selection .

create object v_word 'WORD.APPLICATION'.

set property of v_word 'Visible' = '0' .

call method of v_word 'Documents' = v_documents.

call method of v_documents 'Open' = v_newdoc

exporting #1 = 'c:\test.doc' .

call method of v_word 'ActiveDocument' = v_actdoc .

call method of v_actdoc 'PrintOut' .

call method of v_word 'Quit' .

end-of-selection.

free: v_word, v_actdoc, v_documents, v_newdoc .

In the actual report, i'm printing the smartform doing:

CALL FUNCTION fname

EXPORTING

control_parameters = t_ctrlpar

user_settings = 'X'

v_anlage = v_anlage

v_adr1 = adre1

v_adr2 = adre2

v_adr3 = adre3

v_datconst = v_datcalc

v_notainsp = p_qmnum

v_datinic = v_datcalc

v_toi = v_toi

v_bo = v_bo

v_gpart = v_gpart

v_nomepn = v_name

IMPORTING

document_output_info = t_doc_output

job_output_info = t_job_output

job_output_options = t_job_options

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

And to save the file i use:

CALL 'CUR_LCL' ID 'UC_LN' FIELD uc_ln. "#EC CI_CCALL

IF sy-subrc = 0.

IF uc_ln = 2.

c_unicode = 'X'.

ELSE.

c_unicode = ' '.

ENDIF.

ENDIF.

  • ================

SET BLANK LINES ON.

FORMAT RESET.

REFRESH:

page, mark, marktab.

CLEAR:

width, height, is_mark, itab_otf, mark, sort_mark, marked_string.

mark-page = 1.

CLEAR page.

itab_otf = t_job_output-otfdata.

  • Loop at OTF-Page

LOOP AT itab_otf INTO wa_otf.

CASE wa_otf-tdprintcom.

WHEN pc_id_string.

PERFORM ls_string.

WHEN pc_id_move_to.

page-x = wa_otf-tdprintpar(5).

page-y = wa_otf-tdprintpar+5(5).

page-chain = c_false.

WHEN pc_id_uline.

page-uline = wa_otf-tdprintpar(1).

WHEN pc_id_call_font.

page-bold = wa_otf-tdprintpar+11(1).

WHEN pc_id_open_page.

width = wa_otf-tdprintpar+9(5). " Character-Width

height = wa_otf-tdprintpar+14(5). " Line-Height

lines_per_page = wa_otf-tdprintpar+19(5) / height.

WHEN pc_id_close_page.

PERFORM ls_showpage.

WHEN pc_id_mark.

PERFORM ls_mark.

ENDCASE.

ENDLOOP.

FORMAT INTENSIFIED ON.

IF list_index = slist_index_default.

list_index = sy-lsind.

ENDIF.

PERFORM set_is_list_download(saplgrap) USING 'x'.

CALL FUNCTION 'DOWNLOAD_LIST'

EXPORTING

list_index = list_index

  • COPY_TO_CLIPBOARD = ' '

EXCEPTIONS

list_index_invalid = 1

list_download_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

  • PERFORM get_listlevel_tables USING

  • pages[]

  • list[]

  • fmbs[]

  • fmbx[]

  • fsel[]

  • list_index.

*

  • CALL FUNCTION 'LIST_CONVERT_TO_RTF'

  • TABLES

  • list = list

  • fmbs = fmbs

  • fmbx = fmbx

  • fsel = fsel

  • EXCEPTIONS

  • download_file_write_error

  • download_no_batch

  • download_unknown_error

  • OTHERS.

*

*

*IF sy-subrc NE 0.

  • MESSAGE s050 WITH 'Arquivo gravado com sucesso'.

*ENDIF.

*

It saves a TXT file in the user machine.

So how can i implemente the word doc?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Dec 15, 2011 at 03:42 PM

    any suggestion?

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.