Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Convert SmartForm to Word File.

Hi,

I have a requirement to convert a SmartForm to Word File.

I am suppressing the SmartForm Dialog box and the file name is hard coded.

There won’t be any preview for SmartForm.

The below code works if , the format is PDF, but when I change the format to DOC, it does not work.

The doc file created is a 0 byte file.

Also, I won’t be giving any spool requests..

What is the way to convert a Smart Form to Word document.

Regards,

Vikas

REPORT  z_smart_form_2_ms_word              .
DATA: cparam TYPE ssfctrlop,
  outop TYPE ssfcompop,
  file_size TYPE i,
  bin_filesize TYPE i.

DATA: tab_otf_data TYPE ssfcrescl,
  pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE,
  it_ekpo TYPE STANDARD TABLE OF ekpo WITH HEADER LINE,
  tab_otf_final TYPE itcoo OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.
*" **************** suppressing the dialog box****************************
  outop-tddest = 'LP01'.
  cparam-no_dialog = 'X'.
  cparam-preview = space.
  cparam-getotf = 'X'.
  PERFORM fetchdata.

END-OF-SELECTION.
  PERFORM callsmartform.
  tab_otf_final[] = tab_otf_data-otfdata[].
  PERFORM createwordfile.
  PERFORM savepdffile.

*&---------------------------------------------------------------------*
*&      Form  FetchData
*&---------------------------------------------------------------------*
FORM fetchdata .
  SELECT * FROM ekpo INTO CORRESPONDING FIELDS OF TABLE it_ekpo
  WHERE ebeln >  '4500009071' AND ebeln  < '4500009073' .

ENDFORM.                    " FetchData

*&---------------------------------------------------------------------*
*&      Form  CallSmartForm
*&---------------------------------------------------------------------*
FORM callsmartform .
  CALL FUNCTION '/1BCDWB/SF00000234'
  EXPORTING
  control_parameters         =  cparam
  output_options             = outop
   user_settings              = space
*  s_header                   = st_header
  IMPORTING
    job_output_info            = tab_otf_data
  TABLES
       t_ekpo                     = it_ekpo
* EXCEPTIONS
             .
  IF sy-subrc <> 0.
    MESSAGE  'Error in Calling Smart Form ' TYPE 'I'.
  ENDIF.

ENDFORM.                    " CallSmartForm
*&---------------------------------------------------------------------*
*&      Form  createwordfile
*&---------------------------------------------------------------------*
FORM createwordfile .
  CALL FUNCTION 'CONVERT_OTF'
  EXPORTING
  format = 'DOC'
  max_linewidth = 132
* ARCHIVE_INDEX = ' '
* COPYNUMBER = 0
* ASCII_BIDI_VIS2LOG = ' '
  IMPORTING
  bin_filesize = bin_filesize
* BIN_FILE =
  TABLES
  otf = tab_otf_final
  lines = pdf_tab
  EXCEPTIONS
  err_max_linewidth = 1
  err_format = 2
  err_conv_not_possible = 3
  err_bad_otf = 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.

ENDFORM.                    " createwordfile
*&---------------------------------------------------------------------*
*&      Form  savepdffile
*&---------------------------------------------------------------------*
FORM savepdffile .
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
     bin_filesize                  = bin_filesize
     filename                      = 'C:ab.doc'
     filetype                      = 'BIN'
   IMPORTING
     filelength                    = file_size
    TABLES
      data_tab                      = pdf_tab
* EXCEPTIONS
*   FILE_WRITE_ERROR              = 1
*   OTHERS                        = 22
            .
  IF sy-subrc <> 0.
    MESSAGE  'Error while Saving' TYPE 'I'.
  ENDIF.

ENDFORM.                    " savepdffile

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question