Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Smartforms generating Word documents

Former Member
0 Likes
455

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?

1 REPLY 1
Read only

Former Member
0 Likes
387

any suggestion?