Application Development 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: 

How to download a smartform output as excel file WITH EXACT LAYOUT.

0 Kudos

Hi,

I have searched the forum but could not found any satisfactory answer. I have a smartform with a table, some texts and a logo. I have to write a code which will save the smartform output as excel file in the system keeping the layout of the smartform output EXACT.

i.e., the excel file will contain the output with EXACTLY THE SAME layout as would have been for a pdf file (if the smartform output is converted to a pdf file) and the client can then edit the fields of the table in the excel file. How can I achieve this? Please give a suggestion.. Thanks in advance.

6 REPLIES 6

Sandra_Rossi
Active Contributor
0 Kudos

Why do you want Excel, this application is kind of obsolete for entering data, and not really user-friendly.

If you still want Excel, throw away your smart form, you will have to recreate everything ! (except a part of the data retrieval algorithm)

Two other alternatives:

1) Smart forms may become interactive, using web, they are named web forms. You have to define which cells are input-capable in your smart form, then embed it in a BSP application.

2) Interactive Forms (Adobe PDF)

Anyway, you will have to create many things (and learn these technologies).

For more details about these technologies, look at forum

0 Kudos

Hi Sandra,

We will have to develope the code to convert to excel format on an EXISTING smartform WITHOUT "throwing" or changing the smartform. So can you please clarify how exactly can I proceed?

0 Kudos

What I said is : you can't. Or go to an excel forum, maybe they will be able to help you.

Or do you really have an issue related to SAP?

0 Kudos

Hi Anirban,

Your Requirement is to download a smartform to microsoft Excel .

Well unfortunately we can only download data into excel which is in a tabular format i.e stored in internal tables we have function modules to do the same even u can do that using OLE2.

If u try to download a smartform to Excel only format supported will be ASCII, if u will continue with that the smartforms text's will get downloaded to excel but whole data would be downloaded in a single Cell.

Code to do the same is -


>>>>

CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
  EXPORTING
  i_language = v_language
  i_application = 'SAPDEFAULT'
  IMPORTING
  e_devtype = v_e_devtype.

   CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      FORMNAME                 = w_form
*   VARIANT                  = ' '
*   DIRECT_CALL              = ' '
   IMPORTING
     FM_NAME                  =  w_fmname
   EXCEPTIONS
     NO_FORM                  = 1
     NO_FUNCTION_MODULE       = 2
     OTHERS                   = 3
            .
  IF sy-subrc <> 0.
    MESSAGE E002(zcpm) WITH 'Smartform call fails'.
  ENDIF.

wa_outopt-tdprinter = v_e_devtype.
wa_ctrlop-no_dialog = 'X'.
wa_ctrlop-getotf    = 'X'.


  CALL FUNCTION w_fmname "'/1BCDWB/SF00000025'
    EXPORTING
*   ARCHIVE_INDEX              =
*   ARCHIVE_INDEX_TAB          =
*   ARCHIVE_PARAMETERS         =
    CONTROL_PARAMETERS         = WA_CTRLOP
*   MAIL_APPL_OBJ              =
*   MAIL_RECIPIENT             =
*   MAIL_SENDER                =
    OUTPUT_OPTIONS             = WA_OUTOPT
*    USER_SETTINGS              = ' '
    IMPORTING
*   DOCUMENT_OUTPUT_INFO       =
    JOB_OUTPUT_INFO            = T_OTFDATA
*   JOB_OUTPUT_OPTIONS         =
*    document_output_info       = st_document_output_info
*    job_output_info            = st_job_output_info
*    job_output_options         = st_job_output_options
    TABLES
      T_FINAL                    = T_FINAL
      T_ZSDT_WAGONS              = T_ZSDT_WAGONS_1
      T_QTY                      = T_QTY
      T_QTY1                     = T_QTY1
      T_CON1                     = T_CON1
      T_CON2                     = T_CON2
      "T_ZTMM_OUTWB_TXN           = T_ZTMM_OUTWB_TXN
 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.
T_OTF[] = T_OTFDATA-OTFDATA[].

CALL FUNCTION 'CONVERT_OTF'
EXPORTING
          format = 'ASCII'
          max_linewidth = 132
* ARCHIVE_INDEX = ' '
IMPORTING
          bin_filesize = w_bin_filesize
TABLES
          otf   = t_otf
          lines = t_pdf_tab
EXCEPTIONS
          err_max_linewidth = 1
          err_format = 2
       err_conv_not_possible = 3
OTHERS = 4
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
**********************************************************************************
if tabix_m = 1.
*CALL METHOD cl_gui_frontend_services=>file_save_dialog
*
*CHANGING
*filename = w_FILE_NAME
*path     = w_FILE_PATH
*fullpath = w_FULL_PATH
** USER_ACTION =
** FILE_ENCODING =
*EXCEPTIONS
*CNTL_ERROR = 1
*ERROR_NO_GUI = 2
*NOT_SUPPORTED_BY_GUI = 3
*others = 4
*.
*IF sy-subrc <> 0.
*MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.

CALL function 'TMP_GUI_BROWSE_FOR_FOLDER'
EXPORTING
WINDOW_TITLE = 'Select A File Folder'
INITIAL_FOLDER = 'C:\'
IMPORTING
SELECTED_FOLDER = W_PATH.
endif.
CONDENSE W_PATH.
concatenate W_PATH '\' wa_final-vbeln '.XLS' into w_FULL_PATH.
****************************************************************************Saving the PDF file on to Application server************************
*
CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
   BIN_FILESIZE                     = w_bin_filesize
   FILENAME                         = w_FULL_PATH
   FILETYPE                         = 'BIN'
*   APPEND                          = ' '
*   WRITE_FIELD_SEPARATOR           = ' '
*   HEADER                          = '00'
*   TRUNC_TRAILING_BLANKS           = ' '
*   WRITE_LF                        = 'X'
*   COL_SELECT                      = ' '
*   COL_SELECT_MASK                 = ' '
*   DAT_MODE                        = ' '
*   CONFIRM_OVERWRITE               = ' '
*   NO_AUTH_CHECK                   = ' '
*   CODEPAGE                        = ' '
*   IGNORE_CERR                     = ABAP_TRUE
*   REPLACEMENT                     = '#'
*   WRITE_BOM                       = ' '
*   TRUNC_TRAILING_BLANKS_EOL       = 'X'
*   WK1_N_FORMAT                    = ' '
*   WK1_N_SIZE                      = ' '
*   WK1_T_FORMAT                    = ' '
*   WK1_T_SIZE                      = ' '
 IMPORTING
   FILELENGTH                      = w_filesize
  TABLES
    DATA_TAB                        = t_pdf_tab
*   FIELDNAMES                      =
 EXCEPTIONS
   FILE_WRITE_ERROR                = 1
   NO_BATCH                        = 2
   GUI_REFUSE_FILETRANSFER         = 3
   INVALID_TYPE                    = 4
   NO_AUTHORITY                    = 5
   UNKNOWN_ERROR                   = 6
   HEADER_NOT_ALLOWED              = 7
   SEPARATOR_NOT_ALLOWED           = 8
   FILESIZE_NOT_ALLOWED            = 9
   HEADER_TOO_LONG                 = 10
   DP_ERROR_CREATE                 = 11
   DP_ERROR_SEND                   = 12
   DP_ERROR_WRITE                  = 13
   UNKNOWN_DP_ERROR                = 14
   ACCESS_DENIED                   = 15
   DP_OUT_OF_MEMORY                = 16
   DISK_FULL                       = 17
   DP_TIMEOUT                      = 18
   FILE_NOT_FOUND                  = 19
   DATAPROVIDER_EXCEPTION          = 20
   CONTROL_FLUSH_ERROR             = 21
   OTHERS                          = 22
          .

As u said ,u want to download a smartform to Excel it could be done but only if u r using a internal table and exactly printing line by line values in the smartform, But if u are performing calculation in between, using multiple internal table Work areas, structures, etc i.e if whole smartform is developed with many distributed windows , unfortunately it wont be possible to download a smartform to excel in such cases, because the whole output comes from multiple internal tables, calculations, etc all the data is not printed in a tabular manner so in such a case it would be just impossible to download the smartform to excel.

But we definitely have a workaround which could be done to download the data into excel.

you can develop a ALV report with a header and footer u can define the header and footer of the alv according to the smartform and the middle portion would contain the tabular kind of data which u must be using as Smartform table to print the same.

So if u have a similar kind of smartform with some header data, tabular data, and some footer data, then u can use ALV to do the same thing , advantage with ALV would be that u can easily download the same into excel.

Other alternative is that u can Convert and download the smartform to PDF and copy the same to an Excel wooksheet.

These are all the possibilities with which u can do the same.

Regards,

Akash Rana

0 Kudos

Akash, do a preview before posting, it's displayed in raw as it contains more than 2500 characters.

Anirban, I am not sure to understand what you mean when you say : "the client can then edit the fields of the table in the excel file" ?

My previous answer was about changing the smart form table fields to be input-capable (user can change them, and you'll probably create a program to load the values into SAP).

Former Member
0 Kudos

This message was moderated.